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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. /* global APP, $, interfaceConfig */
  2. const logger = require('jitsi-meet-logger').getLogger(__filename);
  3. import {
  4. getNearestReceiverVideoQualityLevel,
  5. setMaxReceiverVideoQuality
  6. } from '../../../react/features/base/conference';
  7. import {
  8. JitsiParticipantConnectionStatus
  9. } from '../../../react/features/base/lib-jitsi-meet';
  10. import { VIDEO_TYPE } from '../../../react/features/base/media';
  11. import {
  12. getLocalParticipant as getLocalParticipantFromStore,
  13. getPinnedParticipant,
  14. pinParticipant
  15. } from '../../../react/features/base/participants';
  16. import {
  17. shouldDisplayTileView
  18. } from '../../../react/features/video-layout';
  19. import { SHARED_VIDEO_CONTAINER_TYPE } from '../shared_video/SharedVideo';
  20. import SharedVideoThumb from '../shared_video/SharedVideoThumb';
  21. import Filmstrip from './Filmstrip';
  22. import UIEvents from '../../../service/UI/UIEvents';
  23. import UIUtil from '../util/UIUtil';
  24. import RemoteVideo from './RemoteVideo';
  25. import LargeVideoManager from './LargeVideoManager';
  26. import { VIDEO_CONTAINER_TYPE } from './VideoContainer';
  27. import LocalVideo from './LocalVideo';
  28. const remoteVideos = {};
  29. let localVideoThumbnail = null;
  30. let eventEmitter = null;
  31. let largeVideo;
  32. /**
  33. * flipX state of the localVideo
  34. */
  35. let localFlipX = null;
  36. /**
  37. * Handler for local flip X changed event.
  38. * @param {Object} val
  39. */
  40. function onLocalFlipXChanged(val) {
  41. localFlipX = val;
  42. if (largeVideo) {
  43. largeVideo.onLocalFlipXChange(val);
  44. }
  45. }
  46. /**
  47. * Returns the redux representation of all known users.
  48. *
  49. * @private
  50. * @returns {Array}
  51. */
  52. function getAllParticipants() {
  53. return APP.store.getState()['features/base/participants'];
  54. }
  55. /**
  56. * Returns an array of all thumbnails in the filmstrip.
  57. *
  58. * @private
  59. * @returns {Array}
  60. */
  61. function getAllThumbnails() {
  62. return [
  63. localVideoThumbnail,
  64. ...Object.values(remoteVideos)
  65. ];
  66. }
  67. /**
  68. * Private helper to get the redux representation of the local participant.
  69. *
  70. * @private
  71. * @returns {Object}
  72. */
  73. function getLocalParticipant() {
  74. return getLocalParticipantFromStore(APP.store.getState());
  75. }
  76. /**
  77. * Returns the user ID of the remote participant that is current the dominant
  78. * speaker.
  79. *
  80. * @private
  81. * @returns {string|null}
  82. */
  83. function getCurrentRemoteDominantSpeakerID() {
  84. const dominantSpeaker = getAllParticipants()
  85. .find(participant => participant.dominantSpeaker);
  86. if (dominantSpeaker) {
  87. return dominantSpeaker.local ? null : dominantSpeaker.id;
  88. }
  89. return null;
  90. }
  91. /**
  92. * Returns the corresponding resource id to the given peer container
  93. * DOM element.
  94. *
  95. * @return the corresponding resource id to the given peer container
  96. * DOM element
  97. */
  98. function getPeerContainerResourceId(containerElement) {
  99. if (localVideoThumbnail.container === containerElement) {
  100. return localVideoThumbnail.id;
  101. }
  102. const i = containerElement.id.indexOf('participant_');
  103. if (i >= 0) {
  104. return containerElement.id.substring(i + 12);
  105. }
  106. }
  107. const VideoLayout = {
  108. init(emitter) {
  109. eventEmitter = emitter;
  110. localVideoThumbnail = new LocalVideo(
  111. VideoLayout,
  112. emitter,
  113. this._updateLargeVideoIfDisplayed.bind(this));
  114. // sets default video type of local video
  115. // FIXME container type is totally different thing from the video type
  116. localVideoThumbnail.setVideoType(VIDEO_CONTAINER_TYPE);
  117. // if we do not resize the thumbs here, if there is no video device
  118. // the local video thumb maybe one pixel
  119. this.resizeThumbnails(true);
  120. this.registerListeners();
  121. },
  122. /**
  123. * Registering listeners for UI events in Video layout component.
  124. *
  125. * @returns {void}
  126. */
  127. registerListeners() {
  128. eventEmitter.addListener(UIEvents.LOCAL_FLIPX_CHANGED,
  129. onLocalFlipXChanged);
  130. },
  131. /**
  132. * Cleans up state of this singleton {@code VideoLayout}.
  133. *
  134. * @returns {void}
  135. */
  136. reset() {
  137. this._resetLargeVideo();
  138. this._resetFilmstrip();
  139. },
  140. initLargeVideo() {
  141. this._resetLargeVideo();
  142. largeVideo = new LargeVideoManager(eventEmitter);
  143. if (localFlipX) {
  144. largeVideo.onLocalFlipXChange(localFlipX);
  145. }
  146. largeVideo.updateContainerSize();
  147. },
  148. /**
  149. * Sets the audio level of the video elements associated to the given id.
  150. *
  151. * @param id the video identifier in the form it comes from the library
  152. * @param lvl the new audio level to update to
  153. */
  154. setAudioLevel(id, lvl) {
  155. const smallVideo = this.getSmallVideo(id);
  156. if (smallVideo) {
  157. smallVideo.updateAudioLevelIndicator(lvl);
  158. }
  159. if (largeVideo && id === largeVideo.id) {
  160. largeVideo.updateLargeVideoAudioLevel(lvl);
  161. }
  162. },
  163. changeLocalVideo(stream) {
  164. const localId = getLocalParticipant().id;
  165. this.onVideoTypeChanged(localId, stream.videoType);
  166. localVideoThumbnail.changeVideo(stream);
  167. this._updateLargeVideoIfDisplayed(localId);
  168. },
  169. /**
  170. * Get's the localID of the conference and set it to the local video
  171. * (small one). This needs to be called as early as possible, when muc is
  172. * actually joined. Otherwise events can come with information like email
  173. * and setting them assume the id is already set.
  174. */
  175. mucJoined() {
  176. if (largeVideo && !largeVideo.id) {
  177. this.updateLargeVideo(getLocalParticipant().id, true);
  178. }
  179. // FIXME: replace this call with a generic update call once SmallVideo
  180. // only contains a ReactElement. Then remove this call once the
  181. // Filmstrip is fully in React.
  182. localVideoThumbnail.updateIndicators();
  183. },
  184. /**
  185. * Adds or removes icons for not available camera and microphone.
  186. * @param resourceJid the jid of user
  187. * @param devices available devices
  188. */
  189. setDeviceAvailabilityIcons(id, devices) {
  190. if (APP.conference.isLocalId(id)) {
  191. localVideoThumbnail.setDeviceAvailabilityIcons(devices);
  192. return;
  193. }
  194. const video = remoteVideos[id];
  195. if (!video) {
  196. return;
  197. }
  198. video.setDeviceAvailabilityIcons(devices);
  199. },
  200. /**
  201. * Shows/hides local video.
  202. * @param {boolean} true to make the local video visible, false - otherwise
  203. */
  204. setLocalVideoVisible(visible) {
  205. localVideoThumbnail.setVisible(visible);
  206. },
  207. /**
  208. * Checks if removed video is currently displayed and tries to display
  209. * another one instead.
  210. * Uses focusedID if any or dominantSpeakerID if any,
  211. * otherwise elects new video, in this order.
  212. */
  213. _updateAfterThumbRemoved(id) {
  214. // Always trigger an update if large video is empty.
  215. if (!largeVideo
  216. || (this.getLargeVideoID() && !this.isCurrentlyOnLarge(id))) {
  217. return;
  218. }
  219. const pinnedId = this.getPinnedId();
  220. let newId;
  221. if (pinnedId) {
  222. newId = pinnedId;
  223. } else if (getCurrentRemoteDominantSpeakerID()) {
  224. newId = getCurrentRemoteDominantSpeakerID();
  225. } else { // Otherwise select last visible video
  226. newId = this.electLastVisibleVideo();
  227. }
  228. this.updateLargeVideo(newId);
  229. },
  230. electLastVisibleVideo() {
  231. // pick the last visible video in the row
  232. // if nobody else is left, this picks the local video
  233. const remoteThumbs = Filmstrip.getThumbs(true).remoteThumbs;
  234. let thumbs = remoteThumbs.filter('[id!="mixedstream"]');
  235. const lastVisible = thumbs.filter(':visible:last');
  236. if (lastVisible.length) {
  237. const id = getPeerContainerResourceId(lastVisible[0]);
  238. if (remoteVideos[id]) {
  239. logger.info(`electLastVisibleVideo: ${id}`);
  240. return id;
  241. }
  242. // The RemoteVideo was removed (but the DOM elements may still
  243. // exist).
  244. }
  245. logger.info('Last visible video no longer exists');
  246. thumbs = Filmstrip.getThumbs().remoteThumbs;
  247. if (thumbs.length) {
  248. const id = getPeerContainerResourceId(thumbs[0]);
  249. if (remoteVideos[id]) {
  250. logger.info(`electLastVisibleVideo: ${id}`);
  251. return id;
  252. }
  253. // The RemoteVideo was removed (but the DOM elements may
  254. // still exist).
  255. }
  256. // Go with local video
  257. logger.info('Fallback to local video...');
  258. const { id } = getLocalParticipant();
  259. logger.info(`electLastVisibleVideo: ${id}`);
  260. return id;
  261. },
  262. onRemoteStreamAdded(stream) {
  263. const id = stream.getParticipantId();
  264. const remoteVideo = remoteVideos[id];
  265. if (!remoteVideo) {
  266. return;
  267. }
  268. remoteVideo.addRemoteStreamElement(stream);
  269. // Make sure track's muted state is reflected
  270. if (stream.getType() === 'audio') {
  271. this.onAudioMute(stream.getParticipantId(), stream.isMuted());
  272. } else {
  273. this.onVideoMute(stream.getParticipantId(), stream.isMuted());
  274. }
  275. },
  276. onRemoteStreamRemoved(stream) {
  277. const id = stream.getParticipantId();
  278. const remoteVideo = remoteVideos[id];
  279. // Remote stream may be removed after participant left the conference.
  280. if (remoteVideo) {
  281. remoteVideo.removeRemoteStreamElement(stream);
  282. }
  283. if (stream.isVideoTrack()) {
  284. this._updateLargeVideoIfDisplayed(id);
  285. }
  286. this.updateMutedForNoTracks(id, stream.getType());
  287. },
  288. /**
  289. * FIXME get rid of this method once muted indicator are reactified (by
  290. * making sure that user with no tracks is displayed as muted )
  291. *
  292. * If participant has no tracks will make the UI display muted status.
  293. * @param {string} participantId
  294. * @param {string} mediaType 'audio' or 'video'
  295. */
  296. updateMutedForNoTracks(participantId, mediaType) {
  297. const participant = APP.conference.getParticipantById(participantId);
  298. if (participant
  299. && !participant.getTracksByMediaType(mediaType).length) {
  300. if (mediaType === 'audio') {
  301. APP.UI.setAudioMuted(participantId, true);
  302. } else if (mediaType === 'video') {
  303. APP.UI.setVideoMuted(participantId, true);
  304. } else {
  305. logger.error(`Unsupported media type: ${mediaType}`);
  306. }
  307. }
  308. },
  309. /**
  310. * Return the type of the remote video.
  311. * @param id the id for the remote video
  312. * @returns {String} the video type video or screen.
  313. */
  314. getRemoteVideoType(id) {
  315. const smallVideo = VideoLayout.getSmallVideo(id);
  316. return smallVideo ? smallVideo.getVideoType() : null;
  317. },
  318. isPinned(id) {
  319. return id === this.getPinnedId();
  320. },
  321. getPinnedId() {
  322. const { id } = getPinnedParticipant(APP.store.getState()) || {};
  323. return id || null;
  324. },
  325. /**
  326. * Triggers a thumbnail to pin or unpin itself.
  327. *
  328. * @param {number} videoNumber - The index of the video to toggle pin on.
  329. * @private
  330. */
  331. togglePin(videoNumber) {
  332. const videos = getAllThumbnails();
  333. const videoView = videos[videoNumber];
  334. videoView && videoView.togglePin();
  335. },
  336. /**
  337. * Callback invoked to update display when the pin participant has changed.
  338. *
  339. * @paramn {string|null} pinnedParticipantID - The participant ID of the
  340. * participant that is pinned or null if no one is pinned.
  341. * @returns {void}
  342. */
  343. onPinChange(pinnedParticipantID) {
  344. if (interfaceConfig.filmStripOnly) {
  345. return;
  346. }
  347. getAllThumbnails().forEach(thumbnail =>
  348. thumbnail.focus(pinnedParticipantID === thumbnail.getId()));
  349. if (pinnedParticipantID) {
  350. this.updateLargeVideo(pinnedParticipantID);
  351. } else {
  352. const currentDominantSpeakerID
  353. = getCurrentRemoteDominantSpeakerID();
  354. if (currentDominantSpeakerID) {
  355. this.updateLargeVideo(currentDominantSpeakerID);
  356. } else {
  357. // if there is no currentDominantSpeakerID, it can also be
  358. // that local participant is the dominant speaker
  359. // we should act as a participant has left and was on large
  360. // and we should choose somebody (electLastVisibleVideo)
  361. this.updateLargeVideo(this.electLastVisibleVideo());
  362. }
  363. }
  364. },
  365. /**
  366. * Creates a participant container for the given id.
  367. *
  368. * @param {Object} participant - The redux representation of a remote
  369. * participant.
  370. * @returns {void}
  371. */
  372. addRemoteParticipantContainer(participant) {
  373. if (!participant || participant.local) {
  374. return;
  375. } else if (participant.isFakeParticipant) {
  376. const sharedVideoThumb = new SharedVideoThumb(
  377. participant,
  378. SHARED_VIDEO_CONTAINER_TYPE,
  379. VideoLayout);
  380. this.addRemoteVideoContainer(participant.id, sharedVideoThumb);
  381. return;
  382. }
  383. const id = participant.id;
  384. const jitsiParticipant = APP.conference.getParticipantById(id);
  385. const remoteVideo
  386. = new RemoteVideo(jitsiParticipant, VideoLayout, eventEmitter);
  387. this._setRemoteControlProperties(jitsiParticipant, remoteVideo);
  388. this.addRemoteVideoContainer(id, remoteVideo);
  389. this.updateMutedForNoTracks(id, 'audio');
  390. this.updateMutedForNoTracks(id, 'video');
  391. const remoteVideosCount = Object.keys(remoteVideos).length;
  392. if (remoteVideosCount === 1) {
  393. window.setTimeout(() => {
  394. const updatedRemoteVideosCount
  395. = Object.keys(remoteVideos).length;
  396. if (updatedRemoteVideosCount === 1 && remoteVideos[id]) {
  397. this._maybePlaceParticipantOnLargeVideo(id);
  398. }
  399. }, 3000);
  400. }
  401. },
  402. /**
  403. * Adds remote video container for the given id and <tt>SmallVideo</tt>.
  404. *
  405. * @param {string} the id of the video to add
  406. * @param {SmallVideo} smallVideo the small video instance to add as a
  407. * remote video
  408. */
  409. addRemoteVideoContainer(id, remoteVideo) {
  410. remoteVideos[id] = remoteVideo;
  411. if (!remoteVideo.getVideoType()) {
  412. // make video type the default one (camera)
  413. // FIXME container type is not a video type
  414. remoteVideo.setVideoType(VIDEO_CONTAINER_TYPE);
  415. }
  416. VideoLayout.resizeThumbnails(true);
  417. // Initialize the view
  418. remoteVideo.updateView();
  419. },
  420. // FIXME: what does this do???
  421. remoteVideoActive(videoElement, resourceJid) {
  422. logger.info(`${resourceJid} video is now active`, videoElement);
  423. VideoLayout.resizeThumbnails(
  424. false, () => {
  425. if (videoElement) {
  426. $(videoElement).show();
  427. }
  428. });
  429. this._maybePlaceParticipantOnLargeVideo(resourceJid);
  430. },
  431. /**
  432. * Update the large video to the last added video only if there's no current
  433. * dominant, focused speaker or update it to the current dominant speaker.
  434. *
  435. * @params {string} resourceJid - The id of the user to maybe display on
  436. * large video.
  437. * @returns {void}
  438. */
  439. _maybePlaceParticipantOnLargeVideo(resourceJid) {
  440. const pinnedId = this.getPinnedId();
  441. if ((!pinnedId
  442. && !getCurrentRemoteDominantSpeakerID()
  443. && this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE))
  444. || pinnedId === resourceJid
  445. || (!pinnedId && resourceJid
  446. && getCurrentRemoteDominantSpeakerID() === resourceJid)
  447. /* Playback started while we're on the stage - may need to update
  448. video source with the new stream */
  449. || this.isCurrentlyOnLarge(resourceJid)) {
  450. this.updateLargeVideo(resourceJid, true);
  451. }
  452. },
  453. /**
  454. * Shows a visual indicator for the moderator of the conference.
  455. * On local or remote participants.
  456. */
  457. showModeratorIndicator() {
  458. const isModerator = APP.conference.isModerator;
  459. if (isModerator) {
  460. localVideoThumbnail.addModeratorIndicator();
  461. } else {
  462. localVideoThumbnail.removeModeratorIndicator();
  463. }
  464. APP.conference.listMembers().forEach(member => {
  465. const id = member.getId();
  466. const remoteVideo = remoteVideos[id];
  467. if (!remoteVideo) {
  468. return;
  469. }
  470. if (member.isModerator()) {
  471. remoteVideo.addModeratorIndicator();
  472. }
  473. remoteVideo.updateRemoteVideoMenu();
  474. });
  475. },
  476. /*
  477. * Shows or hides the audio muted indicator over the local thumbnail video.
  478. * @param {boolean} isMuted
  479. */
  480. showLocalAudioIndicator(isMuted) {
  481. localVideoThumbnail.showAudioIndicator(isMuted);
  482. },
  483. /**
  484. * Resizes thumbnails.
  485. */
  486. resizeThumbnails(
  487. forceUpdate = false,
  488. onComplete = null) {
  489. const { localVideo, remoteVideo }
  490. = Filmstrip.calculateThumbnailSize();
  491. Filmstrip.resizeThumbnails(localVideo, remoteVideo, forceUpdate);
  492. if (shouldDisplayTileView(APP.store.getState())) {
  493. const height
  494. = (localVideo && localVideo.thumbHeight)
  495. || (remoteVideo && remoteVideo.thumbnHeight)
  496. || 0;
  497. const qualityLevel = getNearestReceiverVideoQualityLevel(height);
  498. APP.store.dispatch(setMaxReceiverVideoQuality(qualityLevel));
  499. }
  500. if (onComplete && typeof onComplete === 'function') {
  501. onComplete();
  502. }
  503. },
  504. /**
  505. * On audio muted event.
  506. */
  507. onAudioMute(id, isMuted) {
  508. if (APP.conference.isLocalId(id)) {
  509. localVideoThumbnail.showAudioIndicator(isMuted);
  510. } else {
  511. const remoteVideo = remoteVideos[id];
  512. if (!remoteVideo) {
  513. return;
  514. }
  515. remoteVideo.showAudioIndicator(isMuted);
  516. remoteVideo.updateRemoteVideoMenu(isMuted);
  517. }
  518. },
  519. /**
  520. * On video muted event.
  521. */
  522. onVideoMute(id, value) {
  523. if (APP.conference.isLocalId(id)) {
  524. localVideoThumbnail.setVideoMutedView(value);
  525. } else {
  526. const remoteVideo = remoteVideos[id];
  527. if (remoteVideo) {
  528. remoteVideo.setVideoMutedView(value);
  529. }
  530. }
  531. if (this.isCurrentlyOnLarge(id)) {
  532. // large video will show avatar instead of muted stream
  533. this.updateLargeVideo(id, true);
  534. }
  535. },
  536. /**
  537. * Display name changed.
  538. */
  539. onDisplayNameChanged(id, displayName, status) {
  540. if (id === 'localVideoContainer'
  541. || APP.conference.isLocalId(id)) {
  542. localVideoThumbnail.setDisplayName(displayName);
  543. } else {
  544. const remoteVideo = remoteVideos[id];
  545. if (remoteVideo) {
  546. remoteVideo.setDisplayName(displayName, status);
  547. }
  548. }
  549. },
  550. /**
  551. * Sets the "raised hand" status for a participant identified by 'id'.
  552. */
  553. setRaisedHandStatus(id, raisedHandStatus) {
  554. const video
  555. = APP.conference.isLocalId(id)
  556. ? localVideoThumbnail : remoteVideos[id];
  557. if (video) {
  558. video.showRaisedHandIndicator(raisedHandStatus);
  559. if (raisedHandStatus) {
  560. video.showDominantSpeakerIndicator(false);
  561. }
  562. }
  563. },
  564. /**
  565. * On dominant speaker changed event.
  566. *
  567. * @param {string} id - The participant ID of the new dominant speaker.
  568. * @returns {void}
  569. */
  570. onDominantSpeakerChanged(id) {
  571. getAllThumbnails().forEach(thumbnail =>
  572. thumbnail.showDominantSpeakerIndicator(id === thumbnail.getId()));
  573. if (!remoteVideos[id]) {
  574. return;
  575. }
  576. // Local video will not have container found, but that's ok
  577. // since we don't want to switch to local video.
  578. if (!interfaceConfig.filmStripOnly && !this.getPinnedId()
  579. && !this.getCurrentlyOnLargeContainer().stayOnStage()) {
  580. this.updateLargeVideo(id);
  581. }
  582. },
  583. /**
  584. * Shows/hides warning about a user's connectivity issues.
  585. *
  586. * @param {string} id - The ID of the remote participant(MUC nickname).
  587. * @param {status} status - The new connection status.
  588. * @returns {void}
  589. */
  590. onParticipantConnectionStatusChanged(id, status) {
  591. if (APP.conference.isLocalId(id)) {
  592. // Maintain old logic of passing in either interrupted or active
  593. // to updateConnectionStatus.
  594. localVideoThumbnail.updateConnectionStatus(status);
  595. if (status === JitsiParticipantConnectionStatus.INTERRUPTED) {
  596. largeVideo && largeVideo.onVideoInterrupted();
  597. } else {
  598. largeVideo && largeVideo.onVideoRestored();
  599. }
  600. return;
  601. }
  602. // We have to trigger full large video update to transition from
  603. // avatar to video on connectivity restored.
  604. this._updateLargeVideoIfDisplayed(id, true);
  605. const remoteVideo = remoteVideos[id];
  606. if (remoteVideo) {
  607. // Updating only connection status indicator is not enough, because
  608. // when we the connection is restored while the avatar was displayed
  609. // (due to 'muted while disconnected' condition) we may want to show
  610. // the video stream again and in order to do that the display mode
  611. // must be updated.
  612. // remoteVideo.updateConnectionStatusIndicator(isActive);
  613. remoteVideo.updateView();
  614. }
  615. },
  616. /**
  617. * On last N change event.
  618. *
  619. * @param endpointsLeavingLastN the list currently leaving last N
  620. * endpoints
  621. * @param endpointsEnteringLastN the list currently entering last N
  622. * endpoints
  623. */
  624. onLastNEndpointsChanged(endpointsLeavingLastN, endpointsEnteringLastN) {
  625. if (endpointsLeavingLastN) {
  626. endpointsLeavingLastN.forEach(this._updateRemoteVideo, this);
  627. }
  628. if (endpointsEnteringLastN) {
  629. endpointsEnteringLastN.forEach(this._updateRemoteVideo, this);
  630. }
  631. },
  632. /**
  633. * Updates remote video by id if it exists.
  634. * @param {string} id of the remote video
  635. * @private
  636. */
  637. _updateRemoteVideo(id) {
  638. const remoteVideo = remoteVideos[id];
  639. if (remoteVideo) {
  640. remoteVideo.updateView();
  641. if (remoteVideo.isCurrentlyOnLargeVideo()) {
  642. this.updateLargeVideo(id);
  643. }
  644. }
  645. },
  646. /**
  647. * Hides the connection indicator
  648. * @param id
  649. */
  650. hideConnectionIndicator(id) {
  651. const remoteVideo = remoteVideos[id];
  652. if (remoteVideo) {
  653. remoteVideo.removeConnectionIndicator();
  654. }
  655. },
  656. /**
  657. * Hides all the indicators
  658. */
  659. hideStats() {
  660. for (const video in remoteVideos) { // eslint-disable-line guard-for-in
  661. const remoteVideo = remoteVideos[video];
  662. if (remoteVideo) {
  663. remoteVideo.removeConnectionIndicator();
  664. }
  665. }
  666. localVideoThumbnail.removeConnectionIndicator();
  667. },
  668. removeParticipantContainer(id) {
  669. // Unlock large video
  670. if (this.getPinnedId() === id) {
  671. logger.info('Focused video owner has left the conference');
  672. APP.store.dispatch(pinParticipant(null));
  673. }
  674. const remoteVideo = remoteVideos[id];
  675. if (remoteVideo) {
  676. // Remove remote video
  677. logger.info(`Removing remote video: ${id}`);
  678. delete remoteVideos[id];
  679. remoteVideo.remove();
  680. } else {
  681. logger.warn(`No remote video for ${id}`);
  682. }
  683. VideoLayout.resizeThumbnails();
  684. VideoLayout._updateAfterThumbRemoved(id);
  685. },
  686. onVideoTypeChanged(id, newVideoType) {
  687. if (VideoLayout.getRemoteVideoType(id) === newVideoType) {
  688. return;
  689. }
  690. logger.info('Peer video type changed: ', id, newVideoType);
  691. let smallVideo;
  692. if (APP.conference.isLocalId(id)) {
  693. if (!localVideoThumbnail) {
  694. logger.warn('Local video not ready yet');
  695. return;
  696. }
  697. smallVideo = localVideoThumbnail;
  698. } else if (remoteVideos[id]) {
  699. smallVideo = remoteVideos[id];
  700. } else {
  701. return;
  702. }
  703. smallVideo.setVideoType(newVideoType);
  704. if (this.isCurrentlyOnLarge(id)) {
  705. this.updateLargeVideo(id, true);
  706. }
  707. },
  708. /**
  709. * Resizes the video area.
  710. *
  711. * TODO: Remove the "animate" param as it is no longer passed in as true.
  712. *
  713. * @param forceUpdate indicates that hidden thumbnails will be shown
  714. */
  715. resizeVideoArea(
  716. forceUpdate = false,
  717. animate = false) {
  718. // Resize the thumbnails first.
  719. this.resizeThumbnails(forceUpdate);
  720. if (largeVideo) {
  721. largeVideo.updateContainerSize();
  722. largeVideo.resize(animate);
  723. }
  724. // Calculate available width and height.
  725. const availableHeight = window.innerHeight;
  726. const availableWidth = UIUtil.getAvailableVideoWidth();
  727. if (availableWidth < 0 || availableHeight < 0) {
  728. return;
  729. }
  730. },
  731. getSmallVideo(id) {
  732. if (APP.conference.isLocalId(id)) {
  733. return localVideoThumbnail;
  734. }
  735. return remoteVideos[id];
  736. },
  737. changeUserAvatar(id, avatarUrl) {
  738. const smallVideo = VideoLayout.getSmallVideo(id);
  739. if (smallVideo) {
  740. smallVideo.avatarChanged(avatarUrl);
  741. } else {
  742. logger.warn(
  743. `Missed avatar update - no small video yet for ${id}`
  744. );
  745. }
  746. if (this.isCurrentlyOnLarge(id)) {
  747. largeVideo.updateAvatar(avatarUrl);
  748. }
  749. },
  750. isLargeVideoVisible() {
  751. return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
  752. },
  753. /**
  754. * @return {LargeContainer} the currently displayed container on large
  755. * video.
  756. */
  757. getCurrentlyOnLargeContainer() {
  758. return largeVideo.getCurrentContainer();
  759. },
  760. isCurrentlyOnLarge(id) {
  761. return largeVideo && largeVideo.id === id;
  762. },
  763. /**
  764. * Triggers an update of remote video and large video displays so they may
  765. * pick up any state changes that have occurred elsewhere.
  766. *
  767. * @returns {void}
  768. */
  769. updateAllVideos() {
  770. const displayedUserId = this.getLargeVideoID();
  771. if (displayedUserId) {
  772. this.updateLargeVideo(displayedUserId, true);
  773. }
  774. Object.keys(remoteVideos).forEach(video => {
  775. remoteVideos[video].updateView();
  776. });
  777. },
  778. updateLargeVideo(id, forceUpdate) {
  779. if (!largeVideo) {
  780. return;
  781. }
  782. const currentContainer = largeVideo.getCurrentContainer();
  783. const currentContainerType = largeVideo.getCurrentContainerType();
  784. const currentId = largeVideo.id;
  785. const isOnLarge = this.isCurrentlyOnLarge(id);
  786. const smallVideo = this.getSmallVideo(id);
  787. if (isOnLarge && !forceUpdate
  788. && LargeVideoManager.isVideoContainer(currentContainerType)
  789. && smallVideo) {
  790. const currentStreamId = currentContainer.getStreamID();
  791. const newStreamId
  792. = smallVideo.videoStream
  793. ? smallVideo.videoStream.getId() : null;
  794. // FIXME it might be possible to get rid of 'forceUpdate' argument
  795. if (currentStreamId !== newStreamId) {
  796. logger.debug('Enforcing large video update for stream change');
  797. forceUpdate = true; // eslint-disable-line no-param-reassign
  798. }
  799. }
  800. if ((!isOnLarge || forceUpdate) && smallVideo) {
  801. const videoType = this.getRemoteVideoType(id);
  802. // FIXME video type is not the same thing as container type
  803. if (id !== currentId && videoType === VIDEO_CONTAINER_TYPE) {
  804. APP.API.notifyOnStageParticipantChanged(id);
  805. }
  806. let oldSmallVideo;
  807. if (currentId) {
  808. oldSmallVideo = this.getSmallVideo(currentId);
  809. }
  810. smallVideo.waitForResolutionChange();
  811. if (oldSmallVideo) {
  812. oldSmallVideo.waitForResolutionChange();
  813. }
  814. largeVideo.updateLargeVideo(
  815. id,
  816. smallVideo.videoStream,
  817. videoType || VIDEO_TYPE.CAMERA
  818. ).then(() => {
  819. // update current small video and the old one
  820. smallVideo.updateView();
  821. oldSmallVideo && oldSmallVideo.updateView();
  822. }, () => {
  823. // use clicked other video during update, nothing to do.
  824. });
  825. } else if (currentId) {
  826. const currentSmallVideo = this.getSmallVideo(currentId);
  827. currentSmallVideo.updateView();
  828. }
  829. },
  830. addLargeVideoContainer(type, container) {
  831. largeVideo && largeVideo.addContainer(type, container);
  832. },
  833. removeLargeVideoContainer(type) {
  834. largeVideo && largeVideo.removeContainer(type);
  835. },
  836. /**
  837. * @returns Promise
  838. */
  839. showLargeVideoContainer(type, show) {
  840. if (!largeVideo) {
  841. return Promise.reject();
  842. }
  843. const isVisible = this.isLargeContainerTypeVisible(type);
  844. if (isVisible === show) {
  845. return Promise.resolve();
  846. }
  847. const currentId = largeVideo.id;
  848. let oldSmallVideo;
  849. if (currentId) {
  850. oldSmallVideo = this.getSmallVideo(currentId);
  851. }
  852. let containerTypeToShow = type;
  853. // if we are hiding a container and there is focusedVideo
  854. // (pinned remote video) use its video type,
  855. // if not then use default type - large video
  856. if (!show) {
  857. const pinnedId = this.getPinnedId();
  858. if (pinnedId) {
  859. containerTypeToShow = this.getRemoteVideoType(pinnedId);
  860. } else {
  861. containerTypeToShow = VIDEO_CONTAINER_TYPE;
  862. }
  863. }
  864. return largeVideo.showContainer(containerTypeToShow)
  865. .then(() => {
  866. if (oldSmallVideo) {
  867. oldSmallVideo && oldSmallVideo.updateView();
  868. }
  869. });
  870. },
  871. isLargeContainerTypeVisible(type) {
  872. return largeVideo && largeVideo.state === type;
  873. },
  874. /**
  875. * Returns the id of the current video shown on large.
  876. * Currently used by tests (torture).
  877. */
  878. getLargeVideoID() {
  879. return largeVideo && largeVideo.id;
  880. },
  881. /**
  882. * Returns the the current video shown on large.
  883. * Currently used by tests (torture).
  884. */
  885. getLargeVideo() {
  886. return largeVideo;
  887. },
  888. /**
  889. * Sets the flipX state of the local video.
  890. * @param {boolean} true for flipped otherwise false;
  891. */
  892. setLocalFlipX(val) {
  893. this.localFlipX = val;
  894. },
  895. getEventEmitter() {
  896. return eventEmitter;
  897. },
  898. /**
  899. * Handles user's features changes.
  900. */
  901. onUserFeaturesChanged(user) {
  902. const video = this.getSmallVideo(user.getId());
  903. if (!video) {
  904. return;
  905. }
  906. this._setRemoteControlProperties(user, video);
  907. },
  908. /**
  909. * Sets the remote control properties (checks whether remote control
  910. * is supported and executes remoteVideo.setRemoteControlSupport).
  911. * @param {JitsiParticipant} user the user that will be checked for remote
  912. * control support.
  913. * @param {RemoteVideo} remoteVideo the remoteVideo on which the properties
  914. * will be set.
  915. */
  916. _setRemoteControlProperties(user, remoteVideo) {
  917. APP.remoteControl.checkUserRemoteControlSupport(user).then(result =>
  918. remoteVideo.setRemoteControlSupport(result));
  919. },
  920. /**
  921. * Returns the wrapper jquery selector for the largeVideo
  922. * @returns {JQuerySelector} the wrapper jquery selector for the largeVideo
  923. */
  924. getLargeVideoWrapper() {
  925. return this.getCurrentlyOnLargeContainer().$wrapper;
  926. },
  927. /**
  928. * Returns the number of remove video ids.
  929. *
  930. * @returns {number} The number of remote videos.
  931. */
  932. getRemoteVideosCount() {
  933. return Object.keys(remoteVideos).length;
  934. },
  935. /**
  936. * Sets the remote control active status for a remote participant.
  937. *
  938. * @param {string} participantID - The id of the remote participant.
  939. * @param {boolean} isActive - The new remote control active status.
  940. * @returns {void}
  941. */
  942. setRemoteControlActiveStatus(participantID, isActive) {
  943. remoteVideos[participantID].setRemoteControlActiveStatus(isActive);
  944. },
  945. /**
  946. * Sets the remote control active status for the local participant.
  947. *
  948. * @returns {void}
  949. */
  950. setLocalRemoteControlActiveChanged() {
  951. Object.values(remoteVideos).forEach(
  952. remoteVideo => remoteVideo.updateRemoteVideoMenu()
  953. );
  954. },
  955. /**
  956. * Helper method to invoke when the video layout has changed and elements
  957. * have to be re-arranged and resized.
  958. *
  959. * @returns {void}
  960. */
  961. refreshLayout() {
  962. localVideoThumbnail && localVideoThumbnail.updateDOMLocation();
  963. VideoLayout.resizeVideoArea();
  964. localVideoThumbnail && localVideoThumbnail.rerender();
  965. Object.values(remoteVideos).forEach(
  966. remoteVideo => remoteVideo.rerender()
  967. );
  968. },
  969. /**
  970. * Cleans up any existing largeVideo instance.
  971. *
  972. * @private
  973. * @returns {void}
  974. */
  975. _resetLargeVideo() {
  976. if (largeVideo) {
  977. largeVideo.destroy();
  978. }
  979. largeVideo = null;
  980. },
  981. /**
  982. * Cleans up filmstrip state. While a separate {@code Filmstrip} exists, its
  983. * implementation is mainly for querying and manipulating the DOM while
  984. * state mostly remains in {@code VideoLayout}.
  985. *
  986. * @private
  987. * @returns {void}
  988. */
  989. _resetFilmstrip() {
  990. Object.keys(remoteVideos).forEach(remoteVideoId => {
  991. this.removeParticipantContainer(remoteVideoId);
  992. delete remoteVideos[remoteVideoId];
  993. });
  994. if (localVideoThumbnail) {
  995. localVideoThumbnail.remove();
  996. localVideoThumbnail = null;
  997. }
  998. },
  999. /**
  1000. * Triggers an update of large video if the passed in participant is
  1001. * currently displayed on large video.
  1002. *
  1003. * @param {string} participantId - The participant ID that should trigger an
  1004. * update of large video if displayed.
  1005. * @param {boolean} force - Whether or not the large video update should
  1006. * happen no matter what.
  1007. * @returns {void}
  1008. */
  1009. _updateLargeVideoIfDisplayed(participantId, force = false) {
  1010. if (this.isCurrentlyOnLarge(participantId)) {
  1011. this.updateLargeVideo(participantId, force);
  1012. }
  1013. }
  1014. };
  1015. export default VideoLayout;