You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VideoLayout.js 31KB

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