您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

VideoLayout.js 31KB

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