Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

VideoLayout.js 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  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 LocalVideo from "./LocalVideo";
  12. import PanelToggler from "../side_pannels/SidePanelToggler";
  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. * Creates a remote video for participant for the given id.
  278. * @param id the id of the participant to add
  279. * @param {SmallVideo} smallVideo optional small video instance to add as a
  280. * remote video, if undefined RemoteVideo will be created
  281. */
  282. addParticipantContainer (id, smallVideo) {
  283. let remoteVideo;
  284. if(smallVideo)
  285. remoteVideo = smallVideo;
  286. else
  287. remoteVideo = new RemoteVideo(id, VideoLayout, eventEmitter);
  288. remoteVideos[id] = remoteVideo;
  289. let videoType = remoteVideoTypes[id];
  290. if (videoType) {
  291. remoteVideo.setVideoType(videoType);
  292. }
  293. // In case this is not currently in the last n we don't show it.
  294. if (localLastNCount && localLastNCount > 0 &&
  295. FilmStrip.getThumbs().length >= localLastNCount + 2) {
  296. remoteVideo.showPeerContainer('hide');
  297. } else {
  298. VideoLayout.resizeThumbnails(false, true);
  299. }
  300. },
  301. videoactive (videoelem, resourceJid) {
  302. console.info(resourceJid + " video is now active", videoelem);
  303. VideoLayout.resizeThumbnails(
  304. false, false, false, function() {$(videoelem).show();});
  305. // Update the large video to the last added video only if there's no
  306. // current dominant, focused speaker or update it to
  307. // the current dominant speaker.
  308. if ((!focusedVideoResourceJid &&
  309. !currentDominantSpeaker) ||
  310. focusedVideoResourceJid === resourceJid ||
  311. (resourceJid &&
  312. currentDominantSpeaker === resourceJid)) {
  313. this.updateLargeVideo(resourceJid, true);
  314. }
  315. },
  316. /**
  317. * Shows the presence status message for the given video.
  318. */
  319. setPresenceStatus (id, statusMsg) {
  320. remoteVideos[id].setPresenceStatus(statusMsg);
  321. },
  322. /**
  323. * Shows a visual indicator for the moderator of the conference.
  324. * On local or remote participants.
  325. */
  326. showModeratorIndicator () {
  327. let isModerator = APP.conference.isModerator;
  328. if (isModerator) {
  329. localVideoThumbnail.createModeratorIndicatorElement();
  330. }
  331. APP.conference.listMembers().forEach(function (member) {
  332. let id = member.getId();
  333. if (member.isModerator()) {
  334. remoteVideos[id].removeRemoteVideoMenu();
  335. remoteVideos[id].createModeratorIndicatorElement();
  336. } else if (isModerator) {
  337. // We are moderator, but user is not - add menu
  338. if ($(`#remote_popupmenu_${id}`).length <= 0) {
  339. remoteVideos[id].addRemoteVideoMenu();
  340. }
  341. }
  342. });
  343. },
  344. /*
  345. * Shows or hides the audio muted indicator over the local thumbnail video.
  346. * @param {boolean} isMuted
  347. */
  348. showLocalAudioIndicator (isMuted) {
  349. localVideoThumbnail.showAudioIndicator(isMuted);
  350. },
  351. /**
  352. * Resizes thumbnails.
  353. */
  354. resizeThumbnails ( animate = false,
  355. forceUpdate = false,
  356. isSideBarVisible = null,
  357. onComplete = null) {
  358. isSideBarVisible
  359. = (isSideBarVisible !== null)
  360. ? isSideBarVisible : PanelToggler.isVisible();
  361. let {thumbWidth, thumbHeight}
  362. = FilmStrip.calculateThumbnailSize(isSideBarVisible);
  363. $('.userAvatar').css('left', (thumbWidth - thumbHeight) / 2);
  364. FilmStrip.resizeThumbnails(thumbWidth, thumbHeight,
  365. animate, forceUpdate)
  366. .then(function () {
  367. BottomToolbar.resizeToolbar(thumbWidth, thumbHeight);
  368. AudioLevels.updateCanvasSize(thumbWidth, thumbHeight);
  369. if (onComplete && typeof onComplete === "function")
  370. onComplete();
  371. });
  372. return {thumbWidth, thumbHeight};
  373. },
  374. /**
  375. * On audio muted event.
  376. */
  377. onAudioMute (id, isMuted) {
  378. if (APP.conference.isLocalId(id)) {
  379. localVideoThumbnail.showAudioIndicator(isMuted);
  380. } else {
  381. remoteVideos[id].showAudioIndicator(isMuted);
  382. if (APP.conference.isModerator) {
  383. remoteVideos[id].updateRemoteVideoMenu(isMuted);
  384. }
  385. }
  386. },
  387. /**
  388. * On video muted event.
  389. */
  390. onVideoMute (id, value) {
  391. if (APP.conference.isLocalId(id)) {
  392. localVideoThumbnail.setMutedView(value);
  393. } else {
  394. var remoteVideo = remoteVideos[id];
  395. remoteVideo.setMutedView(value);
  396. }
  397. if (this.isCurrentlyOnLarge(id)) {
  398. // large video will show avatar instead of muted stream
  399. this.updateLargeVideo(id, true);
  400. }
  401. },
  402. /**
  403. * Display name changed.
  404. */
  405. onDisplayNameChanged (id, displayName, status) {
  406. if (id === 'localVideoContainer' ||
  407. APP.conference.isLocalId(id)) {
  408. localVideoThumbnail.setDisplayName(displayName);
  409. } else {
  410. remoteVideos[id].setDisplayName(displayName, status);
  411. }
  412. },
  413. /**
  414. * On dominant speaker changed event.
  415. */
  416. onDominantSpeakerChanged (id) {
  417. if (id === currentDominantSpeaker) {
  418. return;
  419. }
  420. let oldSpeakerRemoteVideo = remoteVideos[currentDominantSpeaker];
  421. // We ignore local user events, but just unmark remote user as dominant
  422. // while we are talking
  423. if (APP.conference.isLocalId(id)) {
  424. if(oldSpeakerRemoteVideo)
  425. {
  426. oldSpeakerRemoteVideo.updateDominantSpeakerIndicator(false);
  427. localVideoThumbnail.updateDominantSpeakerIndicator(true);
  428. currentDominantSpeaker = null;
  429. }
  430. return;
  431. }
  432. let remoteVideo = remoteVideos[id];
  433. if (!remoteVideo) {
  434. return;
  435. }
  436. // Update the current dominant speaker.
  437. remoteVideo.updateDominantSpeakerIndicator(true);
  438. localVideoThumbnail.updateDominantSpeakerIndicator(false);
  439. // let's remove the indications from the remote video if any
  440. if (oldSpeakerRemoteVideo) {
  441. oldSpeakerRemoteVideo.updateDominantSpeakerIndicator(false);
  442. }
  443. currentDominantSpeaker = id;
  444. // Local video will not have container found, but that's ok
  445. // since we don't want to switch to local video.
  446. // Update the large video if the video source is already available,
  447. // otherwise wait for the "videoactive.jingle" event.
  448. if (!focusedVideoResourceJid && remoteVideo.hasVideoStarted()) {
  449. this.updateLargeVideo(id);
  450. }
  451. },
  452. /**
  453. * On last N change event.
  454. *
  455. * @param lastNEndpoints the list of last N endpoints
  456. * @param endpointsEnteringLastN the list currently entering last N
  457. * endpoints
  458. */
  459. onLastNEndpointsChanged (lastNEndpoints, endpointsEnteringLastN) {
  460. if (this.lastNCount !== lastNEndpoints.length)
  461. this.lastNCount = lastNEndpoints.length;
  462. lastNEndpointsCache = lastNEndpoints;
  463. // Say A, B, C, D, E, and F are in a conference and LastN = 3.
  464. //
  465. // If LastN drops to, say, 2, because of adaptivity, then E should see
  466. // thumbnails for A, B and C. A and B are in E's server side LastN set,
  467. // so E sees them. C is only in E's local LastN set.
  468. //
  469. // If F starts talking and LastN = 3, then E should see thumbnails for
  470. // F, A, B. B gets "ejected" from E's server side LastN set, but it
  471. // enters E's local LastN ejecting C.
  472. // Increase the local LastN set size, if necessary.
  473. if (this.lastNCount > localLastNCount) {
  474. localLastNCount = this.lastNCount;
  475. }
  476. // Update the local LastN set preserving the order in which the
  477. // endpoints appeared in the LastN/local LastN set.
  478. var nextLocalLastNSet = lastNEndpoints.slice(0);
  479. for (var i = 0; i < localLastNSet.length; i++) {
  480. if (nextLocalLastNSet.length >= localLastNCount) {
  481. break;
  482. }
  483. var resourceJid = localLastNSet[i];
  484. if (nextLocalLastNSet.indexOf(resourceJid) === -1) {
  485. nextLocalLastNSet.push(resourceJid);
  486. }
  487. }
  488. localLastNSet = nextLocalLastNSet;
  489. var updateLargeVideo = false;
  490. // Handle LastN/local LastN changes.
  491. FilmStrip.getThumbs().each(( index, element ) => {
  492. var resourceJid = getPeerContainerResourceId(element);
  493. var smallVideo = remoteVideos[resourceJid];
  494. // We do not want to process any logic for our own(local) video
  495. // because the local participant is never in the lastN set.
  496. // The code of this function might detect that the local participant
  497. // has been dropped out of the lastN set and will update the large
  498. // video
  499. // Detected from avatar tests, where lastN event override
  500. // local video pinning
  501. if(APP.conference.isLocalId(resourceJid))
  502. return;
  503. var isReceived = true;
  504. if (resourceJid &&
  505. lastNEndpoints.indexOf(resourceJid) < 0 &&
  506. localLastNSet.indexOf(resourceJid) < 0) {
  507. console.log("Remove from last N", resourceJid);
  508. if (smallVideo)
  509. smallVideo.showPeerContainer('hide');
  510. else if (!APP.conference.isLocalId(resourceJid))
  511. console.error("No remote video for: " + resourceJid);
  512. isReceived = false;
  513. } else if (resourceJid &&
  514. smallVideo.isVisible() &&
  515. lastNEndpoints.indexOf(resourceJid) < 0 &&
  516. localLastNSet.indexOf(resourceJid) >= 0) {
  517. if (smallVideo)
  518. smallVideo.showPeerContainer('avatar');
  519. else if (!APP.conference.isLocalId(resourceJid))
  520. console.error("No remote video for: " + resourceJid);
  521. isReceived = false;
  522. }
  523. if (!isReceived) {
  524. // resourceJid has dropped out of the server side lastN set, so
  525. // it is no longer being received. If resourceJid was being
  526. // displayed in the large video we have to switch to another
  527. // user.
  528. if (!updateLargeVideo &&
  529. this.isCurrentlyOnLarge(resourceJid)) {
  530. updateLargeVideo = true;
  531. }
  532. }
  533. });
  534. if (!endpointsEnteringLastN || endpointsEnteringLastN.length < 0)
  535. endpointsEnteringLastN = lastNEndpoints;
  536. if (endpointsEnteringLastN && endpointsEnteringLastN.length > 0) {
  537. endpointsEnteringLastN.forEach(function (resourceJid) {
  538. var remoteVideo = remoteVideos[resourceJid];
  539. if (remoteVideo)
  540. remoteVideo.showPeerContainer('show');
  541. if (!remoteVideo.isVisible()) {
  542. console.log("Add to last N", resourceJid);
  543. remoteVideo.addRemoteStreamElement(remoteVideo.videoStream);
  544. if (lastNPickupId == resourceJid) {
  545. // Clean up the lastN pickup id.
  546. lastNPickupId = null;
  547. // Don't fire the events again, they've already
  548. // been fired in the contact list click handler.
  549. VideoLayout.handleVideoThumbClicked(
  550. false,
  551. resourceJid);
  552. updateLargeVideo = false;
  553. }
  554. remoteVideo.waitForPlayback(
  555. remoteVideo.selectVideoElement()[0],
  556. remoteVideo.videoStream);
  557. }
  558. });
  559. }
  560. // The endpoint that was being shown in the large video has dropped out
  561. // of the lastN set and there was no lastN pickup jid. We need to update
  562. // the large video now.
  563. if (updateLargeVideo) {
  564. var resource;
  565. // Find out which endpoint to show in the large video.
  566. for (i = 0; i < lastNEndpoints.length; i++) {
  567. resource = lastNEndpoints[i];
  568. if (!resource || APP.conference.isLocalId(resource))
  569. continue;
  570. // videoSrcToSsrc needs to be update for this call to succeed.
  571. this.updateLargeVideo(resource);
  572. break;
  573. }
  574. }
  575. },
  576. /**
  577. * Updates local stats
  578. * @param percent
  579. * @param object
  580. */
  581. updateLocalConnectionStats (percent, object) {
  582. let resolutions = object.resolution;
  583. object.resolution = resolutions[APP.conference.localId];
  584. localVideoThumbnail.updateStatsIndicator(percent, object);
  585. Object.keys(resolutions).forEach(function (id) {
  586. if (APP.conference.isLocalId(id)) {
  587. return;
  588. }
  589. let resolution = resolutions[id];
  590. let remoteVideo = remoteVideos[id];
  591. if (resolution && remoteVideo) {
  592. remoteVideo.updateResolution(resolution);
  593. }
  594. });
  595. },
  596. /**
  597. * Updates remote stats.
  598. * @param id the id associated with the stats
  599. * @param percent the connection quality percent
  600. * @param object the stats data
  601. */
  602. updateConnectionStats (id, percent, object) {
  603. if (remoteVideos[id]) {
  604. remoteVideos[id].updateStatsIndicator(percent, object);
  605. }
  606. },
  607. /**
  608. * Hides the connection indicator
  609. * @param id
  610. */
  611. hideConnectionIndicator (id) {
  612. remoteVideos[id].hideConnectionIndicator();
  613. },
  614. /**
  615. * Hides all the indicators
  616. */
  617. hideStats () {
  618. for(var video in remoteVideos) {
  619. remoteVideos[video].hideIndicator();
  620. }
  621. localVideoThumbnail.hideIndicator();
  622. },
  623. removeParticipantContainer (id) {
  624. // Unlock large video
  625. if (focusedVideoResourceJid === id) {
  626. console.info("Focused video owner has left the conference");
  627. focusedVideoResourceJid = null;
  628. }
  629. if (currentDominantSpeaker === id) {
  630. console.info("Dominant speaker has left the conference");
  631. currentDominantSpeaker = null;
  632. }
  633. var remoteVideo = remoteVideos[id];
  634. if (remoteVideo) {
  635. // Remove remote video
  636. console.info("Removing remote video: " + id);
  637. delete remoteVideos[id];
  638. remoteVideo.remove();
  639. } else {
  640. console.warn("No remote video for " + id);
  641. }
  642. VideoLayout.resizeThumbnails();
  643. },
  644. onVideoTypeChanged (id, newVideoType) {
  645. if (remoteVideoTypes[id] === newVideoType) {
  646. return;
  647. }
  648. console.info("Peer video type changed: ", id, newVideoType);
  649. remoteVideoTypes[id] = newVideoType;
  650. var smallVideo;
  651. if (APP.conference.isLocalId(id)) {
  652. if (!localVideoThumbnail) {
  653. console.warn("Local video not ready yet");
  654. return;
  655. }
  656. smallVideo = localVideoThumbnail;
  657. } else if (remoteVideos[id]) {
  658. smallVideo = remoteVideos[id];
  659. } else {
  660. return;
  661. }
  662. smallVideo.setVideoType(newVideoType);
  663. if (this.isCurrentlyOnLarge(id)) {
  664. this.updateLargeVideo(id, true);
  665. }
  666. },
  667. showMore (id) {
  668. if (id === 'local') {
  669. localVideoThumbnail.connectionIndicator.showMore();
  670. } else {
  671. let remoteVideo = remoteVideos[id];
  672. if (remoteVideo) {
  673. remoteVideo.connectionIndicator.showMore();
  674. } else {
  675. console.info("Error - no remote video for id: " + id);
  676. }
  677. }
  678. },
  679. /**
  680. * Resizes the video area.
  681. *
  682. * @param isSideBarVisible indicates if the side bar is currently visible
  683. * @param forceUpdate indicates that hidden thumbnails will be shown
  684. * @param completeFunction a function to be called when the video area is
  685. * resized.
  686. */resizeVideoArea (isSideBarVisible,
  687. forceUpdate = false,
  688. animate = false,
  689. completeFunction = null) {
  690. if (largeVideo) {
  691. largeVideo.updateContainerSize(isSideBarVisible);
  692. largeVideo.resize(animate);
  693. }
  694. // Calculate available width and height.
  695. let availableHeight = window.innerHeight;
  696. let availableWidth = UIUtil.getAvailableVideoWidth(isSideBarVisible);
  697. if (availableWidth < 0 || availableHeight < 0) {
  698. return;
  699. }
  700. // Resize the thumbnails first.
  701. this.resizeThumbnails(false, forceUpdate, isSideBarVisible);
  702. // Resize the video area element.
  703. $('#videospace').animate({
  704. right: window.innerWidth - availableWidth,
  705. width: availableWidth,
  706. height: availableHeight
  707. }, {
  708. queue: false,
  709. duration: animate ? 500 : 1,
  710. complete: completeFunction
  711. });
  712. },
  713. getSmallVideo (id) {
  714. if (APP.conference.isLocalId(id)) {
  715. return localVideoThumbnail;
  716. } else {
  717. return remoteVideos[id];
  718. }
  719. },
  720. changeUserAvatar (id, avatarUrl) {
  721. var smallVideo = VideoLayout.getSmallVideo(id);
  722. if (smallVideo) {
  723. smallVideo.avatarChanged(avatarUrl);
  724. } else {
  725. console.warn(
  726. "Missed avatar update - no small video yet for " + id
  727. );
  728. }
  729. if (this.isCurrentlyOnLarge(id)) {
  730. largeVideo.updateAvatar(avatarUrl);
  731. }
  732. },
  733. /**
  734. * Indicates that the video has been interrupted.
  735. */
  736. onVideoInterrupted () {
  737. this.enableVideoProblemFilter(true);
  738. let reconnectingKey = "connection.RECONNECTING";
  739. $('#videoConnectionMessage')
  740. .attr("data-i18n", reconnectingKey)
  741. .text(APP.translation.translateString(reconnectingKey))
  742. .css({display: "block"});
  743. },
  744. /**
  745. * Indicates that the video has been restored.
  746. */
  747. onVideoRestored () {
  748. this.enableVideoProblemFilter(false);
  749. $('#videoConnectionMessage').css({display: "none"});
  750. },
  751. enableVideoProblemFilter (enable) {
  752. if (!largeVideo) {
  753. return;
  754. }
  755. largeVideo.enableVideoProblemFilter(enable);
  756. },
  757. isLargeVideoVisible () {
  758. return this.isLargeContainerTypeVisible(VideoContainerType);
  759. },
  760. isCurrentlyOnLarge (id) {
  761. return largeVideo && largeVideo.id === id;
  762. },
  763. updateLargeVideo (id, forceUpdate) {
  764. if (!largeVideo) {
  765. return;
  766. }
  767. let isOnLarge = this.isCurrentlyOnLarge(id);
  768. let currentId = largeVideo.id;
  769. if (!isOnLarge || forceUpdate) {
  770. if (id !== currentId) {
  771. eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
  772. }
  773. if (currentId) {
  774. var oldSmallVideo = this.getSmallVideo(currentId);
  775. }
  776. let smallVideo = this.getSmallVideo(id);
  777. let videoType = this.getRemoteVideoType(id);
  778. largeVideo.updateLargeVideo(
  779. id,
  780. smallVideo.videoStream,
  781. videoType
  782. ).then(function() {
  783. // update current small video and the old one
  784. smallVideo.updateView();
  785. oldSmallVideo && oldSmallVideo.updateView();
  786. }, function () {
  787. // use clicked other video during update, nothing to do.
  788. });
  789. } else if (currentId) {
  790. let currentSmallVideo = this.getSmallVideo(currentId);
  791. currentSmallVideo.updateView();
  792. }
  793. },
  794. addLargeVideoContainer (type, container) {
  795. largeVideo && largeVideo.addContainer(type, container);
  796. },
  797. removeLargeVideoContainer (type) {
  798. largeVideo && largeVideo.removeContainer(type);
  799. },
  800. /**
  801. * @returns Promise
  802. */
  803. showLargeVideoContainer (type, show) {
  804. if (!largeVideo) {
  805. return Promise.reject();
  806. }
  807. let isVisible = this.isLargeContainerTypeVisible(type);
  808. if (isVisible === show) {
  809. return Promise.resolve();
  810. }
  811. // if !show then use default type - large video
  812. return largeVideo.showContainer(show ? type : VideoContainerType);
  813. },
  814. isLargeContainerTypeVisible (type) {
  815. return largeVideo && largeVideo.state === type;
  816. },
  817. /**
  818. * Returns the id of the current video shown on large.
  819. * Currently used by tests (troture).
  820. */
  821. getLargeVideoID () {
  822. return largeVideo.id;
  823. }
  824. };
  825. export default VideoLayout;