選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

VideoLayout.js 25KB

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