Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

VideoLayout.js 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  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. * TODO: Remove the "animate" param as it is no longer passed in as true.
  452. *
  453. * @param forceUpdate indicates that hidden thumbnails will be shown
  454. */
  455. resizeVideoArea(animate = false) {
  456. if (largeVideo) {
  457. largeVideo.updateContainerSize();
  458. largeVideo.resize(animate);
  459. }
  460. },
  461. getSmallVideo(id) {
  462. if (APP.conference.isLocalId(id)) {
  463. return localVideoThumbnail;
  464. }
  465. return remoteVideos[id];
  466. },
  467. changeUserAvatar(id, avatarUrl) {
  468. const smallVideo = VideoLayout.getSmallVideo(id);
  469. if (smallVideo) {
  470. smallVideo.initializeAvatar();
  471. } else {
  472. logger.warn(
  473. `Missed avatar update - no small video yet for ${id}`
  474. );
  475. }
  476. if (this.isCurrentlyOnLarge(id)) {
  477. largeVideo.updateAvatar(avatarUrl);
  478. }
  479. },
  480. isLargeVideoVisible() {
  481. return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
  482. },
  483. /**
  484. * @return {LargeContainer} the currently displayed container on large
  485. * video.
  486. */
  487. getCurrentlyOnLargeContainer() {
  488. return largeVideo.getCurrentContainer();
  489. },
  490. isCurrentlyOnLarge(id) {
  491. return largeVideo && largeVideo.id === id;
  492. },
  493. /**
  494. * Triggers an update of remote video and large video displays so they may
  495. * pick up any state changes that have occurred elsewhere.
  496. *
  497. * @returns {void}
  498. */
  499. updateAllVideos() {
  500. const displayedUserId = this.getLargeVideoID();
  501. if (displayedUserId) {
  502. this.updateLargeVideo(displayedUserId, true);
  503. }
  504. Object.keys(remoteVideos).forEach(video => {
  505. remoteVideos[video].updateView();
  506. });
  507. },
  508. updateLargeVideo(id, forceUpdate) {
  509. if (!largeVideo) {
  510. return;
  511. }
  512. const currentContainer = largeVideo.getCurrentContainer();
  513. const currentContainerType = largeVideo.getCurrentContainerType();
  514. const currentId = largeVideo.id;
  515. const isOnLarge = this.isCurrentlyOnLarge(id);
  516. const smallVideo = this.getSmallVideo(id);
  517. if (isOnLarge && !forceUpdate
  518. && LargeVideoManager.isVideoContainer(currentContainerType)
  519. && smallVideo) {
  520. const currentStreamId = currentContainer.getStreamID();
  521. const newStreamId
  522. = smallVideo.videoStream
  523. ? smallVideo.videoStream.getId() : null;
  524. // FIXME it might be possible to get rid of 'forceUpdate' argument
  525. if (currentStreamId !== newStreamId) {
  526. logger.debug('Enforcing large video update for stream change');
  527. forceUpdate = true; // eslint-disable-line no-param-reassign
  528. }
  529. }
  530. if ((!isOnLarge || forceUpdate) && smallVideo) {
  531. const videoType = this.getRemoteVideoType(id);
  532. // FIXME video type is not the same thing as container type
  533. if (id !== currentId && videoType === VIDEO_CONTAINER_TYPE) {
  534. APP.API.notifyOnStageParticipantChanged(id);
  535. }
  536. let oldSmallVideo;
  537. if (currentId) {
  538. oldSmallVideo = this.getSmallVideo(currentId);
  539. }
  540. smallVideo.waitForResolutionChange();
  541. if (oldSmallVideo) {
  542. oldSmallVideo.waitForResolutionChange();
  543. }
  544. largeVideo.updateLargeVideo(
  545. id,
  546. smallVideo.videoStream,
  547. videoType || VIDEO_TYPE.CAMERA
  548. ).then(() => {
  549. // update current small video and the old one
  550. smallVideo.updateView();
  551. oldSmallVideo && oldSmallVideo.updateView();
  552. }, () => {
  553. // use clicked other video during update, nothing to do.
  554. });
  555. } else if (currentId) {
  556. const currentSmallVideo = this.getSmallVideo(currentId);
  557. currentSmallVideo && currentSmallVideo.updateView();
  558. }
  559. },
  560. addLargeVideoContainer(type, container) {
  561. largeVideo && largeVideo.addContainer(type, container);
  562. },
  563. removeLargeVideoContainer(type) {
  564. largeVideo && largeVideo.removeContainer(type);
  565. },
  566. /**
  567. * @returns Promise
  568. */
  569. showLargeVideoContainer(type, show) {
  570. if (!largeVideo) {
  571. return Promise.reject();
  572. }
  573. const isVisible = this.isLargeContainerTypeVisible(type);
  574. if (isVisible === show) {
  575. return Promise.resolve();
  576. }
  577. const currentId = largeVideo.id;
  578. let oldSmallVideo;
  579. if (currentId) {
  580. oldSmallVideo = this.getSmallVideo(currentId);
  581. }
  582. let containerTypeToShow = type;
  583. // if we are hiding a container and there is focusedVideo
  584. // (pinned remote video) use its video type,
  585. // if not then use default type - large video
  586. if (!show) {
  587. const pinnedId = this.getPinnedId();
  588. if (pinnedId) {
  589. containerTypeToShow = this.getRemoteVideoType(pinnedId);
  590. } else {
  591. containerTypeToShow = VIDEO_CONTAINER_TYPE;
  592. }
  593. }
  594. return largeVideo.showContainer(containerTypeToShow)
  595. .then(() => {
  596. if (oldSmallVideo) {
  597. oldSmallVideo && oldSmallVideo.updateView();
  598. }
  599. });
  600. },
  601. isLargeContainerTypeVisible(type) {
  602. return largeVideo && largeVideo.state === type;
  603. },
  604. /**
  605. * Returns the id of the current video shown on large.
  606. * Currently used by tests (torture).
  607. */
  608. getLargeVideoID() {
  609. return largeVideo && largeVideo.id;
  610. },
  611. /**
  612. * Returns the the current video shown on large.
  613. * Currently used by tests (torture).
  614. */
  615. getLargeVideo() {
  616. return largeVideo;
  617. },
  618. /**
  619. * Sets the flipX state of the local video.
  620. * @param {boolean} true for flipped otherwise false;
  621. */
  622. setLocalFlipX(val) {
  623. this.localFlipX = val;
  624. },
  625. getEventEmitter() {
  626. return eventEmitter;
  627. },
  628. /**
  629. * Handles user's features changes.
  630. */
  631. onUserFeaturesChanged(user) {
  632. const video = this.getSmallVideo(user.getId());
  633. if (!video) {
  634. return;
  635. }
  636. this._setRemoteControlProperties(user, video);
  637. },
  638. /**
  639. * Sets the remote control properties (checks whether remote control
  640. * is supported and executes remoteVideo.setRemoteControlSupport).
  641. * @param {JitsiParticipant} user the user that will be checked for remote
  642. * control support.
  643. * @param {RemoteVideo} remoteVideo the remoteVideo on which the properties
  644. * will be set.
  645. */
  646. _setRemoteControlProperties(user, remoteVideo) {
  647. APP.remoteControl.checkUserRemoteControlSupport(user)
  648. .then(result => remoteVideo.setRemoteControlSupport(result))
  649. .catch(error =>
  650. logger.warn('could not get remote control properties', error));
  651. },
  652. /**
  653. * Returns the wrapper jquery selector for the largeVideo
  654. * @returns {JQuerySelector} the wrapper jquery selector for the largeVideo
  655. */
  656. getLargeVideoWrapper() {
  657. return this.getCurrentlyOnLargeContainer().$wrapper;
  658. },
  659. /**
  660. * Returns the number of remove video ids.
  661. *
  662. * @returns {number} The number of remote videos.
  663. */
  664. getRemoteVideosCount() {
  665. return Object.keys(remoteVideos).length;
  666. },
  667. /**
  668. * Sets the remote control active status for a remote participant.
  669. *
  670. * @param {string} participantID - The id of the remote participant.
  671. * @param {boolean} isActive - The new remote control active status.
  672. * @returns {void}
  673. */
  674. setRemoteControlActiveStatus(participantID, isActive) {
  675. remoteVideos[participantID].setRemoteControlActiveStatus(isActive);
  676. },
  677. /**
  678. * Sets the remote control active status for the local participant.
  679. *
  680. * @returns {void}
  681. */
  682. setLocalRemoteControlActiveChanged() {
  683. Object.values(remoteVideos).forEach(
  684. remoteVideo => remoteVideo.updateRemoteVideoMenu()
  685. );
  686. },
  687. /**
  688. * Helper method to invoke when the video layout has changed and elements
  689. * have to be re-arranged and resized.
  690. *
  691. * @returns {void}
  692. */
  693. refreshLayout() {
  694. localVideoThumbnail && localVideoThumbnail.updateDOMLocation();
  695. VideoLayout.resizeVideoArea();
  696. // Rerender the thumbnails since they are dependant on the layout because of the tooltip positioning.
  697. localVideoThumbnail && localVideoThumbnail.rerender();
  698. Object.values(remoteVideos).forEach(remoteVideoThumbnail => remoteVideoThumbnail.rerender());
  699. },
  700. /**
  701. * Cleans up any existing largeVideo instance.
  702. *
  703. * @private
  704. * @returns {void}
  705. */
  706. _resetLargeVideo() {
  707. if (largeVideo) {
  708. largeVideo.destroy();
  709. }
  710. largeVideo = null;
  711. },
  712. /**
  713. * Cleans up filmstrip state. While a separate {@code Filmstrip} exists, its
  714. * implementation is mainly for querying and manipulating the DOM while
  715. * state mostly remains in {@code VideoLayout}.
  716. *
  717. * @private
  718. * @returns {void}
  719. */
  720. _resetFilmstrip() {
  721. Object.keys(remoteVideos).forEach(remoteVideoId => {
  722. this.removeParticipantContainer(remoteVideoId);
  723. delete remoteVideos[remoteVideoId];
  724. });
  725. if (localVideoThumbnail) {
  726. localVideoThumbnail.remove();
  727. localVideoThumbnail = null;
  728. }
  729. },
  730. /**
  731. * Triggers an update of large video if the passed in participant is
  732. * currently displayed on large video.
  733. *
  734. * @param {string} participantId - The participant ID that should trigger an
  735. * update of large video if displayed.
  736. * @param {boolean} force - Whether or not the large video update should
  737. * happen no matter what.
  738. * @returns {void}
  739. */
  740. _updateLargeVideoIfDisplayed(participantId, force = false) {
  741. if (this.isCurrentlyOnLarge(participantId)) {
  742. this.updateLargeVideo(participantId, force);
  743. }
  744. },
  745. /**
  746. * Handles window resizes.
  747. */
  748. onResize() {
  749. VideoLayout.resizeVideoArea();
  750. }
  751. };
  752. export default VideoLayout;