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

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