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 39KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. /* global config, APP, $, interfaceConfig */
  2. const logger = require("jitsi-meet-logger").getLogger(__filename);
  3. import FilmStrip from "./FilmStrip";
  4. import UIEvents from "../../../service/UI/UIEvents";
  5. import UIUtil from "../util/UIUtil";
  6. import RemoteVideo from "./RemoteVideo";
  7. import LargeVideoManager from "./LargeVideoManager";
  8. import {VIDEO_CONTAINER_TYPE} from "./VideoContainer";
  9. import LocalVideo from "./LocalVideo";
  10. var remoteVideos = {};
  11. var localVideoThumbnail = null;
  12. var currentDominantSpeaker = null;
  13. var localLastNCount = config.channelLastN;
  14. var localLastNSet = [];
  15. var lastNEndpointsCache = [];
  16. var lastNPickupId = null;
  17. var eventEmitter = null;
  18. /**
  19. * Currently focused video jid
  20. * @type {String}
  21. */
  22. var pinnedId = null;
  23. /**
  24. * flipX state of the localVideo
  25. */
  26. let localFlipX = null;
  27. /**
  28. * On contact list item clicked.
  29. */
  30. function onContactClicked (id) {
  31. if (APP.conference.isLocalId(id)) {
  32. $("#localVideoContainer").click();
  33. return;
  34. }
  35. let remoteVideo = remoteVideos[id];
  36. if (remoteVideo && remoteVideo.hasVideo()) {
  37. // It is not always the case that a videoThumb exists (if there is
  38. // no actual video).
  39. if (remoteVideo.hasVideoStarted()) {
  40. // We have a video src, great! Let's update the large video
  41. // now.
  42. VideoLayout.handleVideoThumbClicked(id);
  43. } else {
  44. // If we don't have a video src for jid, there's absolutely
  45. // no point in calling handleVideoThumbClicked; Quite
  46. // simply, it won't work because it needs an src to attach
  47. // to the large video.
  48. //
  49. // Instead, we trigger the pinned endpoint changed event to
  50. // let the bridge adjust its lastN set for myjid and store
  51. // the pinned user in the lastNPickupId variable to be
  52. // picked up later by the lastN changed event handler.
  53. lastNPickupId = id;
  54. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, remoteVideo, true);
  55. }
  56. }
  57. }
  58. /**
  59. * Handler for local flip X changed event.
  60. * @param {Object} val
  61. */
  62. function onLocalFlipXChanged (val) {
  63. localFlipX = val;
  64. if(largeVideo) {
  65. largeVideo.onLocalFlipXChange(val);
  66. }
  67. }
  68. /**
  69. * Returns the corresponding resource id to the given peer container
  70. * DOM element.
  71. *
  72. * @return the corresponding resource id to the given peer container
  73. * DOM element
  74. */
  75. function getPeerContainerResourceId (containerElement) {
  76. if (localVideoThumbnail.container === containerElement) {
  77. return localVideoThumbnail.id;
  78. }
  79. let i = containerElement.id.indexOf('participant_');
  80. if (i >= 0) {
  81. return containerElement.id.substring(i + 12);
  82. }
  83. }
  84. let largeVideo;
  85. var VideoLayout = {
  86. init (emitter) {
  87. eventEmitter = emitter;
  88. // Unregister listeners in case of reinitialization
  89. this.unregisterListeners();
  90. localVideoThumbnail = new LocalVideo(VideoLayout, emitter);
  91. // sets default video type of local video
  92. // FIXME container type is totally different thing from the video type
  93. localVideoThumbnail.setVideoType(VIDEO_CONTAINER_TYPE);
  94. // if we do not resize the thumbs here, if there is no video device
  95. // the local video thumb maybe one pixel
  96. this.resizeThumbnails(false, true);
  97. this.lastNCount = config.channelLastN;
  98. this.registerListeners();
  99. },
  100. /**
  101. * Registering listeners for UI events in Video layout component.
  102. *
  103. * @returns {void}
  104. */
  105. registerListeners() {
  106. eventEmitter.addListener(UIEvents.LOCAL_FLIPX_CHANGED,
  107. onLocalFlipXChanged);
  108. eventEmitter.addListener(UIEvents.CONTACT_CLICKED, onContactClicked);
  109. },
  110. /**
  111. * Unregistering listeners for UI events in Video layout component.
  112. *
  113. * @returns {void}
  114. */
  115. unregisterListeners() {
  116. eventEmitter.removeListener(UIEvents.CONTACT_CLICKED, onContactClicked);
  117. },
  118. initLargeVideo () {
  119. largeVideo = new LargeVideoManager(eventEmitter);
  120. if(localFlipX) {
  121. largeVideo.onLocalFlipXChange(localFlipX);
  122. }
  123. largeVideo.updateContainerSize();
  124. },
  125. /**
  126. * Sets the audio level of the video elements associated to the given id.
  127. *
  128. * @param id the video identifier in the form it comes from the library
  129. * @param lvl the new audio level to update to
  130. */
  131. setAudioLevel(id, lvl) {
  132. let smallVideo = this.getSmallVideo(id);
  133. if (smallVideo)
  134. smallVideo.updateAudioLevelIndicator(lvl);
  135. if (largeVideo && id === largeVideo.id)
  136. largeVideo.updateLargeVideoAudioLevel(lvl);
  137. },
  138. isInLastN (resource) {
  139. return this.lastNCount < 0 || // lastN is disabled
  140. // lastNEndpoints cache not built yet
  141. (this.lastNCount > 0 && !lastNEndpointsCache.length) ||
  142. (lastNEndpointsCache &&
  143. lastNEndpointsCache.indexOf(resource) !== -1);
  144. },
  145. changeLocalAudio (stream) {
  146. let localAudio = document.getElementById('localAudio');
  147. localAudio = stream.attach(localAudio);
  148. // Now when Temasys plugin is converting also <audio> elements to
  149. // plugin's <object>s, in current layout it will capture click events
  150. // before it reaches the local video object. We hide it here in order
  151. // to prevent that.
  152. //if (RTCBrowserType.isIExplorer()) {
  153. // The issue is not present on Safari. Also if we hide it in Safari
  154. // then the local audio track will have 'enabled' flag set to false
  155. // which will result in audio mute issues
  156. // $(localAudio).hide();
  157. localAudio.width = 1;
  158. localAudio.height = 1;
  159. //}
  160. },
  161. changeLocalVideo (stream) {
  162. let localId = APP.conference.getMyUserId();
  163. this.onVideoTypeChanged(localId, stream.videoType);
  164. if (!stream.isMuted()) {
  165. localVideoThumbnail.changeVideo(stream);
  166. }
  167. /* force update if we're currently being displayed */
  168. if (this.isCurrentlyOnLarge(localId)) {
  169. this.updateLargeVideo(localId, true);
  170. }
  171. },
  172. /**
  173. * Get's the localID of the conference and set it to the local video
  174. * (small one). This needs to be called as early as possible, when muc is
  175. * actually joined. Otherwise events can come with information like email
  176. * and setting them assume the id is already set.
  177. */
  178. mucJoined () {
  179. if (largeVideo && !largeVideo.id) {
  180. this.updateLargeVideo(APP.conference.getMyUserId(), true);
  181. }
  182. },
  183. /**
  184. * Adds or removes icons for not available camera and microphone.
  185. * @param resourceJid the jid of user
  186. * @param devices available devices
  187. */
  188. setDeviceAvailabilityIcons (id, devices) {
  189. if (APP.conference.isLocalId(id)) {
  190. localVideoThumbnail.setDeviceAvailabilityIcons(devices);
  191. return;
  192. }
  193. let video = remoteVideos[id];
  194. if (!video) {
  195. return;
  196. }
  197. video.setDeviceAvailabilityIcons(devices);
  198. },
  199. /**
  200. * Enables/disables device availability icons for the given participant id.
  201. * The default value is {true}.
  202. * @param id the identifier of the participant
  203. * @param enable {true} to enable device availability icons
  204. */
  205. enableDeviceAvailabilityIcons (id, enable) {
  206. let video;
  207. if (APP.conference.isLocalId(id)) {
  208. video = localVideoThumbnail;
  209. }
  210. else {
  211. video = remoteVideos[id];
  212. }
  213. if (video)
  214. video.enableDeviceAvailabilityIcons(enable);
  215. },
  216. /**
  217. * Shows/hides local video.
  218. * @param {boolean} true to make the local video visible, false - otherwise
  219. */
  220. setLocalVideoVisible(visible) {
  221. localVideoThumbnail.setVisible(visible);
  222. },
  223. /**
  224. * Checks if removed video is currently displayed and tries to display
  225. * another one instead.
  226. * Uses focusedID if any or dominantSpeakerID if any,
  227. * otherwise elects new video, in this order.
  228. */
  229. updateAfterThumbRemoved (id) {
  230. if (!this.isCurrentlyOnLarge(id)) {
  231. return;
  232. }
  233. let newId;
  234. if (pinnedId)
  235. newId = pinnedId;
  236. else if (currentDominantSpeaker)
  237. newId = currentDominantSpeaker;
  238. else // Otherwise select last visible video
  239. newId = this.electLastVisibleVideo();
  240. this.updateLargeVideo(newId);
  241. },
  242. electLastVisibleVideo () {
  243. // pick the last visible video in the row
  244. // if nobody else is left, this picks the local video
  245. let remoteThumbs = FilmStrip.getThumbs(true).remoteThumbs;
  246. let thumbs = remoteThumbs.filter('[id!="mixedstream"]');
  247. let lastVisible = thumbs.filter(':visible:last');
  248. if (lastVisible.length) {
  249. let id = getPeerContainerResourceId(lastVisible[0]);
  250. if (remoteVideos[id]) {
  251. logger.info("electLastVisibleVideo: " + id);
  252. return id;
  253. }
  254. // The RemoteVideo was removed (but the DOM elements may still
  255. // exist).
  256. }
  257. logger.info("Last visible video no longer exists");
  258. thumbs = FilmStrip.getThumbs().remoteThumbs;
  259. if (thumbs.length) {
  260. let id = getPeerContainerResourceId(thumbs[0]);
  261. if (remoteVideos[id]) {
  262. logger.info("electLastVisibleVideo: " + id);
  263. return id;
  264. }
  265. // The RemoteVideo was removed (but the DOM elements may
  266. // still exist).
  267. }
  268. // Go with local video
  269. logger.info("Fallback to local video...");
  270. let id = APP.conference.getMyUserId();
  271. logger.info("electLastVisibleVideo: " + id);
  272. return id;
  273. },
  274. onRemoteStreamAdded (stream) {
  275. let id = stream.getParticipantId();
  276. let remoteVideo = remoteVideos[id];
  277. if (!remoteVideo)
  278. return;
  279. remoteVideo.addRemoteStreamElement(stream);
  280. // if track is muted make sure we reflect that
  281. if(stream.isMuted())
  282. {
  283. if(stream.getType() === "audio")
  284. this.onAudioMute(stream.getParticipantId(), true);
  285. else
  286. this.onVideoMute(stream.getParticipantId(), true);
  287. }
  288. },
  289. onRemoteStreamRemoved (stream) {
  290. let id = stream.getParticipantId();
  291. let remoteVideo = remoteVideos[id];
  292. // Remote stream may be removed after participant left the conference.
  293. if (remoteVideo) {
  294. remoteVideo.removeRemoteStreamElement(stream);
  295. }
  296. },
  297. /**
  298. * Return the type of the remote video.
  299. * @param id the id for the remote video
  300. * @returns {String} the video type video or screen.
  301. */
  302. getRemoteVideoType (id) {
  303. let smallVideo = VideoLayout.getSmallVideo(id);
  304. return smallVideo ? smallVideo.getVideoType() : null;
  305. },
  306. isPinned (id) {
  307. return (pinnedId) ? (id === pinnedId) : false;
  308. },
  309. getPinnedId () {
  310. return pinnedId;
  311. },
  312. /**
  313. * Handles the click on a video thumbnail.
  314. *
  315. * @param id the identifier of the video thumbnail
  316. */
  317. handleVideoThumbClicked (id) {
  318. var smallVideo = VideoLayout.getSmallVideo(id);
  319. if(pinnedId) {
  320. var oldSmallVideo = VideoLayout.getSmallVideo(pinnedId);
  321. if (oldSmallVideo && !interfaceConfig.filmStripOnly) {
  322. oldSmallVideo.focus(false);
  323. // as no pinned event will be sent for local video
  324. // and we will unpin old one, lets signal it
  325. // otherwise we will just send the new pinned one
  326. if (smallVideo.isLocal)
  327. eventEmitter.emit(
  328. UIEvents.PINNED_ENDPOINT, oldSmallVideo, false);
  329. }
  330. }
  331. // Unpin if currently pinned.
  332. if (pinnedId === id)
  333. {
  334. pinnedId = null;
  335. // Enable the currently set dominant speaker.
  336. if (currentDominantSpeaker) {
  337. if(smallVideo && smallVideo.hasVideo()) {
  338. this.updateLargeVideo(currentDominantSpeaker);
  339. }
  340. } else {
  341. // if there is no currentDominantSpeaker, it can also be
  342. // that local participant is the dominant speaker
  343. // we should act as a participant has left and was on large
  344. // and we should choose somebody (electLastVisibleVideo)
  345. this.updateLargeVideo(this.electLastVisibleVideo());
  346. }
  347. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, smallVideo, false);
  348. return;
  349. }
  350. // Lock new video
  351. pinnedId = id;
  352. // Update focused/pinned interface.
  353. if (id) {
  354. if (smallVideo && !interfaceConfig.filmStripOnly)
  355. smallVideo.focus(true);
  356. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, smallVideo, true);
  357. }
  358. this.updateLargeVideo(id);
  359. },
  360. /**
  361. * Creates or adds a participant container for the given id and smallVideo.
  362. *
  363. * @param {JitsiParticipant} user the participant to add
  364. * @param {SmallVideo} smallVideo optional small video instance to add as a
  365. * remote video, if undefined <tt>RemoteVideo</tt> will be created
  366. */
  367. addParticipantContainer (user, smallVideo) {
  368. let id = user.getId();
  369. let remoteVideo;
  370. if(smallVideo)
  371. remoteVideo = smallVideo;
  372. else
  373. remoteVideo = new RemoteVideo(user, VideoLayout, eventEmitter);
  374. this._setRemoteControlProperties(user, remoteVideo);
  375. this.addRemoteVideoContainer(id, remoteVideo);
  376. },
  377. /**
  378. * Adds remote video container for the given id and <tt>SmallVideo</tt>.
  379. *
  380. * @param {string} the id of the video to add
  381. * @param {SmallVideo} smallVideo the small video instance to add as a
  382. * remote video
  383. */
  384. addRemoteVideoContainer (id, remoteVideo) {
  385. remoteVideos[id] = remoteVideo;
  386. if (!remoteVideo.getVideoType()) {
  387. // make video type the default one (camera)
  388. // FIXME container type is not a video type
  389. remoteVideo.setVideoType(VIDEO_CONTAINER_TYPE);
  390. }
  391. // In case this is not currently in the last n we don't show it.
  392. if (localLastNCount && localLastNCount > 0 &&
  393. FilmStrip.getThumbs().remoteThumbs.length >= localLastNCount + 2) {
  394. remoteVideo.showPeerContainer('hide');
  395. } else {
  396. VideoLayout.resizeThumbnails(false, true);
  397. }
  398. // Initialize the view
  399. remoteVideo.updateView();
  400. },
  401. // FIXME: what does this do???
  402. remoteVideoActive(videoElement, resourceJid) {
  403. logger.info(resourceJid + " video is now active", videoElement);
  404. VideoLayout.resizeThumbnails(
  405. false, false, function() {$(videoElement).show();});
  406. // Update the large video to the last added video only if there's no
  407. // current dominant, focused speaker or update it to
  408. // the current dominant speaker.
  409. if ((!pinnedId &&
  410. !currentDominantSpeaker &&
  411. this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE)) ||
  412. pinnedId === resourceJid ||
  413. (!pinnedId && resourceJid &&
  414. currentDominantSpeaker === resourceJid) ||
  415. /* Playback started while we're on the stage - may need to update
  416. video source with the new stream */
  417. this.isCurrentlyOnLarge(resourceJid)) {
  418. this.updateLargeVideo(resourceJid, true);
  419. }
  420. },
  421. /**
  422. * Shows a visual indicator for the moderator of the conference.
  423. * On local or remote participants.
  424. */
  425. showModeratorIndicator () {
  426. let isModerator = APP.conference.isModerator;
  427. if (isModerator) {
  428. localVideoThumbnail.addModeratorIndicator();
  429. } else {
  430. localVideoThumbnail.removeModeratorIndicator();
  431. }
  432. APP.conference.listMembers().forEach(function (member) {
  433. let id = member.getId();
  434. let remoteVideo = remoteVideos[id];
  435. if (!remoteVideo)
  436. return;
  437. if (member.isModerator()) {
  438. remoteVideo.addModeratorIndicator();
  439. }
  440. if (isModerator) {
  441. // We are moderator, but user is not - add menu
  442. if(!remoteVideo.hasRemoteVideoMenu) {
  443. remoteVideo.addRemoteVideoMenu();
  444. }
  445. }
  446. });
  447. },
  448. /*
  449. * Shows or hides the audio muted indicator over the local thumbnail video.
  450. * @param {boolean} isMuted
  451. */
  452. showLocalAudioIndicator (isMuted) {
  453. localVideoThumbnail.showAudioIndicator(isMuted);
  454. },
  455. /**
  456. * Shows/hides the indication about local connection being interrupted.
  457. *
  458. * @param {boolean} isInterrupted <tt>true</tt> if local connection is
  459. * currently in the interrupted state or <tt>false</tt> if the connection
  460. * is fine.
  461. */
  462. showLocalConnectionInterrupted (isInterrupted) {
  463. localVideoThumbnail.connectionIndicator
  464. .updateConnectionStatusIndicator(!isInterrupted);
  465. },
  466. /**
  467. * Resizes thumbnails.
  468. */
  469. resizeThumbnails ( animate = false,
  470. forceUpdate = false,
  471. onComplete = null) {
  472. const { localVideo, remoteVideo }
  473. = FilmStrip.calculateThumbnailSize();
  474. FilmStrip.resizeThumbnails(localVideo, remoteVideo,
  475. animate, forceUpdate)
  476. .then(function () {
  477. if (onComplete && typeof onComplete === "function")
  478. onComplete();
  479. });
  480. return { localVideo, remoteVideo };
  481. },
  482. /**
  483. * On audio muted event.
  484. */
  485. onAudioMute (id, isMuted) {
  486. if (APP.conference.isLocalId(id)) {
  487. localVideoThumbnail.showAudioIndicator(isMuted);
  488. } else {
  489. let remoteVideo = remoteVideos[id];
  490. if (!remoteVideo)
  491. return;
  492. remoteVideo.showAudioIndicator(isMuted);
  493. if (APP.conference.isModerator) {
  494. remoteVideo.updateRemoteVideoMenu(isMuted);
  495. }
  496. }
  497. },
  498. /**
  499. * On video muted event.
  500. */
  501. onVideoMute (id, value) {
  502. if (APP.conference.isLocalId(id)) {
  503. localVideoThumbnail.setVideoMutedView(value);
  504. } else {
  505. let remoteVideo = remoteVideos[id];
  506. if (remoteVideo)
  507. remoteVideo.setVideoMutedView(value);
  508. }
  509. if (this.isCurrentlyOnLarge(id)) {
  510. // large video will show avatar instead of muted stream
  511. this.updateLargeVideo(id, true);
  512. }
  513. },
  514. /**
  515. * Display name changed.
  516. */
  517. onDisplayNameChanged (id, displayName, status) {
  518. if (id === 'localVideoContainer' ||
  519. APP.conference.isLocalId(id)) {
  520. localVideoThumbnail.setDisplayName(displayName);
  521. } else {
  522. let remoteVideo = remoteVideos[id];
  523. if (remoteVideo)
  524. remoteVideo.setDisplayName(displayName, status);
  525. }
  526. },
  527. /**
  528. * Sets the "raised hand" status for a participant identified by 'id'.
  529. */
  530. setRaisedHandStatus(id, raisedHandStatus) {
  531. var video
  532. = APP.conference.isLocalId(id)
  533. ? localVideoThumbnail : remoteVideos[id];
  534. if (video) {
  535. video.showRaisedHandIndicator(raisedHandStatus);
  536. if (raisedHandStatus) {
  537. video.showDominantSpeakerIndicator(false);
  538. }
  539. }
  540. },
  541. /**
  542. * On dominant speaker changed event.
  543. */
  544. onDominantSpeakerChanged (id) {
  545. if (id === currentDominantSpeaker) {
  546. return;
  547. }
  548. let oldSpeakerRemoteVideo = remoteVideos[currentDominantSpeaker];
  549. // We ignore local user events, but just unmark remote user as dominant
  550. // while we are talking
  551. if (APP.conference.isLocalId(id)) {
  552. if(oldSpeakerRemoteVideo)
  553. {
  554. oldSpeakerRemoteVideo.showDominantSpeakerIndicator(false);
  555. currentDominantSpeaker = null;
  556. }
  557. localVideoThumbnail.showDominantSpeakerIndicator(true);
  558. return;
  559. }
  560. let remoteVideo = remoteVideos[id];
  561. if (!remoteVideo) {
  562. return;
  563. }
  564. // Update the current dominant speaker.
  565. remoteVideo.showDominantSpeakerIndicator(true);
  566. localVideoThumbnail.showDominantSpeakerIndicator(false);
  567. // let's remove the indications from the remote video if any
  568. if (oldSpeakerRemoteVideo) {
  569. oldSpeakerRemoteVideo.showDominantSpeakerIndicator(false);
  570. }
  571. currentDominantSpeaker = id;
  572. // Local video will not have container found, but that's ok
  573. // since we don't want to switch to local video.
  574. // Update the large video if the video source is already available,
  575. // otherwise wait for the "videoactive.jingle" event.
  576. // FIXME: there is no "videoactive.jingle" event.
  577. if (!interfaceConfig.filmStripOnly && !pinnedId
  578. && remoteVideo.hasVideoStarted()
  579. && !this.getCurrentlyOnLargeContainer().stayOnStage()) {
  580. this.updateLargeVideo(id);
  581. }
  582. },
  583. /**
  584. * Shows/hides warning about remote user's connectivity issues.
  585. *
  586. * @param {string} id the ID of the remote participant(MUC nickname)
  587. * @param {boolean} isActive true if the connection is ok or false when
  588. * the user is having connectivity issues.
  589. */
  590. // eslint-disable-next-line no-unused-vars
  591. onParticipantConnectionStatusChanged (id, isActive) {
  592. // Show/hide warning on the large video
  593. if (this.isCurrentlyOnLarge(id)) {
  594. if (largeVideo) {
  595. // We have to trigger full large video update to transition from
  596. // avatar to video on connectivity restored.
  597. this.updateLargeVideo(id, true /* force update */);
  598. }
  599. }
  600. // Show/hide warning on the thumbnail
  601. let remoteVideo = remoteVideos[id];
  602. if (remoteVideo) {
  603. // Updating only connection status indicator is not enough, because
  604. // when we the connection is restored while the avatar was displayed
  605. // (due to 'muted while disconnected' condition) we may want to show
  606. // the video stream again and in order to do that the display mode
  607. // must be updated.
  608. //remoteVideo.updateConnectionStatusIndicator(isActive);
  609. remoteVideo.updateView();
  610. }
  611. },
  612. /**
  613. * On last N change event.
  614. *
  615. * @param lastNEndpoints the list of last N endpoints
  616. * @param endpointsEnteringLastN the list currently entering last N
  617. * endpoints
  618. */
  619. onLastNEndpointsChanged (lastNEndpoints, endpointsEnteringLastN) {
  620. if (this.lastNCount !== lastNEndpoints.length)
  621. this.lastNCount = lastNEndpoints.length;
  622. lastNEndpointsCache = lastNEndpoints;
  623. // Say A, B, C, D, E, and F are in a conference and LastN = 3.
  624. //
  625. // If LastN drops to, say, 2, because of adaptivity, then E should see
  626. // thumbnails for A, B and C. A and B are in E's server side LastN set,
  627. // so E sees them. C is only in E's local LastN set.
  628. //
  629. // If F starts talking and LastN = 3, then E should see thumbnails for
  630. // F, A, B. B gets "ejected" from E's server side LastN set, but it
  631. // enters E's local LastN ejecting C.
  632. // Increase the local LastN set size, if necessary.
  633. if (this.lastNCount > localLastNCount) {
  634. localLastNCount = this.lastNCount;
  635. }
  636. // Update the local LastN set preserving the order in which the
  637. // endpoints appeared in the LastN/local LastN set.
  638. var nextLocalLastNSet = lastNEndpoints.slice(0);
  639. for (var i = 0; i < localLastNSet.length; i++) {
  640. if (nextLocalLastNSet.length >= localLastNCount) {
  641. break;
  642. }
  643. var resourceJid = localLastNSet[i];
  644. if (nextLocalLastNSet.indexOf(resourceJid) === -1) {
  645. nextLocalLastNSet.push(resourceJid);
  646. }
  647. }
  648. localLastNSet = nextLocalLastNSet;
  649. var updateLargeVideo = false;
  650. // Handle LastN/local LastN changes.
  651. FilmStrip.getThumbs().remoteThumbs.each(( index, element ) => {
  652. var resourceJid = getPeerContainerResourceId(element);
  653. var smallVideo = remoteVideos[resourceJid];
  654. // We do not want to process any logic for our own(local) video
  655. // because the local participant is never in the lastN set.
  656. // The code of this function might detect that the local participant
  657. // has been dropped out of the lastN set and will update the large
  658. // video
  659. // Detected from avatar tests, where lastN event override
  660. // local video pinning
  661. if(APP.conference.isLocalId(resourceJid))
  662. return;
  663. var isReceived = true;
  664. if (resourceJid &&
  665. lastNEndpoints.indexOf(resourceJid) < 0 &&
  666. localLastNSet.indexOf(resourceJid) < 0) {
  667. logger.log("Remove from last N", resourceJid);
  668. if (smallVideo)
  669. smallVideo.showPeerContainer('hide');
  670. else if (!APP.conference.isLocalId(resourceJid))
  671. logger.error("No remote video for: " + resourceJid);
  672. isReceived = false;
  673. } else if (resourceJid &&
  674. //TOFIX: smallVideo may be undefined
  675. smallVideo.isVisible() &&
  676. lastNEndpoints.indexOf(resourceJid) < 0 &&
  677. localLastNSet.indexOf(resourceJid) >= 0) {
  678. // TOFIX: if we're here we already know that the smallVideo
  679. // exists. Look at the previous FIX above.
  680. if (smallVideo)
  681. smallVideo.showPeerContainer('avatar');
  682. else if (!APP.conference.isLocalId(resourceJid))
  683. logger.error("No remote video for: " + resourceJid);
  684. isReceived = false;
  685. }
  686. if (!isReceived) {
  687. // resourceJid has dropped out of the server side lastN set, so
  688. // it is no longer being received. If resourceJid was being
  689. // displayed in the large video we have to switch to another
  690. // user.
  691. if (!updateLargeVideo &&
  692. this.isCurrentlyOnLarge(resourceJid)) {
  693. updateLargeVideo = true;
  694. }
  695. }
  696. });
  697. if (!endpointsEnteringLastN || endpointsEnteringLastN.length < 0)
  698. endpointsEnteringLastN = lastNEndpoints;
  699. if (endpointsEnteringLastN && endpointsEnteringLastN.length > 0) {
  700. endpointsEnteringLastN.forEach(function (resourceJid) {
  701. var remoteVideo = remoteVideos[resourceJid];
  702. if (remoteVideo)
  703. remoteVideo.showPeerContainer('show');
  704. if (!remoteVideo.isVisible()) {
  705. logger.log("Add to last N", resourceJid);
  706. remoteVideo.addRemoteStreamElement(remoteVideo.videoStream);
  707. if (lastNPickupId == resourceJid) {
  708. // Clean up the lastN pickup id.
  709. lastNPickupId = null;
  710. VideoLayout.handleVideoThumbClicked(resourceJid);
  711. updateLargeVideo = false;
  712. }
  713. remoteVideo.waitForPlayback(
  714. remoteVideo.selectVideoElement()[0],
  715. remoteVideo.videoStream);
  716. }
  717. });
  718. }
  719. // The endpoint that was being shown in the large video has dropped out
  720. // of the lastN set and there was no lastN pickup jid. We need to update
  721. // the large video now.
  722. if (updateLargeVideo) {
  723. var resource;
  724. // Find out which endpoint to show in the large video.
  725. for (i = 0; i < lastNEndpoints.length; i++) {
  726. resource = lastNEndpoints[i];
  727. if (!resource || APP.conference.isLocalId(resource))
  728. continue;
  729. // videoSrcToSsrc needs to be update for this call to succeed.
  730. this.updateLargeVideo(resource);
  731. break;
  732. }
  733. }
  734. },
  735. /**
  736. * Updates local stats
  737. * @param percent
  738. * @param object
  739. */
  740. updateLocalConnectionStats (percent, object) {
  741. const { framerate, resolution } = object;
  742. // FIXME overwrites 'lib-jitsi-meet' internal object
  743. // Why library internal objects are passed as event's args ?
  744. object.resolution = resolution[APP.conference.getMyUserId()];
  745. object.framerate = framerate[APP.conference.getMyUserId()];
  746. localVideoThumbnail.updateStatsIndicator(percent, object);
  747. Object.keys(resolution).forEach(function (id) {
  748. if (APP.conference.isLocalId(id)) {
  749. return;
  750. }
  751. let resolutionValue = resolution[id];
  752. let remoteVideo = remoteVideos[id];
  753. if (resolutionValue && remoteVideo) {
  754. remoteVideo.updateResolution(resolutionValue);
  755. }
  756. });
  757. },
  758. /**
  759. * Updates remote stats.
  760. * @param id the id associated with the stats
  761. * @param percent the connection quality percent
  762. * @param object the stats data
  763. */
  764. updateConnectionStats (id, percent, object) {
  765. let remoteVideo = remoteVideos[id];
  766. if (remoteVideo) {
  767. remoteVideo.updateStatsIndicator(percent, object);
  768. }
  769. },
  770. /**
  771. * Hides the connection indicator
  772. * @param id
  773. */
  774. hideConnectionIndicator (id) {
  775. let remoteVideo = remoteVideos[id];
  776. if (remoteVideo)
  777. remoteVideo.hideConnectionIndicator();
  778. },
  779. /**
  780. * Hides all the indicators
  781. */
  782. hideStats () {
  783. for (var video in remoteVideos) {
  784. let remoteVideo = remoteVideos[video];
  785. if (remoteVideo)
  786. remoteVideo.hideIndicator();
  787. }
  788. localVideoThumbnail.hideIndicator();
  789. },
  790. removeParticipantContainer (id) {
  791. // Unlock large video
  792. if (pinnedId === id) {
  793. logger.info("Focused video owner has left the conference");
  794. pinnedId = null;
  795. }
  796. if (currentDominantSpeaker === id) {
  797. logger.info("Dominant speaker has left the conference");
  798. currentDominantSpeaker = null;
  799. }
  800. var remoteVideo = remoteVideos[id];
  801. if (remoteVideo) {
  802. // Remove remote video
  803. logger.info("Removing remote video: " + id);
  804. delete remoteVideos[id];
  805. remoteVideo.remove();
  806. } else {
  807. logger.warn("No remote video for " + id);
  808. }
  809. VideoLayout.resizeThumbnails();
  810. },
  811. onVideoTypeChanged (id, newVideoType) {
  812. if (VideoLayout.getRemoteVideoType(id) === newVideoType) {
  813. return;
  814. }
  815. logger.info("Peer video type changed: ", id, newVideoType);
  816. var smallVideo;
  817. if (APP.conference.isLocalId(id)) {
  818. if (!localVideoThumbnail) {
  819. logger.warn("Local video not ready yet");
  820. return;
  821. }
  822. smallVideo = localVideoThumbnail;
  823. } else if (remoteVideos[id]) {
  824. smallVideo = remoteVideos[id];
  825. } else {
  826. return;
  827. }
  828. smallVideo.setVideoType(newVideoType);
  829. if (this.isCurrentlyOnLarge(id)) {
  830. this.updateLargeVideo(id, true);
  831. }
  832. },
  833. showMore (id) {
  834. if (id === 'local') {
  835. localVideoThumbnail.connectionIndicator.showMore();
  836. } else {
  837. let remoteVideo = remoteVideos[id];
  838. if (remoteVideo) {
  839. remoteVideo.connectionIndicator.showMore();
  840. } else {
  841. logger.info("Error - no remote video for id: " + id);
  842. }
  843. }
  844. },
  845. /**
  846. * Resizes the video area.
  847. *
  848. * @param forceUpdate indicates that hidden thumbnails will be shown
  849. * @param completeFunction a function to be called when the video area is
  850. * resized.
  851. */
  852. resizeVideoArea (forceUpdate = false,
  853. animate = false,
  854. completeFunction = null) {
  855. if (largeVideo) {
  856. largeVideo.updateContainerSize();
  857. largeVideo.resize(animate);
  858. }
  859. // Calculate available width and height.
  860. let availableHeight = window.innerHeight;
  861. let availableWidth = UIUtil.getAvailableVideoWidth();
  862. if (availableWidth < 0 || availableHeight < 0) {
  863. return;
  864. }
  865. // Resize the thumbnails first.
  866. this.resizeThumbnails(false, forceUpdate);
  867. // Resize the video area element.
  868. $('#videospace').animate({
  869. right: window.innerWidth - availableWidth,
  870. width: availableWidth,
  871. height: availableHeight
  872. }, {
  873. queue: false,
  874. duration: animate ? 500 : 1,
  875. complete: completeFunction
  876. });
  877. },
  878. getSmallVideo (id) {
  879. if (APP.conference.isLocalId(id)) {
  880. return localVideoThumbnail;
  881. } else {
  882. return remoteVideos[id];
  883. }
  884. },
  885. changeUserAvatar (id, avatarUrl) {
  886. var smallVideo = VideoLayout.getSmallVideo(id);
  887. if (smallVideo) {
  888. smallVideo.avatarChanged(avatarUrl);
  889. } else {
  890. logger.warn(
  891. "Missed avatar update - no small video yet for " + id
  892. );
  893. }
  894. if (this.isCurrentlyOnLarge(id)) {
  895. largeVideo.updateAvatar(avatarUrl);
  896. }
  897. },
  898. /**
  899. * Indicates that the video has been interrupted.
  900. */
  901. onVideoInterrupted () {
  902. if (largeVideo) {
  903. largeVideo.onVideoInterrupted();
  904. }
  905. },
  906. /**
  907. * Indicates that the video has been restored.
  908. */
  909. onVideoRestored () {
  910. if (largeVideo) {
  911. largeVideo.onVideoRestored();
  912. }
  913. },
  914. isLargeVideoVisible () {
  915. return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
  916. },
  917. /**
  918. * @return {LargeContainer} the currently displayed container on large
  919. * video.
  920. */
  921. getCurrentlyOnLargeContainer () {
  922. return largeVideo.getContainer(largeVideo.state);
  923. },
  924. isCurrentlyOnLarge (id) {
  925. return largeVideo && largeVideo.id === id;
  926. },
  927. updateLargeVideo (id, forceUpdate) {
  928. if (!largeVideo) {
  929. return;
  930. }
  931. let isOnLarge = this.isCurrentlyOnLarge(id);
  932. let currentId = largeVideo.id;
  933. if (!isOnLarge || forceUpdate) {
  934. let videoType = this.getRemoteVideoType(id);
  935. // FIXME video type is not the same thing as container type
  936. if (id !== currentId && videoType === VIDEO_CONTAINER_TYPE) {
  937. eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
  938. }
  939. let smallVideo = this.getSmallVideo(id);
  940. let oldSmallVideo;
  941. if (currentId) {
  942. oldSmallVideo = this.getSmallVideo(currentId);
  943. }
  944. smallVideo.waitForResolutionChange();
  945. if (oldSmallVideo)
  946. oldSmallVideo.waitForResolutionChange();
  947. largeVideo.updateLargeVideo(
  948. id,
  949. smallVideo.videoStream,
  950. videoType
  951. ).then(function() {
  952. // update current small video and the old one
  953. smallVideo.updateView();
  954. oldSmallVideo && oldSmallVideo.updateView();
  955. }, function () {
  956. // use clicked other video during update, nothing to do.
  957. });
  958. } else if (currentId) {
  959. let currentSmallVideo = this.getSmallVideo(currentId);
  960. currentSmallVideo.updateView();
  961. }
  962. },
  963. addLargeVideoContainer (type, container) {
  964. largeVideo && largeVideo.addContainer(type, container);
  965. },
  966. removeLargeVideoContainer (type) {
  967. largeVideo && largeVideo.removeContainer(type);
  968. },
  969. /**
  970. * @returns Promise
  971. */
  972. showLargeVideoContainer (type, show) {
  973. if (!largeVideo) {
  974. return Promise.reject();
  975. }
  976. let isVisible = this.isLargeContainerTypeVisible(type);
  977. if (isVisible === show) {
  978. return Promise.resolve();
  979. }
  980. let currentId = largeVideo.id;
  981. if(currentId) {
  982. var oldSmallVideo = this.getSmallVideo(currentId);
  983. }
  984. let containerTypeToShow = type;
  985. // if we are hiding a container and there is focusedVideo
  986. // (pinned remote video) use its video type,
  987. // if not then use default type - large video
  988. if (!show) {
  989. if(pinnedId)
  990. containerTypeToShow = this.getRemoteVideoType(pinnedId);
  991. else
  992. containerTypeToShow = VIDEO_CONTAINER_TYPE;
  993. }
  994. return largeVideo.showContainer(containerTypeToShow)
  995. .then(() => {
  996. if(oldSmallVideo)
  997. oldSmallVideo && oldSmallVideo.updateView();
  998. });
  999. },
  1000. isLargeContainerTypeVisible (type) {
  1001. return largeVideo && largeVideo.state === type;
  1002. },
  1003. /**
  1004. * Returns the id of the current video shown on large.
  1005. * Currently used by tests (torture).
  1006. */
  1007. getLargeVideoID () {
  1008. return largeVideo.id;
  1009. },
  1010. /**
  1011. * Returns the the current video shown on large.
  1012. * Currently used by tests (torture).
  1013. */
  1014. getLargeVideo () {
  1015. return largeVideo;
  1016. },
  1017. /**
  1018. * Updates the resolution label, indicating to the user that the large
  1019. * video stream is currently HD.
  1020. */
  1021. updateResolutionLabel(isResolutionHD) {
  1022. let id = 'videoResolutionLabel';
  1023. UIUtil.setVisible(id, isResolutionHD);
  1024. },
  1025. /**
  1026. * Sets the flipX state of the local video.
  1027. * @param {boolean} true for flipped otherwise false;
  1028. */
  1029. setLocalFlipX (val) {
  1030. this.localFlipX = val;
  1031. },
  1032. getEventEmitter() {return eventEmitter;},
  1033. /**
  1034. * Handles user's features changes.
  1035. */
  1036. onUserFeaturesChanged (user) {
  1037. let video = this.getSmallVideo(user.getId());
  1038. if (!video) {
  1039. return;
  1040. }
  1041. this._setRemoteControlProperties(user, video);
  1042. },
  1043. /**
  1044. * Sets the remote control properties (checks whether remote control
  1045. * is supported and executes remoteVideo.setRemoteControlSupport).
  1046. * @param {JitsiParticipant} user the user that will be checked for remote
  1047. * control support.
  1048. * @param {RemoteVideo} remoteVideo the remoteVideo on which the properties
  1049. * will be set.
  1050. */
  1051. _setRemoteControlProperties (user, remoteVideo) {
  1052. APP.remoteControl.checkUserRemoteControlSupport(user).then(result =>
  1053. remoteVideo.setRemoteControlSupport(result));
  1054. },
  1055. /**
  1056. * Returns the wrapper jquery selector for the largeVideo
  1057. * @returns {JQuerySelector} the wrapper jquery selector for the largeVideo
  1058. */
  1059. getLargeVideoWrapper() {
  1060. return this.getCurrentlyOnLargeContainer().$wrapper;
  1061. }
  1062. };
  1063. export default VideoLayout;