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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. /* global APP, $, interfaceConfig */
  2. const logger = require('jitsi-meet-logger').getLogger(__filename);
  3. import { MEDIA_TYPE, VIDEO_TYPE } from '../../../react/features/base/media';
  4. import {
  5. getLocalParticipant as getLocalParticipantFromStore,
  6. getPinnedParticipant,
  7. getParticipantById,
  8. pinParticipant
  9. } from '../../../react/features/base/participants';
  10. import { getTrackByMediaTypeAndParticipant } from '../../../react/features/base/tracks';
  11. import { SHARED_VIDEO_CONTAINER_TYPE } from '../shared_video/SharedVideo';
  12. import SharedVideoThumb from '../shared_video/SharedVideoThumb';
  13. import UIEvents from '../../../service/UI/UIEvents';
  14. import RemoteVideo from './RemoteVideo';
  15. import LargeVideoManager from './LargeVideoManager';
  16. import { VIDEO_CONTAINER_TYPE } from './VideoContainer';
  17. import LocalVideo from './LocalVideo';
  18. const remoteVideos = {};
  19. let localVideoThumbnail = null;
  20. let eventEmitter = null;
  21. let largeVideo;
  22. /**
  23. * flipX state of the localVideo
  24. */
  25. let localFlipX = null;
  26. /**
  27. * Handler for local flip X changed event.
  28. * @param {Object} val
  29. */
  30. function onLocalFlipXChanged(val) {
  31. localFlipX = val;
  32. if (largeVideo) {
  33. largeVideo.onLocalFlipXChange(val);
  34. }
  35. }
  36. /**
  37. * Returns an array of all thumbnails in the filmstrip.
  38. *
  39. * @private
  40. * @returns {Array}
  41. */
  42. function getAllThumbnails() {
  43. return [
  44. localVideoThumbnail,
  45. ...Object.values(remoteVideos)
  46. ];
  47. }
  48. /**
  49. * Private helper to get the redux representation of the local participant.
  50. *
  51. * @private
  52. * @returns {Object}
  53. */
  54. function getLocalParticipant() {
  55. return getLocalParticipantFromStore(APP.store.getState());
  56. }
  57. const VideoLayout = {
  58. init(emitter) {
  59. eventEmitter = emitter;
  60. localVideoThumbnail = new LocalVideo(
  61. VideoLayout,
  62. emitter,
  63. this._updateLargeVideoIfDisplayed.bind(this));
  64. this.registerListeners();
  65. },
  66. /**
  67. * Registering listeners for UI events in Video layout component.
  68. *
  69. * @returns {void}
  70. */
  71. registerListeners() {
  72. eventEmitter.addListener(UIEvents.LOCAL_FLIPX_CHANGED,
  73. onLocalFlipXChanged);
  74. },
  75. /**
  76. * Cleans up state of this singleton {@code VideoLayout}.
  77. *
  78. * @returns {void}
  79. */
  80. reset() {
  81. this._resetLargeVideo();
  82. this._resetFilmstrip();
  83. },
  84. initLargeVideo() {
  85. this._resetLargeVideo();
  86. largeVideo = new LargeVideoManager(eventEmitter);
  87. if (localFlipX) {
  88. largeVideo.onLocalFlipXChange(localFlipX);
  89. }
  90. largeVideo.updateContainerSize();
  91. },
  92. /**
  93. * Sets the audio level of the video elements associated to the given id.
  94. *
  95. * @param id the video identifier in the form it comes from the library
  96. * @param lvl the new audio level to update to
  97. */
  98. setAudioLevel(id, lvl) {
  99. const smallVideo = this.getSmallVideo(id);
  100. if (smallVideo) {
  101. smallVideo.updateAudioLevelIndicator(lvl);
  102. }
  103. if (largeVideo && id === largeVideo.id) {
  104. largeVideo.updateLargeVideoAudioLevel(lvl);
  105. }
  106. },
  107. changeLocalVideo(stream) {
  108. const localId = getLocalParticipant().id;
  109. this.onVideoTypeChanged(localId, stream.videoType);
  110. localVideoThumbnail.changeVideo(stream);
  111. this._updateLargeVideoIfDisplayed(localId);
  112. },
  113. /**
  114. * Get's the localID of the conference and set it to the local video
  115. * (small one). This needs to be called as early as possible, when muc is
  116. * actually joined. Otherwise events can come with information like email
  117. * and setting them assume the id is already set.
  118. */
  119. mucJoined() {
  120. // FIXME: replace this call with a generic update call once SmallVideo
  121. // only contains a ReactElement. Then remove this call once the
  122. // Filmstrip is fully in React.
  123. localVideoThumbnail.updateIndicators();
  124. },
  125. /**
  126. * Shows/hides local video.
  127. * @param {boolean} true to make the local video visible, false - otherwise
  128. */
  129. setLocalVideoVisible(visible) {
  130. localVideoThumbnail.setVisible(visible);
  131. },
  132. onRemoteStreamAdded(stream) {
  133. const id = stream.getParticipantId();
  134. const remoteVideo = remoteVideos[id];
  135. logger.debug(`Received a new ${stream.getType()} stream for ${id}`);
  136. if (!remoteVideo) {
  137. logger.debug('No remote video element to add stream');
  138. return;
  139. }
  140. remoteVideo.addRemoteStreamElement(stream);
  141. // Make sure track's muted state is reflected
  142. if (stream.getType() === 'audio') {
  143. this.onAudioMute(id, stream.isMuted());
  144. } else {
  145. this.onVideoMute(id, stream.isMuted());
  146. }
  147. },
  148. onRemoteStreamRemoved(stream) {
  149. const id = stream.getParticipantId();
  150. const remoteVideo = remoteVideos[id];
  151. // Remote stream may be removed after participant left the conference.
  152. if (remoteVideo) {
  153. remoteVideo.removeRemoteStreamElement(stream);
  154. }
  155. this.updateMutedForNoTracks(id, stream.getType());
  156. },
  157. /**
  158. * FIXME get rid of this method once muted indicator are reactified (by
  159. * making sure that user with no tracks is displayed as muted )
  160. *
  161. * If participant has no tracks will make the UI display muted status.
  162. * @param {string} participantId
  163. * @param {string} mediaType 'audio' or 'video'
  164. */
  165. updateMutedForNoTracks(participantId, mediaType) {
  166. const participant = APP.conference.getParticipantById(participantId);
  167. if (participant && !participant.getTracksByMediaType(mediaType).length) {
  168. if (mediaType === 'audio') {
  169. APP.UI.setAudioMuted(participantId, true);
  170. } else if (mediaType === 'video') {
  171. APP.UI.setVideoMuted(participantId, true);
  172. } else {
  173. logger.error(`Unsupported media type: ${mediaType}`);
  174. }
  175. }
  176. },
  177. /**
  178. * Return the type of the remote video.
  179. * @param id the id for the remote video
  180. * @returns {String} the video type video or screen.
  181. */
  182. getRemoteVideoType(id) {
  183. const state = APP.store.getState();
  184. const participant = getParticipantById(state, id);
  185. if (participant?.isFakeParticipant) {
  186. return SHARED_VIDEO_CONTAINER_TYPE;
  187. }
  188. const videoTrack = getTrackByMediaTypeAndParticipant(state['features/base/tracks'], MEDIA_TYPE.VIDEO, id);
  189. return videoTrack?.videoType;
  190. },
  191. isPinned(id) {
  192. return id === this.getPinnedId();
  193. },
  194. getPinnedId() {
  195. const { id } = getPinnedParticipant(APP.store.getState()) || {};
  196. return id || null;
  197. },
  198. /**
  199. * Triggers a thumbnail to pin or unpin itself.
  200. *
  201. * @param {number} videoNumber - The index of the video to toggle pin on.
  202. * @private
  203. */
  204. togglePin(videoNumber) {
  205. const videos = getAllThumbnails();
  206. const videoView = videos[videoNumber];
  207. videoView && videoView.togglePin();
  208. },
  209. /**
  210. * Callback invoked to update display when the pin participant has changed.
  211. *
  212. * @paramn {string|null} pinnedParticipantID - The participant ID of the
  213. * participant that is pinned or null if no one is pinned.
  214. * @returns {void}
  215. */
  216. onPinChange(pinnedParticipantID) {
  217. if (interfaceConfig.filmStripOnly) {
  218. return;
  219. }
  220. getAllThumbnails().forEach(thumbnail =>
  221. thumbnail.focus(pinnedParticipantID === thumbnail.getId()));
  222. },
  223. /**
  224. * Creates a participant container for the given id.
  225. *
  226. * @param {Object} participant - The redux representation of a remote
  227. * participant.
  228. * @returns {void}
  229. */
  230. addRemoteParticipantContainer(participant) {
  231. if (!participant || participant.local) {
  232. return;
  233. } else if (participant.isFakeParticipant) {
  234. const sharedVideoThumb = new SharedVideoThumb(
  235. participant,
  236. SHARED_VIDEO_CONTAINER_TYPE,
  237. VideoLayout);
  238. this.addRemoteVideoContainer(participant.id, sharedVideoThumb);
  239. return;
  240. }
  241. const id = participant.id;
  242. const jitsiParticipant = APP.conference.getParticipantById(id);
  243. const remoteVideo = new RemoteVideo(jitsiParticipant, VideoLayout);
  244. this._setRemoteControlProperties(jitsiParticipant, remoteVideo);
  245. this.addRemoteVideoContainer(id, remoteVideo);
  246. this.updateMutedForNoTracks(id, 'audio');
  247. this.updateMutedForNoTracks(id, 'video');
  248. },
  249. /**
  250. * Adds remote video container for the given id and <tt>SmallVideo</tt>.
  251. *
  252. * @param {string} the id of the video to add
  253. * @param {SmallVideo} smallVideo the small video instance to add as a
  254. * remote video
  255. */
  256. addRemoteVideoContainer(id, remoteVideo) {
  257. remoteVideos[id] = remoteVideo;
  258. // Initialize the view
  259. remoteVideo.updateView();
  260. },
  261. // FIXME: what does this do???
  262. remoteVideoActive(videoElement, resourceJid) {
  263. logger.info(`${resourceJid} video is now active`, videoElement);
  264. if (videoElement) {
  265. $(videoElement).show();
  266. }
  267. this._updateLargeVideoIfDisplayed(resourceJid, true);
  268. },
  269. /**
  270. * On audio muted event.
  271. */
  272. onAudioMute(id, isMuted) {
  273. if (APP.conference.isLocalId(id)) {
  274. localVideoThumbnail.showAudioIndicator(isMuted);
  275. } else {
  276. const remoteVideo = remoteVideos[id];
  277. if (!remoteVideo) {
  278. return;
  279. }
  280. remoteVideo.showAudioIndicator(isMuted);
  281. remoteVideo.updateRemoteVideoMenu();
  282. }
  283. },
  284. /**
  285. * On video muted event.
  286. */
  287. onVideoMute(id, value) {
  288. if (APP.conference.isLocalId(id)) {
  289. localVideoThumbnail && localVideoThumbnail.setVideoMutedView(value);
  290. } else {
  291. const remoteVideo = remoteVideos[id];
  292. if (remoteVideo) {
  293. remoteVideo.setVideoMutedView(value);
  294. }
  295. }
  296. // large video will show avatar instead of muted stream
  297. this._updateLargeVideoIfDisplayed(id, true);
  298. },
  299. /**
  300. * Display name changed.
  301. */
  302. onDisplayNameChanged(id) {
  303. if (id === 'localVideoContainer'
  304. || APP.conference.isLocalId(id)) {
  305. localVideoThumbnail.updateDisplayName();
  306. } else {
  307. const remoteVideo = remoteVideos[id];
  308. if (remoteVideo) {
  309. remoteVideo.updateDisplayName();
  310. }
  311. }
  312. },
  313. /**
  314. * On dominant speaker changed event.
  315. *
  316. * @param {string} id - The participant ID of the new dominant speaker.
  317. * @returns {void}
  318. */
  319. onDominantSpeakerChanged(id) {
  320. getAllThumbnails().forEach(thumbnail =>
  321. thumbnail.showDominantSpeakerIndicator(id === thumbnail.getId()));
  322. },
  323. /**
  324. * Shows/hides warning about a user's connectivity issues.
  325. *
  326. * @param {string} id - The ID of the remote participant(MUC nickname).
  327. * @returns {void}
  328. */
  329. onParticipantConnectionStatusChanged(id) {
  330. if (APP.conference.isLocalId(id)) {
  331. return;
  332. }
  333. // We have to trigger full large video update to transition from
  334. // avatar to video on connectivity restored.
  335. this._updateLargeVideoIfDisplayed(id, true);
  336. const remoteVideo = remoteVideos[id];
  337. if (remoteVideo) {
  338. // Updating only connection status indicator is not enough, because
  339. // when we the connection is restored while the avatar was displayed
  340. // (due to 'muted while disconnected' condition) we may want to show
  341. // the video stream again and in order to do that the display mode
  342. // must be updated.
  343. // remoteVideo.updateConnectionStatusIndicator(isActive);
  344. remoteVideo.updateView();
  345. }
  346. },
  347. /**
  348. * On last N change event.
  349. *
  350. * @param endpointsLeavingLastN the list currently leaving last N
  351. * endpoints
  352. * @param endpointsEnteringLastN the list currently entering last N
  353. * endpoints
  354. */
  355. onLastNEndpointsChanged(endpointsLeavingLastN, endpointsEnteringLastN) {
  356. if (endpointsLeavingLastN) {
  357. endpointsLeavingLastN.forEach(this._updateRemoteVideo, this);
  358. }
  359. if (endpointsEnteringLastN) {
  360. endpointsEnteringLastN.forEach(this._updateRemoteVideo, this);
  361. }
  362. },
  363. /**
  364. * Updates remote video by id if it exists.
  365. * @param {string} id of the remote video
  366. * @private
  367. */
  368. _updateRemoteVideo(id) {
  369. const remoteVideo = remoteVideos[id];
  370. if (remoteVideo) {
  371. remoteVideo.updateView();
  372. this._updateLargeVideoIfDisplayed(id);
  373. }
  374. },
  375. /**
  376. * Hides all the indicators
  377. */
  378. hideStats() {
  379. for (const video in remoteVideos) { // eslint-disable-line guard-for-in
  380. const remoteVideo = remoteVideos[video];
  381. if (remoteVideo) {
  382. remoteVideo.removeConnectionIndicator();
  383. }
  384. }
  385. localVideoThumbnail.removeConnectionIndicator();
  386. },
  387. removeParticipantContainer(id) {
  388. // Unlock large video
  389. if (this.getPinnedId() === id) {
  390. logger.info('Focused video owner has left the conference');
  391. APP.store.dispatch(pinParticipant(null));
  392. }
  393. const remoteVideo = remoteVideos[id];
  394. if (remoteVideo) {
  395. // Remove remote video
  396. logger.info(`Removing remote video: ${id}`);
  397. delete remoteVideos[id];
  398. remoteVideo.remove();
  399. } else {
  400. logger.warn(`No remote video for ${id}`);
  401. }
  402. },
  403. onVideoTypeChanged(id, newVideoType) {
  404. if (VideoLayout.getRemoteVideoType(id) === newVideoType) {
  405. return;
  406. }
  407. logger.info('Peer video type changed: ', id, newVideoType);
  408. this._updateLargeVideoIfDisplayed(id, true);
  409. },
  410. /**
  411. * Resizes the video area.
  412. */
  413. resizeVideoArea() {
  414. if (largeVideo) {
  415. largeVideo.updateContainerSize();
  416. largeVideo.resize(false);
  417. }
  418. },
  419. getSmallVideo(id) {
  420. if (APP.conference.isLocalId(id)) {
  421. return localVideoThumbnail;
  422. }
  423. return remoteVideos[id];
  424. },
  425. changeUserAvatar(id, avatarUrl) {
  426. const smallVideo = VideoLayout.getSmallVideo(id);
  427. if (smallVideo) {
  428. smallVideo.initializeAvatar();
  429. } else {
  430. logger.warn(
  431. `Missed avatar update - no small video yet for ${id}`
  432. );
  433. }
  434. if (this.isCurrentlyOnLarge(id)) {
  435. largeVideo.updateAvatar(avatarUrl);
  436. }
  437. },
  438. isLargeVideoVisible() {
  439. return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
  440. },
  441. /**
  442. * @return {LargeContainer} the currently displayed container on large
  443. * video.
  444. */
  445. getCurrentlyOnLargeContainer() {
  446. return largeVideo.getCurrentContainer();
  447. },
  448. isCurrentlyOnLarge(id) {
  449. return largeVideo && largeVideo.id === id;
  450. },
  451. /**
  452. * Triggers an update of remote video and large video displays so they may
  453. * pick up any state changes that have occurred elsewhere.
  454. *
  455. * @returns {void}
  456. */
  457. updateAllVideos() {
  458. const displayedUserId = this.getLargeVideoID();
  459. if (displayedUserId) {
  460. this.updateLargeVideo(displayedUserId, true);
  461. }
  462. Object.keys(remoteVideos).forEach(video => {
  463. remoteVideos[video].updateView();
  464. });
  465. },
  466. updateLargeVideo(id, forceUpdate) {
  467. if (!largeVideo) {
  468. return;
  469. }
  470. const currentContainer = largeVideo.getCurrentContainer();
  471. const currentContainerType = largeVideo.getCurrentContainerType();
  472. const isOnLarge = this.isCurrentlyOnLarge(id);
  473. const state = APP.store.getState();
  474. const videoTrack = getTrackByMediaTypeAndParticipant(state['features/base/tracks'], MEDIA_TYPE.VIDEO, id);
  475. const videoStream = videoTrack?.jitsiTrack;
  476. if (isOnLarge && !forceUpdate
  477. && LargeVideoManager.isVideoContainer(currentContainerType)
  478. && videoStream) {
  479. const currentStreamId = currentContainer.getStreamID();
  480. const newStreamId = videoStream?.getId() || null;
  481. // FIXME it might be possible to get rid of 'forceUpdate' argument
  482. if (currentStreamId !== newStreamId) {
  483. logger.debug('Enforcing large video update for stream change');
  484. forceUpdate = true; // eslint-disable-line no-param-reassign
  485. }
  486. }
  487. if (!isOnLarge || forceUpdate) {
  488. const videoType = this.getRemoteVideoType(id);
  489. largeVideo.updateLargeVideo(
  490. id,
  491. videoStream,
  492. videoType || VIDEO_TYPE.CAMERA
  493. ).catch(() => {
  494. // do nothing
  495. });
  496. }
  497. },
  498. addLargeVideoContainer(type, container) {
  499. largeVideo && largeVideo.addContainer(type, container);
  500. },
  501. removeLargeVideoContainer(type) {
  502. largeVideo && largeVideo.removeContainer(type);
  503. },
  504. /**
  505. * @returns Promise
  506. */
  507. showLargeVideoContainer(type, show) {
  508. if (!largeVideo) {
  509. return Promise.reject();
  510. }
  511. const isVisible = this.isLargeContainerTypeVisible(type);
  512. if (isVisible === show) {
  513. return Promise.resolve();
  514. }
  515. const currentId = largeVideo.id;
  516. let oldSmallVideo;
  517. if (currentId) {
  518. oldSmallVideo = this.getSmallVideo(currentId);
  519. }
  520. let containerTypeToShow = type;
  521. // if we are hiding a container and there is focusedVideo
  522. // (pinned remote video) use its video type,
  523. // if not then use default type - large video
  524. if (!show) {
  525. const pinnedId = this.getPinnedId();
  526. if (pinnedId) {
  527. containerTypeToShow = this.getRemoteVideoType(pinnedId);
  528. } else {
  529. containerTypeToShow = VIDEO_CONTAINER_TYPE;
  530. }
  531. }
  532. return largeVideo.showContainer(containerTypeToShow)
  533. .then(() => {
  534. if (oldSmallVideo) {
  535. oldSmallVideo && oldSmallVideo.updateView();
  536. }
  537. });
  538. },
  539. isLargeContainerTypeVisible(type) {
  540. return largeVideo && largeVideo.state === type;
  541. },
  542. /**
  543. * Returns the id of the current video shown on large.
  544. * Currently used by tests (torture).
  545. */
  546. getLargeVideoID() {
  547. return largeVideo && largeVideo.id;
  548. },
  549. /**
  550. * Returns the the current video shown on large.
  551. * Currently used by tests (torture).
  552. */
  553. getLargeVideo() {
  554. return largeVideo;
  555. },
  556. /**
  557. * Sets the flipX state of the local video.
  558. * @param {boolean} true for flipped otherwise false;
  559. */
  560. setLocalFlipX(val) {
  561. this.localFlipX = val;
  562. },
  563. /**
  564. * Handles user's features changes.
  565. */
  566. onUserFeaturesChanged(user) {
  567. const video = this.getSmallVideo(user.getId());
  568. if (!video) {
  569. return;
  570. }
  571. this._setRemoteControlProperties(user, video);
  572. },
  573. /**
  574. * Sets the remote control properties (checks whether remote control
  575. * is supported and executes remoteVideo.setRemoteControlSupport).
  576. * @param {JitsiParticipant} user the user that will be checked for remote
  577. * control support.
  578. * @param {RemoteVideo} remoteVideo the remoteVideo on which the properties
  579. * will be set.
  580. */
  581. _setRemoteControlProperties(user, remoteVideo) {
  582. APP.remoteControl.checkUserRemoteControlSupport(user)
  583. .then(result => remoteVideo.setRemoteControlSupport(result))
  584. .catch(error =>
  585. logger.warn(`could not get remote control properties for: ${user.getJid()}`, error));
  586. },
  587. /**
  588. * Returns the wrapper jquery selector for the largeVideo
  589. * @returns {JQuerySelector} the wrapper jquery selector for the largeVideo
  590. */
  591. getLargeVideoWrapper() {
  592. return this.getCurrentlyOnLargeContainer().$wrapper;
  593. },
  594. /**
  595. * Returns the number of remove video ids.
  596. *
  597. * @returns {number} The number of remote videos.
  598. */
  599. getRemoteVideosCount() {
  600. return Object.keys(remoteVideos).length;
  601. },
  602. /**
  603. * Sets the remote control active status for a remote participant.
  604. *
  605. * @param {string} participantID - The id of the remote participant.
  606. * @param {boolean} isActive - The new remote control active status.
  607. * @returns {void}
  608. */
  609. setRemoteControlActiveStatus(participantID, isActive) {
  610. remoteVideos[participantID].setRemoteControlActiveStatus(isActive);
  611. },
  612. /**
  613. * Sets the remote control active status for the local participant.
  614. *
  615. * @returns {void}
  616. */
  617. setLocalRemoteControlActiveChanged() {
  618. Object.values(remoteVideos).forEach(
  619. remoteVideo => remoteVideo.updateRemoteVideoMenu()
  620. );
  621. },
  622. /**
  623. * Helper method to invoke when the video layout has changed and elements
  624. * have to be re-arranged and resized.
  625. *
  626. * @returns {void}
  627. */
  628. refreshLayout() {
  629. localVideoThumbnail && localVideoThumbnail.updateDOMLocation();
  630. VideoLayout.resizeVideoArea();
  631. // Rerender the thumbnails since they are dependant on the layout because of the tooltip positioning.
  632. localVideoThumbnail && localVideoThumbnail.rerender();
  633. Object.values(remoteVideos).forEach(remoteVideoThumbnail => remoteVideoThumbnail.rerender());
  634. },
  635. /**
  636. * Cleans up any existing largeVideo instance.
  637. *
  638. * @private
  639. * @returns {void}
  640. */
  641. _resetLargeVideo() {
  642. if (largeVideo) {
  643. largeVideo.destroy();
  644. }
  645. largeVideo = null;
  646. },
  647. /**
  648. * Cleans up filmstrip state. While a separate {@code Filmstrip} exists, its
  649. * implementation is mainly for querying and manipulating the DOM while
  650. * state mostly remains in {@code VideoLayout}.
  651. *
  652. * @private
  653. * @returns {void}
  654. */
  655. _resetFilmstrip() {
  656. Object.keys(remoteVideos).forEach(remoteVideoId => {
  657. this.removeParticipantContainer(remoteVideoId);
  658. delete remoteVideos[remoteVideoId];
  659. });
  660. if (localVideoThumbnail) {
  661. localVideoThumbnail.remove();
  662. localVideoThumbnail = null;
  663. }
  664. },
  665. /**
  666. * Triggers an update of large video if the passed in participant is
  667. * currently displayed on large video.
  668. *
  669. * @param {string} participantId - The participant ID that should trigger an
  670. * update of large video if displayed.
  671. * @param {boolean} force - Whether or not the large video update should
  672. * happen no matter what.
  673. * @returns {void}
  674. */
  675. _updateLargeVideoIfDisplayed(participantId, force = false) {
  676. if (this.isCurrentlyOnLarge(participantId)) {
  677. this.updateLargeVideo(participantId, force);
  678. }
  679. },
  680. /**
  681. * Handles window resizes.
  682. */
  683. onResize() {
  684. VideoLayout.resizeVideoArea();
  685. }
  686. };
  687. export default VideoLayout;