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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  1. /* global APP, $, interfaceConfig */
  2. const logger = require('jitsi-meet-logger').getLogger(__filename);
  3. import {
  4. JitsiParticipantConnectionStatus
  5. } from '../../../react/features/base/lib-jitsi-meet';
  6. import { VIDEO_TYPE } from '../../../react/features/base/media';
  7. import {
  8. getLocalParticipant as getLocalParticipantFromStore,
  9. getPinnedParticipant,
  10. pinParticipant
  11. } from '../../../react/features/base/participants';
  12. import { SHARED_VIDEO_CONTAINER_TYPE } from '../shared_video/SharedVideo';
  13. import SharedVideoThumb from '../shared_video/SharedVideoThumb';
  14. import UIEvents from '../../../service/UI/UIEvents';
  15. import RemoteVideo from './RemoteVideo';
  16. import LargeVideoManager from './LargeVideoManager';
  17. import { VIDEO_CONTAINER_TYPE } from './VideoContainer';
  18. import LocalVideo from './LocalVideo';
  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. // sets default video type of local video
  66. // FIXME container type is totally different thing from the video type
  67. localVideoThumbnail.setVideoType(VIDEO_CONTAINER_TYPE);
  68. this.registerListeners();
  69. },
  70. /**
  71. * Registering listeners for UI events in Video layout component.
  72. *
  73. * @returns {void}
  74. */
  75. registerListeners() {
  76. eventEmitter.addListener(UIEvents.LOCAL_FLIPX_CHANGED,
  77. onLocalFlipXChanged);
  78. },
  79. /**
  80. * Cleans up state of this singleton {@code VideoLayout}.
  81. *
  82. * @returns {void}
  83. */
  84. reset() {
  85. this._resetLargeVideo();
  86. this._resetFilmstrip();
  87. },
  88. initLargeVideo() {
  89. this._resetLargeVideo();
  90. largeVideo = new LargeVideoManager(eventEmitter);
  91. if (localFlipX) {
  92. largeVideo.onLocalFlipXChange(localFlipX);
  93. }
  94. largeVideo.updateContainerSize();
  95. },
  96. /**
  97. * Sets the audio level of the video elements associated to the given id.
  98. *
  99. * @param id the video identifier in the form it comes from the library
  100. * @param lvl the new audio level to update to
  101. */
  102. setAudioLevel(id, lvl) {
  103. const smallVideo = this.getSmallVideo(id);
  104. if (smallVideo) {
  105. smallVideo.updateAudioLevelIndicator(lvl);
  106. }
  107. if (largeVideo && id === largeVideo.id) {
  108. largeVideo.updateLargeVideoAudioLevel(lvl);
  109. }
  110. },
  111. changeLocalVideo(stream) {
  112. const localId = getLocalParticipant().id;
  113. this.onVideoTypeChanged(localId, stream.videoType);
  114. localVideoThumbnail.changeVideo(stream);
  115. this._updateLargeVideoIfDisplayed(localId);
  116. },
  117. /**
  118. * Get's the localID of the conference and set it to the local video
  119. * (small one). This needs to be called as early as possible, when muc is
  120. * actually joined. Otherwise events can come with information like email
  121. * and setting them assume the id is already set.
  122. */
  123. mucJoined() {
  124. // FIXME: replace this call with a generic update call once SmallVideo
  125. // only contains a ReactElement. Then remove this call once the
  126. // Filmstrip is fully in React.
  127. localVideoThumbnail.updateIndicators();
  128. },
  129. /**
  130. * Shows/hides local video.
  131. * @param {boolean} true to make the local video visible, false - otherwise
  132. */
  133. setLocalVideoVisible(visible) {
  134. localVideoThumbnail.setVisible(visible);
  135. },
  136. onRemoteStreamAdded(stream) {
  137. const id = stream.getParticipantId();
  138. const remoteVideo = remoteVideos[id];
  139. logger.debug(`Received a new ${stream.getType()} stream for ${id}`);
  140. if (!remoteVideo) {
  141. logger.debug('No remote video element to add stream');
  142. return;
  143. }
  144. remoteVideo.addRemoteStreamElement(stream);
  145. // Make sure track's muted state is reflected
  146. if (stream.getType() === 'audio') {
  147. this.onAudioMute(stream.getParticipantId(), stream.isMuted());
  148. } else {
  149. this.onVideoMute(stream.getParticipantId(), stream.isMuted());
  150. }
  151. },
  152. onRemoteStreamRemoved(stream) {
  153. const id = stream.getParticipantId();
  154. const remoteVideo = remoteVideos[id];
  155. // Remote stream may be removed after participant left the conference.
  156. if (remoteVideo) {
  157. remoteVideo.removeRemoteStreamElement(stream);
  158. }
  159. this.updateMutedForNoTracks(id, stream.getType());
  160. },
  161. /**
  162. * FIXME get rid of this method once muted indicator are reactified (by
  163. * making sure that user with no tracks is displayed as muted )
  164. *
  165. * If participant has no tracks will make the UI display muted status.
  166. * @param {string} participantId
  167. * @param {string} mediaType 'audio' or 'video'
  168. */
  169. updateMutedForNoTracks(participantId, mediaType) {
  170. const participant = APP.conference.getParticipantById(participantId);
  171. if (participant
  172. && !participant.getTracksByMediaType(mediaType).length) {
  173. if (mediaType === 'audio') {
  174. APP.UI.setAudioMuted(participantId, true);
  175. } else if (mediaType === 'video') {
  176. APP.UI.setVideoMuted(participantId, true);
  177. } else {
  178. logger.error(`Unsupported media type: ${mediaType}`);
  179. }
  180. }
  181. },
  182. /**
  183. * Return the type of the remote video.
  184. * @param id the id for the remote video
  185. * @returns {String} the video type video or screen.
  186. */
  187. getRemoteVideoType(id) {
  188. const smallVideo = VideoLayout.getSmallVideo(id);
  189. return smallVideo ? smallVideo.getVideoType() : null;
  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. if (!remoteVideo.getVideoType()) {
  259. // make video type the default one (camera)
  260. // FIXME container type is not a video type
  261. remoteVideo.setVideoType(VIDEO_CONTAINER_TYPE);
  262. }
  263. // Initialize the view
  264. remoteVideo.updateView();
  265. },
  266. // FIXME: what does this do???
  267. remoteVideoActive(videoElement, resourceJid) {
  268. logger.info(`${resourceJid} video is now active`, videoElement);
  269. if (videoElement) {
  270. $(videoElement).show();
  271. }
  272. this._updateLargeVideoIfDisplayed(resourceJid, true);
  273. },
  274. /**
  275. * Shows a visual indicator for the moderator of the conference.
  276. * On local or remote participants.
  277. */
  278. showModeratorIndicator() {
  279. const isModerator = APP.conference.isModerator;
  280. if (isModerator) {
  281. localVideoThumbnail.addModeratorIndicator();
  282. } else {
  283. localVideoThumbnail.removeModeratorIndicator();
  284. }
  285. APP.conference.listMembers().forEach(member => {
  286. const id = member.getId();
  287. const remoteVideo = remoteVideos[id];
  288. if (!remoteVideo) {
  289. return;
  290. }
  291. if (member.isModerator()) {
  292. remoteVideo.addModeratorIndicator();
  293. }
  294. remoteVideo.updateRemoteVideoMenu();
  295. });
  296. },
  297. /**
  298. * On audio muted event.
  299. */
  300. onAudioMute(id, isMuted) {
  301. if (APP.conference.isLocalId(id)) {
  302. localVideoThumbnail.showAudioIndicator(isMuted);
  303. } else {
  304. const remoteVideo = remoteVideos[id];
  305. if (!remoteVideo) {
  306. return;
  307. }
  308. remoteVideo.showAudioIndicator(isMuted);
  309. remoteVideo.updateRemoteVideoMenu(isMuted);
  310. }
  311. },
  312. /**
  313. * On video muted event.
  314. */
  315. onVideoMute(id, value) {
  316. if (APP.conference.isLocalId(id)) {
  317. localVideoThumbnail && localVideoThumbnail.setVideoMutedView(value);
  318. } else {
  319. const remoteVideo = remoteVideos[id];
  320. if (remoteVideo) {
  321. remoteVideo.setVideoMutedView(value);
  322. }
  323. }
  324. // large video will show avatar instead of muted stream
  325. this._updateLargeVideoIfDisplayed(id, true);
  326. },
  327. /**
  328. * Display name changed.
  329. */
  330. onDisplayNameChanged(id) {
  331. if (id === 'localVideoContainer'
  332. || APP.conference.isLocalId(id)) {
  333. localVideoThumbnail.updateDisplayName();
  334. } else {
  335. const remoteVideo = remoteVideos[id];
  336. if (remoteVideo) {
  337. remoteVideo.updateDisplayName();
  338. }
  339. }
  340. },
  341. /**
  342. * On dominant speaker changed event.
  343. *
  344. * @param {string} id - The participant ID of the new dominant speaker.
  345. * @returns {void}
  346. */
  347. onDominantSpeakerChanged(id) {
  348. getAllThumbnails().forEach(thumbnail =>
  349. thumbnail.showDominantSpeakerIndicator(id === thumbnail.getId()));
  350. },
  351. /**
  352. * Shows/hides warning about a user's connectivity issues.
  353. *
  354. * @param {string} id - The ID of the remote participant(MUC nickname).
  355. * @param {status} status - The new connection status.
  356. * @returns {void}
  357. */
  358. onParticipantConnectionStatusChanged(id, status) {
  359. if (APP.conference.isLocalId(id)) {
  360. // Maintain old logic of passing in either interrupted or active
  361. // to updateConnectionStatus.
  362. localVideoThumbnail.updateConnectionStatus(status);
  363. if (status === JitsiParticipantConnectionStatus.INTERRUPTED) {
  364. largeVideo && largeVideo.onVideoInterrupted();
  365. } else {
  366. largeVideo && largeVideo.onVideoRestored();
  367. }
  368. return;
  369. }
  370. // We have to trigger full large video update to transition from
  371. // avatar to video on connectivity restored.
  372. this._updateLargeVideoIfDisplayed(id, true);
  373. const remoteVideo = remoteVideos[id];
  374. if (remoteVideo) {
  375. // Updating only connection status indicator is not enough, because
  376. // when we the connection is restored while the avatar was displayed
  377. // (due to 'muted while disconnected' condition) we may want to show
  378. // the video stream again and in order to do that the display mode
  379. // must be updated.
  380. // remoteVideo.updateConnectionStatusIndicator(isActive);
  381. remoteVideo.updateView();
  382. }
  383. },
  384. /**
  385. * On last N change event.
  386. *
  387. * @param endpointsLeavingLastN the list currently leaving last N
  388. * endpoints
  389. * @param endpointsEnteringLastN the list currently entering last N
  390. * endpoints
  391. */
  392. onLastNEndpointsChanged(endpointsLeavingLastN, endpointsEnteringLastN) {
  393. if (endpointsLeavingLastN) {
  394. endpointsLeavingLastN.forEach(this._updateRemoteVideo, this);
  395. }
  396. if (endpointsEnteringLastN) {
  397. endpointsEnteringLastN.forEach(this._updateRemoteVideo, this);
  398. }
  399. },
  400. /**
  401. * Updates remote video by id if it exists.
  402. * @param {string} id of the remote video
  403. * @private
  404. */
  405. _updateRemoteVideo(id) {
  406. const remoteVideo = remoteVideos[id];
  407. if (remoteVideo) {
  408. remoteVideo.updateView();
  409. this._updateLargeVideoIfDisplayed(id);
  410. }
  411. },
  412. /**
  413. * Hides all the indicators
  414. */
  415. hideStats() {
  416. for (const video in remoteVideos) { // eslint-disable-line guard-for-in
  417. const remoteVideo = remoteVideos[video];
  418. if (remoteVideo) {
  419. remoteVideo.removeConnectionIndicator();
  420. }
  421. }
  422. localVideoThumbnail.removeConnectionIndicator();
  423. },
  424. removeParticipantContainer(id) {
  425. // Unlock large video
  426. if (this.getPinnedId() === id) {
  427. logger.info('Focused video owner has left the conference');
  428. APP.store.dispatch(pinParticipant(null));
  429. }
  430. const remoteVideo = remoteVideos[id];
  431. if (remoteVideo) {
  432. // Remove remote video
  433. logger.info(`Removing remote video: ${id}`);
  434. delete remoteVideos[id];
  435. remoteVideo.remove();
  436. } else {
  437. logger.warn(`No remote video for ${id}`);
  438. }
  439. },
  440. onVideoTypeChanged(id, newVideoType) {
  441. if (VideoLayout.getRemoteVideoType(id) === newVideoType) {
  442. return;
  443. }
  444. logger.info('Peer video type changed: ', id, newVideoType);
  445. let smallVideo;
  446. if (APP.conference.isLocalId(id)) {
  447. if (!localVideoThumbnail) {
  448. logger.warn('Local video not ready yet');
  449. return;
  450. }
  451. smallVideo = localVideoThumbnail;
  452. } else if (remoteVideos[id]) {
  453. smallVideo = remoteVideos[id];
  454. } else {
  455. return;
  456. }
  457. smallVideo.setVideoType(newVideoType);
  458. this._updateLargeVideoIfDisplayed(id, true);
  459. },
  460. /**
  461. * Resizes the video area.
  462. *
  463. * TODO: Remove the "animate" param as it is no longer passed in as true.
  464. *
  465. * @param forceUpdate indicates that hidden thumbnails will be shown
  466. */
  467. resizeVideoArea(animate = false) {
  468. if (largeVideo) {
  469. largeVideo.updateContainerSize();
  470. largeVideo.resize(animate);
  471. }
  472. },
  473. getSmallVideo(id) {
  474. if (APP.conference.isLocalId(id)) {
  475. return localVideoThumbnail;
  476. }
  477. return remoteVideos[id];
  478. },
  479. changeUserAvatar(id, avatarUrl) {
  480. const smallVideo = VideoLayout.getSmallVideo(id);
  481. if (smallVideo) {
  482. smallVideo.initializeAvatar();
  483. } else {
  484. logger.warn(
  485. `Missed avatar update - no small video yet for ${id}`
  486. );
  487. }
  488. if (this.isCurrentlyOnLarge(id)) {
  489. largeVideo.updateAvatar(avatarUrl);
  490. }
  491. },
  492. isLargeVideoVisible() {
  493. return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
  494. },
  495. /**
  496. * @return {LargeContainer} the currently displayed container on large
  497. * video.
  498. */
  499. getCurrentlyOnLargeContainer() {
  500. return largeVideo.getCurrentContainer();
  501. },
  502. isCurrentlyOnLarge(id) {
  503. return largeVideo && largeVideo.id === id;
  504. },
  505. /**
  506. * Triggers an update of remote video and large video displays so they may
  507. * pick up any state changes that have occurred elsewhere.
  508. *
  509. * @returns {void}
  510. */
  511. updateAllVideos() {
  512. const displayedUserId = this.getLargeVideoID();
  513. if (displayedUserId) {
  514. this.updateLargeVideo(displayedUserId, true);
  515. }
  516. Object.keys(remoteVideos).forEach(video => {
  517. remoteVideos[video].updateView();
  518. });
  519. },
  520. updateLargeVideo(id, forceUpdate) {
  521. if (!largeVideo) {
  522. return;
  523. }
  524. const currentContainer = largeVideo.getCurrentContainer();
  525. const currentContainerType = largeVideo.getCurrentContainerType();
  526. const currentId = largeVideo.id;
  527. const isOnLarge = this.isCurrentlyOnLarge(id);
  528. const smallVideo = this.getSmallVideo(id);
  529. if (isOnLarge && !forceUpdate
  530. && LargeVideoManager.isVideoContainer(currentContainerType)
  531. && smallVideo) {
  532. const currentStreamId = currentContainer.getStreamID();
  533. const newStreamId
  534. = smallVideo.videoStream
  535. ? smallVideo.videoStream.getId() : null;
  536. // FIXME it might be possible to get rid of 'forceUpdate' argument
  537. if (currentStreamId !== newStreamId) {
  538. logger.debug('Enforcing large video update for stream change');
  539. forceUpdate = true; // eslint-disable-line no-param-reassign
  540. }
  541. }
  542. if ((!isOnLarge || forceUpdate) && smallVideo) {
  543. const videoType = this.getRemoteVideoType(id);
  544. // FIXME video type is not the same thing as container type
  545. if (id !== currentId && videoType === VIDEO_CONTAINER_TYPE) {
  546. APP.API.notifyOnStageParticipantChanged(id);
  547. }
  548. let oldSmallVideo;
  549. if (currentId) {
  550. oldSmallVideo = this.getSmallVideo(currentId);
  551. }
  552. smallVideo.waitForResolutionChange();
  553. if (oldSmallVideo) {
  554. oldSmallVideo.waitForResolutionChange();
  555. }
  556. largeVideo.updateLargeVideo(
  557. id,
  558. smallVideo.videoStream,
  559. videoType || VIDEO_TYPE.CAMERA
  560. ).then(() => {
  561. // update current small video and the old one
  562. smallVideo.updateView();
  563. oldSmallVideo && oldSmallVideo.updateView();
  564. }, () => {
  565. // use clicked other video during update, nothing to do.
  566. });
  567. } else if (currentId) {
  568. const currentSmallVideo = this.getSmallVideo(currentId);
  569. currentSmallVideo && currentSmallVideo.updateView();
  570. }
  571. },
  572. addLargeVideoContainer(type, container) {
  573. largeVideo && largeVideo.addContainer(type, container);
  574. },
  575. removeLargeVideoContainer(type) {
  576. largeVideo && largeVideo.removeContainer(type);
  577. },
  578. /**
  579. * @returns Promise
  580. */
  581. showLargeVideoContainer(type, show) {
  582. if (!largeVideo) {
  583. return Promise.reject();
  584. }
  585. const isVisible = this.isLargeContainerTypeVisible(type);
  586. if (isVisible === show) {
  587. return Promise.resolve();
  588. }
  589. const currentId = largeVideo.id;
  590. let oldSmallVideo;
  591. if (currentId) {
  592. oldSmallVideo = this.getSmallVideo(currentId);
  593. }
  594. let containerTypeToShow = type;
  595. // if we are hiding a container and there is focusedVideo
  596. // (pinned remote video) use its video type,
  597. // if not then use default type - large video
  598. if (!show) {
  599. const pinnedId = this.getPinnedId();
  600. if (pinnedId) {
  601. containerTypeToShow = this.getRemoteVideoType(pinnedId);
  602. } else {
  603. containerTypeToShow = VIDEO_CONTAINER_TYPE;
  604. }
  605. }
  606. return largeVideo.showContainer(containerTypeToShow)
  607. .then(() => {
  608. if (oldSmallVideo) {
  609. oldSmallVideo && oldSmallVideo.updateView();
  610. }
  611. });
  612. },
  613. isLargeContainerTypeVisible(type) {
  614. return largeVideo && largeVideo.state === type;
  615. },
  616. /**
  617. * Returns the id of the current video shown on large.
  618. * Currently used by tests (torture).
  619. */
  620. getLargeVideoID() {
  621. return largeVideo && largeVideo.id;
  622. },
  623. /**
  624. * Returns the the current video shown on large.
  625. * Currently used by tests (torture).
  626. */
  627. getLargeVideo() {
  628. return largeVideo;
  629. },
  630. /**
  631. * Sets the flipX state of the local video.
  632. * @param {boolean} true for flipped otherwise false;
  633. */
  634. setLocalFlipX(val) {
  635. this.localFlipX = val;
  636. },
  637. getEventEmitter() {
  638. return eventEmitter;
  639. },
  640. /**
  641. * Handles user's features changes.
  642. */
  643. onUserFeaturesChanged(user) {
  644. const video = this.getSmallVideo(user.getId());
  645. if (!video) {
  646. return;
  647. }
  648. this._setRemoteControlProperties(user, video);
  649. },
  650. /**
  651. * Sets the remote control properties (checks whether remote control
  652. * is supported and executes remoteVideo.setRemoteControlSupport).
  653. * @param {JitsiParticipant} user the user that will be checked for remote
  654. * control support.
  655. * @param {RemoteVideo} remoteVideo the remoteVideo on which the properties
  656. * will be set.
  657. */
  658. _setRemoteControlProperties(user, remoteVideo) {
  659. APP.remoteControl.checkUserRemoteControlSupport(user)
  660. .then(result => remoteVideo.setRemoteControlSupport(result))
  661. .catch(error =>
  662. logger.warn('could not get remote control properties', error));
  663. },
  664. /**
  665. * Returns the wrapper jquery selector for the largeVideo
  666. * @returns {JQuerySelector} the wrapper jquery selector for the largeVideo
  667. */
  668. getLargeVideoWrapper() {
  669. return this.getCurrentlyOnLargeContainer().$wrapper;
  670. },
  671. /**
  672. * Returns the number of remove video ids.
  673. *
  674. * @returns {number} The number of remote videos.
  675. */
  676. getRemoteVideosCount() {
  677. return Object.keys(remoteVideos).length;
  678. },
  679. /**
  680. * Sets the remote control active status for a remote participant.
  681. *
  682. * @param {string} participantID - The id of the remote participant.
  683. * @param {boolean} isActive - The new remote control active status.
  684. * @returns {void}
  685. */
  686. setRemoteControlActiveStatus(participantID, isActive) {
  687. remoteVideos[participantID].setRemoteControlActiveStatus(isActive);
  688. },
  689. /**
  690. * Sets the remote control active status for the local participant.
  691. *
  692. * @returns {void}
  693. */
  694. setLocalRemoteControlActiveChanged() {
  695. Object.values(remoteVideos).forEach(
  696. remoteVideo => remoteVideo.updateRemoteVideoMenu()
  697. );
  698. },
  699. /**
  700. * Helper method to invoke when the video layout has changed and elements
  701. * have to be re-arranged and resized.
  702. *
  703. * @returns {void}
  704. */
  705. refreshLayout() {
  706. localVideoThumbnail && localVideoThumbnail.updateDOMLocation();
  707. VideoLayout.resizeVideoArea();
  708. // Rerender the thumbnails since they are dependant on the layout because of the tooltip positioning.
  709. localVideoThumbnail && localVideoThumbnail.rerender();
  710. Object.values(remoteVideos).forEach(remoteVideoThumbnail => remoteVideoThumbnail.rerender());
  711. },
  712. /**
  713. * Cleans up any existing largeVideo instance.
  714. *
  715. * @private
  716. * @returns {void}
  717. */
  718. _resetLargeVideo() {
  719. if (largeVideo) {
  720. largeVideo.destroy();
  721. }
  722. largeVideo = null;
  723. },
  724. /**
  725. * Cleans up filmstrip state. While a separate {@code Filmstrip} exists, its
  726. * implementation is mainly for querying and manipulating the DOM while
  727. * state mostly remains in {@code VideoLayout}.
  728. *
  729. * @private
  730. * @returns {void}
  731. */
  732. _resetFilmstrip() {
  733. Object.keys(remoteVideos).forEach(remoteVideoId => {
  734. this.removeParticipantContainer(remoteVideoId);
  735. delete remoteVideos[remoteVideoId];
  736. });
  737. if (localVideoThumbnail) {
  738. localVideoThumbnail.remove();
  739. localVideoThumbnail = null;
  740. }
  741. },
  742. /**
  743. * Triggers an update of large video if the passed in participant is
  744. * currently displayed on large video.
  745. *
  746. * @param {string} participantId - The participant ID that should trigger an
  747. * update of large video if displayed.
  748. * @param {boolean} force - Whether or not the large video update should
  749. * happen no matter what.
  750. * @returns {void}
  751. */
  752. _updateLargeVideoIfDisplayed(participantId, force = false) {
  753. if (this.isCurrentlyOnLarge(participantId)) {
  754. this.updateLargeVideo(participantId, force);
  755. }
  756. },
  757. /**
  758. * Handles window resizes.
  759. */
  760. onResize() {
  761. VideoLayout.resizeVideoArea();
  762. }
  763. };
  764. export default VideoLayout;