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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  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. object.resolution = resolution[APP.conference.getMyUserId()];
  743. object.framerate = framerate[APP.conference.getMyUserId()];
  744. localVideoThumbnail.updateStatsIndicator(percent, object);
  745. Object.keys(resolution).forEach(function (id) {
  746. if (APP.conference.isLocalId(id)) {
  747. return;
  748. }
  749. let resolutionValue = resolution[id];
  750. let remoteVideo = remoteVideos[id];
  751. if (resolutionValue && remoteVideo) {
  752. remoteVideo.updateResolution(resolutionValue);
  753. }
  754. });
  755. },
  756. /**
  757. * Updates remote stats.
  758. * @param id the id associated with the stats
  759. * @param percent the connection quality percent
  760. * @param object the stats data
  761. */
  762. updateConnectionStats (id, percent, object) {
  763. let remoteVideo = remoteVideos[id];
  764. if (remoteVideo) {
  765. remoteVideo.updateStatsIndicator(percent, object);
  766. }
  767. },
  768. /**
  769. * Hides the connection indicator
  770. * @param id
  771. */
  772. hideConnectionIndicator (id) {
  773. let remoteVideo = remoteVideos[id];
  774. if (remoteVideo)
  775. remoteVideo.hideConnectionIndicator();
  776. },
  777. /**
  778. * Hides all the indicators
  779. */
  780. hideStats () {
  781. for (var video in remoteVideos) {
  782. let remoteVideo = remoteVideos[video];
  783. if (remoteVideo)
  784. remoteVideo.hideIndicator();
  785. }
  786. localVideoThumbnail.hideIndicator();
  787. },
  788. removeParticipantContainer (id) {
  789. // Unlock large video
  790. if (pinnedId === id) {
  791. logger.info("Focused video owner has left the conference");
  792. pinnedId = null;
  793. }
  794. if (currentDominantSpeaker === id) {
  795. logger.info("Dominant speaker has left the conference");
  796. currentDominantSpeaker = null;
  797. }
  798. var remoteVideo = remoteVideos[id];
  799. if (remoteVideo) {
  800. // Remove remote video
  801. logger.info("Removing remote video: " + id);
  802. delete remoteVideos[id];
  803. remoteVideo.remove();
  804. } else {
  805. logger.warn("No remote video for " + id);
  806. }
  807. VideoLayout.resizeThumbnails();
  808. },
  809. onVideoTypeChanged (id, newVideoType) {
  810. if (VideoLayout.getRemoteVideoType(id) === newVideoType) {
  811. return;
  812. }
  813. logger.info("Peer video type changed: ", id, newVideoType);
  814. var smallVideo;
  815. if (APP.conference.isLocalId(id)) {
  816. if (!localVideoThumbnail) {
  817. logger.warn("Local video not ready yet");
  818. return;
  819. }
  820. smallVideo = localVideoThumbnail;
  821. } else if (remoteVideos[id]) {
  822. smallVideo = remoteVideos[id];
  823. } else {
  824. return;
  825. }
  826. smallVideo.setVideoType(newVideoType);
  827. if (this.isCurrentlyOnLarge(id)) {
  828. this.updateLargeVideo(id, true);
  829. }
  830. },
  831. showMore (id) {
  832. if (id === 'local') {
  833. localVideoThumbnail.connectionIndicator.showMore();
  834. } else {
  835. let remoteVideo = remoteVideos[id];
  836. if (remoteVideo) {
  837. remoteVideo.connectionIndicator.showMore();
  838. } else {
  839. logger.info("Error - no remote video for id: " + id);
  840. }
  841. }
  842. },
  843. /**
  844. * Resizes the video area.
  845. *
  846. * @param forceUpdate indicates that hidden thumbnails will be shown
  847. * @param completeFunction a function to be called when the video area is
  848. * resized.
  849. */
  850. resizeVideoArea (forceUpdate = false,
  851. animate = false,
  852. completeFunction = null) {
  853. if (largeVideo) {
  854. largeVideo.updateContainerSize();
  855. largeVideo.resize(animate);
  856. }
  857. // Calculate available width and height.
  858. let availableHeight = window.innerHeight;
  859. let availableWidth = UIUtil.getAvailableVideoWidth();
  860. if (availableWidth < 0 || availableHeight < 0) {
  861. return;
  862. }
  863. // Resize the thumbnails first.
  864. this.resizeThumbnails(false, forceUpdate);
  865. // Resize the video area element.
  866. $('#videospace').animate({
  867. right: window.innerWidth - availableWidth,
  868. width: availableWidth,
  869. height: availableHeight
  870. }, {
  871. queue: false,
  872. duration: animate ? 500 : 1,
  873. complete: completeFunction
  874. });
  875. },
  876. getSmallVideo (id) {
  877. if (APP.conference.isLocalId(id)) {
  878. return localVideoThumbnail;
  879. } else {
  880. return remoteVideos[id];
  881. }
  882. },
  883. changeUserAvatar (id, avatarUrl) {
  884. var smallVideo = VideoLayout.getSmallVideo(id);
  885. if (smallVideo) {
  886. smallVideo.avatarChanged(avatarUrl);
  887. } else {
  888. logger.warn(
  889. "Missed avatar update - no small video yet for " + id
  890. );
  891. }
  892. if (this.isCurrentlyOnLarge(id)) {
  893. largeVideo.updateAvatar(avatarUrl);
  894. }
  895. },
  896. /**
  897. * Indicates that the video has been interrupted.
  898. */
  899. onVideoInterrupted () {
  900. if (largeVideo) {
  901. largeVideo.onVideoInterrupted();
  902. }
  903. },
  904. /**
  905. * Indicates that the video has been restored.
  906. */
  907. onVideoRestored () {
  908. if (largeVideo) {
  909. largeVideo.onVideoRestored();
  910. }
  911. },
  912. isLargeVideoVisible () {
  913. return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
  914. },
  915. /**
  916. * @return {LargeContainer} the currently displayed container on large
  917. * video.
  918. */
  919. getCurrentlyOnLargeContainer () {
  920. return largeVideo.getContainer(largeVideo.state);
  921. },
  922. isCurrentlyOnLarge (id) {
  923. return largeVideo && largeVideo.id === id;
  924. },
  925. updateLargeVideo (id, forceUpdate) {
  926. if (!largeVideo) {
  927. return;
  928. }
  929. let isOnLarge = this.isCurrentlyOnLarge(id);
  930. let currentId = largeVideo.id;
  931. if (!isOnLarge || forceUpdate) {
  932. let videoType = this.getRemoteVideoType(id);
  933. // FIXME video type is not the same thing as container type
  934. if (id !== currentId && videoType === VIDEO_CONTAINER_TYPE) {
  935. eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
  936. }
  937. let smallVideo = this.getSmallVideo(id);
  938. let oldSmallVideo;
  939. if (currentId) {
  940. oldSmallVideo = this.getSmallVideo(currentId);
  941. }
  942. smallVideo.waitForResolutionChange();
  943. if (oldSmallVideo)
  944. oldSmallVideo.waitForResolutionChange();
  945. largeVideo.updateLargeVideo(
  946. id,
  947. smallVideo.videoStream,
  948. videoType
  949. ).then(function() {
  950. // update current small video and the old one
  951. smallVideo.updateView();
  952. oldSmallVideo && oldSmallVideo.updateView();
  953. }, function () {
  954. // use clicked other video during update, nothing to do.
  955. });
  956. } else if (currentId) {
  957. let currentSmallVideo = this.getSmallVideo(currentId);
  958. currentSmallVideo.updateView();
  959. }
  960. },
  961. addLargeVideoContainer (type, container) {
  962. largeVideo && largeVideo.addContainer(type, container);
  963. },
  964. removeLargeVideoContainer (type) {
  965. largeVideo && largeVideo.removeContainer(type);
  966. },
  967. /**
  968. * @returns Promise
  969. */
  970. showLargeVideoContainer (type, show) {
  971. if (!largeVideo) {
  972. return Promise.reject();
  973. }
  974. let isVisible = this.isLargeContainerTypeVisible(type);
  975. if (isVisible === show) {
  976. return Promise.resolve();
  977. }
  978. let currentId = largeVideo.id;
  979. if(currentId) {
  980. var oldSmallVideo = this.getSmallVideo(currentId);
  981. }
  982. let containerTypeToShow = type;
  983. // if we are hiding a container and there is focusedVideo
  984. // (pinned remote video) use its video type,
  985. // if not then use default type - large video
  986. if (!show) {
  987. if(pinnedId)
  988. containerTypeToShow = this.getRemoteVideoType(pinnedId);
  989. else
  990. containerTypeToShow = VIDEO_CONTAINER_TYPE;
  991. }
  992. return largeVideo.showContainer(containerTypeToShow)
  993. .then(() => {
  994. if(oldSmallVideo)
  995. oldSmallVideo && oldSmallVideo.updateView();
  996. });
  997. },
  998. isLargeContainerTypeVisible (type) {
  999. return largeVideo && largeVideo.state === type;
  1000. },
  1001. /**
  1002. * Returns the id of the current video shown on large.
  1003. * Currently used by tests (torture).
  1004. */
  1005. getLargeVideoID () {
  1006. return largeVideo.id;
  1007. },
  1008. /**
  1009. * Returns the the current video shown on large.
  1010. * Currently used by tests (torture).
  1011. */
  1012. getLargeVideo () {
  1013. return largeVideo;
  1014. },
  1015. /**
  1016. * Updates the resolution label, indicating to the user that the large
  1017. * video stream is currently HD.
  1018. */
  1019. updateResolutionLabel(isResolutionHD) {
  1020. let id = 'videoResolutionLabel';
  1021. UIUtil.setVisible(id, isResolutionHD);
  1022. },
  1023. /**
  1024. * Sets the flipX state of the local video.
  1025. * @param {boolean} true for flipped otherwise false;
  1026. */
  1027. setLocalFlipX (val) {
  1028. this.localFlipX = val;
  1029. },
  1030. getEventEmitter() {return eventEmitter;},
  1031. /**
  1032. * Handles user's features changes.
  1033. */
  1034. onUserFeaturesChanged (user) {
  1035. let video = this.getSmallVideo(user.getId());
  1036. if (!video) {
  1037. return;
  1038. }
  1039. this._setRemoteControlProperties(user, video);
  1040. },
  1041. /**
  1042. * Sets the remote control properties (checks whether remote control
  1043. * is supported and executes remoteVideo.setRemoteControlSupport).
  1044. * @param {JitsiParticipant} user the user that will be checked for remote
  1045. * control support.
  1046. * @param {RemoteVideo} remoteVideo the remoteVideo on which the properties
  1047. * will be set.
  1048. */
  1049. _setRemoteControlProperties (user, remoteVideo) {
  1050. APP.remoteControl.checkUserRemoteControlSupport(user).then(result =>
  1051. remoteVideo.setRemoteControlSupport(result));
  1052. },
  1053. /**
  1054. * Returns the wrapper jquery selector for the largeVideo
  1055. * @returns {JQuerySelector} the wrapper jquery selector for the largeVideo
  1056. */
  1057. getLargeVideoWrapper() {
  1058. return this.getCurrentlyOnLargeContainer().$wrapper;
  1059. }
  1060. };
  1061. export default VideoLayout;