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

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