選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

VideoLayout.js 33KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  1. /* global config, APP, $, interfaceConfig */
  2. /* jshint -W101 */
  3. import AudioLevels from "../audio_levels/AudioLevels";
  4. import Avatar from "../avatar/Avatar";
  5. import BottomToolbar from "../toolbars/BottomToolbar";
  6. import UIEvents from "../../../service/UI/UIEvents";
  7. import UIUtil from "../util/UIUtil";
  8. import RemoteVideo from "./RemoteVideo";
  9. import LargeVideoManager, {VideoContainerType} from "./LargeVideo";
  10. import {PreziContainerType} from '../prezi/Prezi';
  11. import LocalVideo from "./LocalVideo";
  12. var RTCBrowserType = require('../../RTC/RTCBrowserType');
  13. var remoteVideos = {};
  14. var remoteVideoTypes = {};
  15. var localVideoThumbnail = null;
  16. var currentDominantSpeaker = null;
  17. var lastNCount = config.channelLastN;
  18. var localLastNCount = config.channelLastN;
  19. var localLastNSet = [];
  20. var lastNEndpointsCache = [];
  21. var lastNPickupId = null;
  22. var eventEmitter = null;
  23. /**
  24. * Currently focused video jid
  25. * @type {String}
  26. */
  27. var focusedVideoResourceJid = null;
  28. const thumbAspectRatio = 16.0 / 9.0;
  29. /**
  30. * On contact list item clicked.
  31. */
  32. function onContactClicked (id) {
  33. if (APP.conference.isLocalId(id)) {
  34. $("#localVideoContainer").click();
  35. return;
  36. }
  37. let remoteVideo = remoteVideos[id];
  38. if (remoteVideo && remoteVideo.selectVideoElement().length) {
  39. // It is not always the case that a videoThumb exists (if there is
  40. // no actual video).
  41. if (remoteVideo.stream) {
  42. // We have a video src, great! Let's update the large video
  43. // now.
  44. VideoLayout.handleVideoThumbClicked(false, id);
  45. } else {
  46. // If we don't have a video src for jid, there's absolutely
  47. // no point in calling handleVideoThumbClicked; Quite
  48. // simply, it won't work because it needs an src to attach
  49. // to the large video.
  50. //
  51. // Instead, we trigger the pinned endpoint changed event to
  52. // let the bridge adjust its lastN set for myjid and store
  53. // the pinned user in the lastNPickupId variable to be
  54. // picked up later by the lastN changed event handler.
  55. lastNPickupId = id;
  56. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, id);
  57. }
  58. }
  59. }
  60. /**
  61. * Returns the corresponding resource id to the given peer container
  62. * DOM element.
  63. *
  64. * @return the corresponding resource id to the given peer container
  65. * DOM element
  66. */
  67. function getPeerContainerResourceId (containerElement) {
  68. if (localVideoThumbnail.container === containerElement) {
  69. return localVideoThumbnail.id;
  70. }
  71. let i = containerElement.id.indexOf('participant_');
  72. if (i >= 0) {
  73. return containerElement.id.substring(i + 12);
  74. }
  75. }
  76. let largeVideo;
  77. var VideoLayout = {
  78. init (emitter) {
  79. eventEmitter = emitter;
  80. localVideoThumbnail = new LocalVideo(VideoLayout, emitter);
  81. emitter.addListener(UIEvents.CONTACT_CLICKED, onContactClicked);
  82. },
  83. initLargeVideo (isSideBarVisible) {
  84. largeVideo = new LargeVideoManager();
  85. largeVideo.updateContainerSize(isSideBarVisible);
  86. AudioLevels.init();
  87. },
  88. setAudioLevel(id, lvl) {
  89. if (!largeVideo) {
  90. return;
  91. }
  92. AudioLevels.updateAudioLevel(
  93. id, lvl, largeVideo.id
  94. );
  95. },
  96. isInLastN (resource) {
  97. return lastNCount < 0 || // lastN is disabled
  98. // lastNEndpoints cache not built yet
  99. (lastNCount > 0 && !lastNEndpointsCache.length) ||
  100. (lastNEndpointsCache &&
  101. lastNEndpointsCache.indexOf(resource) !== -1);
  102. },
  103. changeLocalAudio (stream) {
  104. let localAudio = document.getElementById('localAudio');
  105. stream.attach($(localAudio));
  106. //return; // FIXME maybe move this into the library?
  107. // Writing volume not allowed in IE
  108. if (!RTCBrowserType.isIExplorer()) {
  109. localAudio.autoplay = true;
  110. localAudio.volume = 0;
  111. }
  112. // Now when Temasys plugin is converting also <audio> elements to
  113. // plugin's <object>s, in current layout it will capture click events
  114. // before it reaches the local video object. We hide it here in order
  115. // to prevent that.
  116. if (RTCBrowserType.isIExplorer()) {
  117. // The issue is not present on Safari. Also if we hide it in Safari
  118. // then the local audio track will have 'enabled' flag set to false
  119. // which will result in audio mute issues
  120. $('#localAudio').hide();
  121. }
  122. },
  123. changeLocalVideo (stream) {
  124. // Set default display name.
  125. localVideoThumbnail.setDisplayName();
  126. localVideoThumbnail.createConnectionIndicator();
  127. let localId = APP.conference.localId;
  128. this.onVideoTypeChanged(localId, stream.videoType);
  129. let {thumbWidth, thumbHeight} = this.calculateThumbnailSize();
  130. AudioLevels.updateAudioLevelCanvas(null, thumbWidth, thumbHeight);
  131. if (!stream.isMuted()) {
  132. localVideoThumbnail.changeVideo(stream);
  133. }
  134. /* force update if we're currently being displayed */
  135. if (this.isCurrentlyOnLarge(localId)) {
  136. this.updateLargeVideo(localId, true);
  137. }
  138. },
  139. /**
  140. * Get's the localID of the conference and set it to the local video
  141. * (small one). This needs to be called as early as possible, when muc is
  142. * actually joined. Otherwise events can come with information like email
  143. * and setting them assume the id is already set.
  144. */
  145. mucJoined () {
  146. let id = APP.conference.localId;
  147. localVideoThumbnail.joined(id);
  148. if (largeVideo && !largeVideo.id) {
  149. this.updateLargeVideo(id, true);
  150. }
  151. },
  152. /**
  153. * Adds or removes icons for not available camera and microphone.
  154. * @param resourceJid the jid of user
  155. * @param devices available devices
  156. */
  157. setDeviceAvailabilityIcons (resourceJid, devices) {
  158. if(!devices)
  159. return;
  160. if(!resourceJid) {
  161. localVideoThumbnail.setDeviceAvailabilityIcons(devices);
  162. } else {
  163. if(remoteVideos[resourceJid])
  164. remoteVideos[resourceJid].setDeviceAvailabilityIcons(devices);
  165. }
  166. },
  167. /**
  168. * Checks if removed video is currently displayed and tries to display
  169. * another one instead.
  170. */
  171. updateRemovedVideo (id) {
  172. if (!this.isCurrentlyOnLarge(id)) {
  173. return;
  174. }
  175. let newId;
  176. // We'll show user's avatar if he is the dominant speaker or if
  177. // his video thumbnail is pinned
  178. if (remoteVideos[id] && (id === focusedVideoResourceJid || id === currentDominantSpeaker)) {
  179. newId = id;
  180. } else {
  181. // Otherwise select last visible video
  182. newId = this.electLastVisibleVideo();
  183. }
  184. this.updateLargeVideo(newId);
  185. },
  186. electLastVisibleVideo () {
  187. // pick the last visible video in the row
  188. // if nobody else is left, this picks the local video
  189. let thumbs = BottomToolbar.getThumbs(true).filter('[id!="mixedstream"]');
  190. let lastVisible = thumbs.filter(':visible:last');
  191. if (lastVisible.length) {
  192. let id = getPeerContainerResourceId(lastVisible[0]);
  193. if (remoteVideos[id]) {
  194. console.info("electLastVisibleVideo: " + id);
  195. return id;
  196. }
  197. // The RemoteVideo was removed (but the DOM elements may still
  198. // exist).
  199. }
  200. console.info("Last visible video no longer exists");
  201. thumbs = BottomToolbar.getThumbs();
  202. if (thumbs.length) {
  203. let id = getPeerContainerResourceId(thumbs[0]);
  204. if (remoteVideos[id]) {
  205. console.info("electLastVisibleVideo: " + id);
  206. return id;
  207. }
  208. // The RemoteVideo was removed (but the DOM elements may
  209. // still exist).
  210. }
  211. // Go with local video
  212. console.info("Fallback to local video...");
  213. let id = APP.conference.localId;
  214. console.info("electLastVisibleVideo: " + id);
  215. return id;
  216. },
  217. onRemoteStreamAdded (stream) {
  218. let id = stream.getParticipantId();
  219. remoteVideos[id].addRemoteStreamElement(stream);
  220. // if track is muted make sure we reflect that
  221. if(stream.isMuted())
  222. {
  223. if(stream.getType() === "audio")
  224. this.onAudioMute(stream.getParticipantId(), true);
  225. else
  226. this.onVideoMute(stream.getParticipantId(), true);
  227. }
  228. },
  229. /**
  230. * Return the type of the remote video.
  231. * @param id the id for the remote video
  232. * @returns the video type video or screen.
  233. */
  234. getRemoteVideoType (id) {
  235. return remoteVideoTypes[id];
  236. },
  237. handleVideoThumbClicked (noPinnedEndpointChangedEvent,
  238. resourceJid) {
  239. if(focusedVideoResourceJid) {
  240. var oldSmallVideo
  241. = VideoLayout.getSmallVideo(focusedVideoResourceJid);
  242. if (oldSmallVideo && !interfaceConfig.filmStripOnly)
  243. oldSmallVideo.focus(false);
  244. }
  245. var smallVideo = VideoLayout.getSmallVideo(resourceJid);
  246. // Unlock current focused.
  247. if (focusedVideoResourceJid === resourceJid)
  248. {
  249. focusedVideoResourceJid = null;
  250. // Enable the currently set dominant speaker.
  251. if (currentDominantSpeaker) {
  252. if(smallVideo && smallVideo.hasVideo()) {
  253. this.updateLargeVideo(currentDominantSpeaker);
  254. }
  255. }
  256. if (!noPinnedEndpointChangedEvent) {
  257. eventEmitter.emit(UIEvents.PINNED_ENDPOINT);
  258. }
  259. return;
  260. }
  261. // Lock new video
  262. focusedVideoResourceJid = resourceJid;
  263. // Update focused/pinned interface.
  264. if (resourceJid) {
  265. if (smallVideo && !interfaceConfig.filmStripOnly)
  266. smallVideo.focus(true);
  267. if (!noPinnedEndpointChangedEvent) {
  268. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, resourceJid);
  269. }
  270. }
  271. this.updateLargeVideo(resourceJid);
  272. // Writing volume not allowed in IE
  273. if (!RTCBrowserType.isIExplorer()) {
  274. $('audio').each(function (idx, el) {
  275. el.volume = 0;
  276. el.volume = 1;
  277. });
  278. }
  279. },
  280. /**
  281. * Checks if container for participant identified by given id exists
  282. * in the document and creates it eventually.
  283. *
  284. * @return Returns <tt>true</tt> if the peer container exists,
  285. * <tt>false</tt> - otherwise
  286. */
  287. addParticipantContainer (id) {
  288. let remoteVideo = new RemoteVideo(id, VideoLayout, eventEmitter);
  289. remoteVideos[id] = remoteVideo;
  290. let videoType = remoteVideoTypes[id];
  291. if (videoType) {
  292. remoteVideo.setVideoType(videoType);
  293. }
  294. // In case this is not currently in the last n we don't show it.
  295. if (localLastNCount && localLastNCount > 0 &&
  296. BottomToolbar.getThumbs().length >= localLastNCount + 2) {
  297. remoteVideo.showPeerContainer('hide');
  298. } else {
  299. VideoLayout.resizeThumbnails();
  300. }
  301. },
  302. inputDisplayNameHandler (name) {
  303. localVideoThumbnail.inputDisplayNameHandler(name);
  304. },
  305. videoactive (videoelem, resourceJid) {
  306. console.info(resourceJid + " video is now active");
  307. videoelem.show();
  308. VideoLayout.resizeThumbnails();
  309. // Update the large video to the last added video only if there's no
  310. // current dominant, focused speaker or prezi playing or update it to
  311. // the current dominant speaker.
  312. if ((!focusedVideoResourceJid &&
  313. !currentDominantSpeaker &&
  314. !this.isLargeContainerTypeVisible(PreziContainerType)) ||
  315. focusedVideoResourceJid === resourceJid ||
  316. (resourceJid &&
  317. currentDominantSpeaker === resourceJid)) {
  318. this.updateLargeVideo(resourceJid, true);
  319. }
  320. },
  321. /**
  322. * Shows the presence status message for the given video.
  323. */
  324. setPresenceStatus (resourceJid, statusMsg) {
  325. remoteVideos[resourceJid].setPresenceStatus(statusMsg);
  326. },
  327. /**
  328. * Shows a visual indicator for the moderator of the conference.
  329. * On local or remote participants.
  330. */
  331. showModeratorIndicator () {
  332. let isModerator = APP.conference.isModerator;
  333. if (isModerator) {
  334. localVideoThumbnail.createModeratorIndicatorElement();
  335. }
  336. APP.conference.listMembers().forEach(function (member) {
  337. let id = member.getId();
  338. if (member.isModerator()) {
  339. remoteVideos[id].removeRemoteVideoMenu();
  340. remoteVideos[id].createModeratorIndicatorElement();
  341. } else if (isModerator) {
  342. // We are moderator, but user is not - add menu
  343. if ($(`#remote_popupmenu_${id}`).length <= 0) {
  344. remoteVideos[id].addRemoteVideoMenu();
  345. }
  346. }
  347. });
  348. },
  349. /*
  350. * Shows or hides the audio muted indicator over the local thumbnail video.
  351. * @param {boolean} isMuted
  352. */
  353. showLocalAudioIndicator (isMuted) {
  354. localVideoThumbnail.showAudioIndicator(isMuted);
  355. },
  356. /**
  357. * Resizes the large video container.
  358. */
  359. resizeLargeVideoContainer (isSideBarVisible) {
  360. if (largeVideo) {
  361. largeVideo.updateContainerSize(isSideBarVisible);
  362. largeVideo.resize(false);
  363. } else {
  364. this.resizeVideoSpace(false, isSideBarVisible);
  365. }
  366. this.resizeThumbnails(false);
  367. },
  368. /**
  369. * Resizes thumbnails.
  370. */
  371. resizeThumbnails (animate = false) {
  372. let {thumbWidth, thumbHeight} = this.calculateThumbnailSize();
  373. $('.userAvatar').css('left', (thumbWidth - thumbHeight) / 2);
  374. BottomToolbar.resizeThumbnails(thumbWidth, thumbHeight, animate).then(function () {
  375. BottomToolbar.resizeToolbar(thumbWidth, thumbHeight);
  376. AudioLevels.updateCanvasSize(thumbWidth, thumbHeight);
  377. });
  378. },
  379. /**
  380. * Calculates the thumbnail size.
  381. *
  382. */
  383. calculateThumbnailSize () {
  384. let videoSpaceWidth = BottomToolbar.getFilmStripWidth();
  385. // Calculate the available height, which is the inner window height
  386. // minus 39px for the header minus 2px for the delimiter lines on the
  387. // top and bottom of the large video, minus the 36px space inside the
  388. // remoteVideos container used for highlighting shadow.
  389. let availableHeight = 100;
  390. let numvids = BottomToolbar.getThumbs().length;
  391. if (localLastNCount && localLastNCount > 0) {
  392. numvids = Math.min(localLastNCount + 1, numvids);
  393. }
  394. // Remove the 3px borders arround videos and border around the remote
  395. // videos area and the 4 pixels between the local video and the others
  396. //TODO: Find out where the 4 pixels come from and remove them
  397. let availableWinWidth = videoSpaceWidth - 2 * 3 * numvids - 70 - 4;
  398. let availableWidth = availableWinWidth / numvids;
  399. let maxHeight = Math.min(160, availableHeight);
  400. availableHeight
  401. = Math.min( maxHeight,
  402. availableWidth / thumbAspectRatio,
  403. window.innerHeight - 18);
  404. if (availableHeight < availableWidth / thumbAspectRatio) {
  405. availableWidth = Math.floor(availableHeight * thumbAspectRatio);
  406. }
  407. return {
  408. thumbWidth: availableWidth,
  409. thumbHeight: availableHeight
  410. };
  411. },
  412. /**
  413. * On audio muted event.
  414. */
  415. onAudioMute (id, isMuted) {
  416. if (APP.conference.isLocalId(id)) {
  417. localVideoThumbnail.showAudioIndicator(isMuted);
  418. } else {
  419. remoteVideos[id].showAudioIndicator(isMuted);
  420. if (APP.conference.isModerator) {
  421. remoteVideos[id].updateRemoteVideoMenu(isMuted);
  422. }
  423. }
  424. },
  425. /**
  426. * On video muted event.
  427. */
  428. onVideoMute (id, value) {
  429. if (APP.conference.isLocalId(id)) {
  430. localVideoThumbnail.setMutedView(value);
  431. } else {
  432. var remoteVideo = remoteVideos[id];
  433. remoteVideo.setMutedView(value);
  434. var el = remoteVideo.selectVideoElement();
  435. if (!value)
  436. el.show();
  437. else
  438. el.hide();
  439. }
  440. if(this.isCurrentlyOnLarge(id))
  441. largeVideo.showAvatar(value);
  442. },
  443. /**
  444. * Display name changed.
  445. */
  446. onDisplayNameChanged (id, displayName, status) {
  447. if (id === 'localVideoContainer' ||
  448. APP.conference.isLocalId(id)) {
  449. localVideoThumbnail.setDisplayName(displayName);
  450. } else {
  451. remoteVideos[id].setDisplayName(displayName, status);
  452. }
  453. },
  454. /**
  455. * On dominant speaker changed event.
  456. */
  457. onDominantSpeakerChanged (id) {
  458. // We ignore local user events.
  459. if (APP.conference.isLocalId(id) || (id === currentDominantSpeaker)) {
  460. return;
  461. }
  462. let remoteVideo = remoteVideos[id];
  463. if (!remoteVideo) {
  464. return;
  465. }
  466. // Update the current dominant speaker.
  467. remoteVideo.updateDominantSpeakerIndicator(true);
  468. // let's remove the indications from the remote video if any
  469. let oldSpeakerRemoteVideo = remoteVideos[currentDominantSpeaker];
  470. if (oldSpeakerRemoteVideo) {
  471. oldSpeakerRemoteVideo.updateDominantSpeakerIndicator(false);
  472. }
  473. currentDominantSpeaker = id;
  474. // Obtain container for new dominant speaker.
  475. let videoSel = remoteVideo.selectVideoElement();
  476. // Local video will not have container found, but that's ok
  477. // since we don't want to switch to local video.
  478. if (!focusedVideoResourceJid && videoSel.length) {
  479. // Update the large video if the video source is already available,
  480. // otherwise wait for the "videoactive.jingle" event.
  481. if (videoSel[0].currentTime > 0) {
  482. this.updateLargeVideo(id);
  483. }
  484. }
  485. },
  486. /**
  487. * On last N change event.
  488. *
  489. * @param lastNEndpoints the list of last N endpoints
  490. * @param endpointsEnteringLastN the list currently entering last N
  491. * endpoints
  492. */
  493. onLastNEndpointsChanged (lastNEndpoints, endpointsEnteringLastN) {
  494. if (lastNCount !== lastNEndpoints.length)
  495. lastNCount = lastNEndpoints.length;
  496. lastNEndpointsCache = lastNEndpoints;
  497. // Say A, B, C, D, E, and F are in a conference and LastN = 3.
  498. //
  499. // If LastN drops to, say, 2, because of adaptivity, then E should see
  500. // thumbnails for A, B and C. A and B are in E's server side LastN set,
  501. // so E sees them. C is only in E's local LastN set.
  502. //
  503. // If F starts talking and LastN = 3, then E should see thumbnails for
  504. // F, A, B. B gets "ejected" from E's server side LastN set, but it
  505. // enters E's local LastN ejecting C.
  506. // Increase the local LastN set size, if necessary.
  507. if (lastNCount > localLastNCount) {
  508. localLastNCount = lastNCount;
  509. }
  510. // Update the local LastN set preserving the order in which the
  511. // endpoints appeared in the LastN/local LastN set.
  512. var nextLocalLastNSet = lastNEndpoints.slice(0);
  513. for (var i = 0; i < localLastNSet.length; i++) {
  514. if (nextLocalLastNSet.length >= localLastNCount) {
  515. break;
  516. }
  517. var resourceJid = localLastNSet[i];
  518. if (nextLocalLastNSet.indexOf(resourceJid) === -1) {
  519. nextLocalLastNSet.push(resourceJid);
  520. }
  521. }
  522. localLastNSet = nextLocalLastNSet;
  523. var updateLargeVideo = false;
  524. // Handle LastN/local LastN changes.
  525. BottomToolbar.getThumbs().each(function( index, element ) {
  526. var resourceJid = getPeerContainerResourceId(element);
  527. // We do not want to process any logic for our own(local) video
  528. // because the local participant is never in the lastN set.
  529. // The code of this function might detect that the local participant
  530. // has been dropped out of the lastN set and will update the large
  531. // video
  532. // Detected from avatar tests, where lastN event override
  533. // local video pinning
  534. if(APP.conference.isLocalId(resourceJid))
  535. return;
  536. var isReceived = true;
  537. if (resourceJid &&
  538. lastNEndpoints.indexOf(resourceJid) < 0 &&
  539. localLastNSet.indexOf(resourceJid) < 0) {
  540. console.log("Remove from last N", resourceJid);
  541. if (remoteVideos[resourceJid])
  542. remoteVideos[resourceJid].showPeerContainer('hide');
  543. else if (!APP.conference.isLocalId(resourceJid))
  544. console.error("No remote video for: " + resourceJid);
  545. isReceived = false;
  546. } else if (resourceJid &&
  547. $('#participant_' + resourceJid).is(':visible') &&
  548. lastNEndpoints.indexOf(resourceJid) < 0 &&
  549. localLastNSet.indexOf(resourceJid) >= 0) {
  550. if (remoteVideos[resourceJid])
  551. remoteVideos[resourceJid].showPeerContainer('avatar');
  552. else if (!APP.conference.isLocalId(resourceJid))
  553. console.error("No remote video for: " + resourceJid);
  554. isReceived = false;
  555. }
  556. if (!isReceived) {
  557. // resourceJid has dropped out of the server side lastN set, so
  558. // it is no longer being received. If resourceJid was being
  559. // displayed in the large video we have to switch to another
  560. // user.
  561. if (!updateLargeVideo &&
  562. this.isCurrentlyOnLarge(resourceJid)) {
  563. updateLargeVideo = true;
  564. }
  565. }
  566. });
  567. if (!endpointsEnteringLastN || endpointsEnteringLastN.length < 0)
  568. endpointsEnteringLastN = lastNEndpoints;
  569. if (endpointsEnteringLastN && endpointsEnteringLastN.length > 0) {
  570. endpointsEnteringLastN.forEach(function (resourceJid) {
  571. var isVisible = $('#participant_' + resourceJid).is(':visible');
  572. var remoteVideo = remoteVideos[resourceJid];
  573. remoteVideo.showPeerContainer('show');
  574. if (!isVisible) {
  575. console.log("Add to last N", resourceJid);
  576. var jid = APP.xmpp.findJidFromResource(resourceJid);
  577. var mediaStream =
  578. APP.RTC.remoteStreams[jid]['video'];
  579. var sel = remoteVideo.selectVideoElement();
  580. APP.RTC.attachMediaStream(sel, mediaStream.stream);
  581. if (lastNPickupId == mediaStream.peerjid) {
  582. // Clean up the lastN pickup id.
  583. lastNPickupId = null;
  584. // Don't fire the events again, they've already
  585. // been fired in the contact list click handler.
  586. VideoLayout.handleVideoThumbClicked(
  587. false,
  588. Strophe.getResourceFromJid(mediaStream.peerjid));
  589. updateLargeVideo = false;
  590. }
  591. remoteVideos[resourceJid].
  592. waitForPlayback(sel, mediaStream);
  593. }
  594. });
  595. }
  596. // The endpoint that was being shown in the large video has dropped out
  597. // of the lastN set and there was no lastN pickup jid. We need to update
  598. // the large video now.
  599. if (updateLargeVideo) {
  600. var resource;
  601. // Find out which endpoint to show in the large video.
  602. for (i = 0; i < lastNEndpoints.length; i++) {
  603. resource = lastNEndpoints[i];
  604. if (!resource || APP.conference.isLocalId(resource))
  605. continue;
  606. // videoSrcToSsrc needs to be update for this call to succeed.
  607. this.updateLargeVideo(resource);
  608. break;
  609. }
  610. }
  611. },
  612. /**
  613. * Updates local stats
  614. * @param percent
  615. * @param object
  616. */
  617. updateLocalConnectionStats (percent, object) {
  618. let resolutions = {};
  619. if (object.resolution !== null) {
  620. resolutions = object.resolution;
  621. object.resolution = resolutions[APP.conference.localId];
  622. }
  623. localVideoThumbnail.updateStatsIndicator(percent, object);
  624. Object.keys(resolutions).forEach(function (id) {
  625. if (APP.conference.isLocalId(id)) {
  626. return;
  627. }
  628. let resolution = resolutions[id];
  629. let remoteVideo = remoteVideos[id];
  630. if (resolution && remoteVideo) {
  631. remoteVideo.updateResolution(resolution);
  632. }
  633. });
  634. },
  635. /**
  636. * Updates remote stats.
  637. * @param id the id associated with the stats
  638. * @param percent the connection quality percent
  639. * @param object the stats data
  640. */
  641. updateConnectionStats (id, percent, object) {
  642. if (remoteVideos[id]) {
  643. remoteVideos[id].updateStatsIndicator(percent, object);
  644. }
  645. },
  646. /**
  647. * Hides the connection indicator
  648. * @param id
  649. */
  650. hideConnectionIndicator (id) {
  651. remoteVideos[id].hideConnectionIndicator();
  652. },
  653. /**
  654. * Hides all the indicators
  655. */
  656. hideStats () {
  657. for(var video in remoteVideos) {
  658. remoteVideos[video].hideIndicator();
  659. }
  660. localVideoThumbnail.hideIndicator();
  661. },
  662. removeParticipantContainer (id) {
  663. // Unlock large video
  664. if (focusedVideoResourceJid === id) {
  665. console.info("Focused video owner has left the conference");
  666. focusedVideoResourceJid = null;
  667. }
  668. if (currentDominantSpeaker === id) {
  669. console.info("Dominant speaker has left the conference");
  670. currentDominantSpeaker = null;
  671. }
  672. var remoteVideo = remoteVideos[id];
  673. if (remoteVideo) {
  674. // Remove remote video
  675. console.info("Removing remote video: " + id);
  676. delete remoteVideos[id];
  677. remoteVideo.remove();
  678. } else {
  679. console.warn("No remote video for " + id);
  680. }
  681. VideoLayout.resizeThumbnails();
  682. },
  683. onVideoTypeChanged (id, newVideoType) {
  684. if (remoteVideoTypes[id] === newVideoType) {
  685. return;
  686. }
  687. console.info("Peer video type changed: ", id, newVideoType);
  688. remoteVideoTypes[id] = newVideoType;
  689. var smallVideo;
  690. if (APP.conference.isLocalId(id)) {
  691. if (!localVideoThumbnail) {
  692. console.warn("Local video not ready yet");
  693. return;
  694. }
  695. smallVideo = localVideoThumbnail;
  696. } else if (remoteVideos[id]) {
  697. smallVideo = remoteVideos[id];
  698. } else {
  699. return;
  700. }
  701. smallVideo.setVideoType(newVideoType);
  702. if (this.isCurrentlyOnLarge(id)) {
  703. this.updateLargeVideo(id, true);
  704. }
  705. },
  706. showMore (jid) {
  707. if (jid === 'local') {
  708. localVideoThumbnail.connectionIndicator.showMore();
  709. } else {
  710. var remoteVideo = remoteVideos[Strophe.getResourceFromJid(jid)];
  711. if (remoteVideo) {
  712. remoteVideo.connectionIndicator.showMore();
  713. } else {
  714. console.info("Error - no remote video for jid: " + jid);
  715. }
  716. }
  717. },
  718. addRemoteVideoContainer (id) {
  719. return RemoteVideo.createContainer(id);
  720. },
  721. /**
  722. * Resizes the video area.
  723. *
  724. * @param isSideBarVisible indicates if the side bar is currently visible
  725. * @param callback a function to be called when the video space is
  726. * resized.
  727. */
  728. resizeVideoArea (isSideBarVisible, callback) {
  729. let animate = true;
  730. if (largeVideo) {
  731. largeVideo.updateContainerSize(isSideBarVisible);
  732. largeVideo.resize(animate);
  733. this.resizeVideoSpace(animate, isSideBarVisible, callback);
  734. }
  735. VideoLayout.resizeThumbnails(animate);
  736. },
  737. /**
  738. * Resizes the #videospace html element
  739. * @param animate boolean property that indicates whether the resize should
  740. * be animated or not.
  741. * @param isChatVisible boolean property that indicates whether the chat
  742. * area is displayed or not.
  743. * If that parameter is null the method will check the chat panel
  744. * visibility.
  745. * @param completeFunction a function to be called when the video space
  746. * is resized.
  747. */
  748. resizeVideoSpace (animate, isChatVisible, completeFunction) {
  749. var availableHeight = window.innerHeight;
  750. var availableWidth = UIUtil.getAvailableVideoWidth(isChatVisible);
  751. if (availableWidth < 0 || availableHeight < 0) return;
  752. if(animate) {
  753. $('#videospace').animate({
  754. right: window.innerWidth - availableWidth,
  755. width: availableWidth,
  756. height: availableHeight
  757. },
  758. {
  759. queue: false,
  760. duration: 500,
  761. complete: completeFunction
  762. });
  763. } else {
  764. $('#videospace').width(availableWidth).height(availableHeight);
  765. }
  766. },
  767. getSmallVideo (id) {
  768. if (APP.conference.isLocalId(id)) {
  769. return localVideoThumbnail;
  770. } else {
  771. return remoteVideos[id];
  772. }
  773. },
  774. changeUserAvatar (id, avatarUrl) {
  775. var smallVideo = VideoLayout.getSmallVideo(id);
  776. if (smallVideo) {
  777. smallVideo.avatarChanged(avatarUrl);
  778. } else {
  779. console.warn(
  780. "Missed avatar update - no small video yet for " + id
  781. );
  782. }
  783. if (this.isCurrentlyOnLarge(id)) {
  784. largeVideo.updateAvatar(avatarUrl);
  785. }
  786. },
  787. /**
  788. * Indicates that the video has been interrupted.
  789. */
  790. onVideoInterrupted () {
  791. this.enableVideoProblemFilter(true);
  792. let reconnectingKey = "connection.RECONNECTING";
  793. $('#videoConnectionMessage')
  794. .attr("data-i18n", reconnectingKey)
  795. .text(APP.translation.translateString(reconnectingKey))
  796. .css({display: "block"});
  797. },
  798. /**
  799. * Indicates that the video has been restored.
  800. */
  801. onVideoRestored () {
  802. this.enableVideoProblemFilter(false);
  803. $('#videoConnectionMessage').css({display: "none"});
  804. },
  805. enableVideoProblemFilter (enable) {
  806. if (!largeVideo) {
  807. return;
  808. }
  809. largeVideo.enableVideoProblemFilter(enable);
  810. },
  811. isLargeVideoVisible () {
  812. return this.isLargeContainerTypeVisible(VideoContainerType);
  813. },
  814. isCurrentlyOnLarge (id) {
  815. return largeVideo && largeVideo.id === id;
  816. },
  817. updateLargeVideo (id, forceUpdate) {
  818. if (!largeVideo) {
  819. return;
  820. }
  821. let isOnLarge = this.isCurrentlyOnLarge(id);
  822. let currentId = largeVideo.id;
  823. if (!isOnLarge || forceUpdate) {
  824. if (id !== currentId) {
  825. eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
  826. }
  827. if (currentId) {
  828. var oldSmallVideo = this.getSmallVideo(currentId);
  829. }
  830. let smallVideo = this.getSmallVideo(id);
  831. let videoType = this.getRemoteVideoType(id);
  832. largeVideo.updateLargeVideo(
  833. smallVideo.stream,
  834. videoType,
  835. // LargeVideoUpdatedCallBack
  836. function() {
  837. // update current small video and the old one
  838. smallVideo.updateView();
  839. oldSmallVideo && oldSmallVideo.updateView();
  840. // change the avatar url on large
  841. largeVideo.updateAvatar(Avatar.getAvatarUrl(smallVideo.id));
  842. // show the avatar on large if needed
  843. largeVideo.showAvatar(smallVideo.stream.isMuted());
  844. });
  845. } else if (currentId) {
  846. let currentSmallVideo = this.getSmallVideo(currentId);
  847. currentSmallVideo.updateView();
  848. }
  849. },
  850. addLargeVideoContainer (type, container) {
  851. largeVideo && largeVideo.addContainer(type, container);
  852. },
  853. removeLargeVideoContainer (type) {
  854. largeVideo && largeVideo.removeContainer(type);
  855. },
  856. /**
  857. * @returns Promise
  858. */
  859. showLargeVideoContainer (type, show) {
  860. if (!largeVideo) {
  861. return Promise.reject();
  862. }
  863. let isVisible = this.isLargeContainerTypeVisible(type);
  864. if (isVisible === show) {
  865. return Promise.resolve();
  866. }
  867. // if !show then use default type - large video
  868. return largeVideo.showContainer(show ? type : VideoContainerType);
  869. },
  870. isLargeContainerTypeVisible (type) {
  871. return largeVideo && largeVideo.state === type;
  872. },
  873. /**
  874. * Returns the id of the current video shown on large.
  875. * Currently used by tests (troture).
  876. */
  877. getLargeVideoID () {
  878. return largeVideo.id;
  879. }
  880. };
  881. export default VideoLayout;