Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

LargeVideoManager.js 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. /* global APP */
  2. /* eslint-disable no-unused-vars */
  3. import Logger from '@jitsi/logger';
  4. import $ from 'jquery';
  5. import React from 'react';
  6. import ReactDOM from 'react-dom';
  7. import { I18nextProvider } from 'react-i18next';
  8. import { Provider } from 'react-redux';
  9. import { createScreenSharingIssueEvent, sendAnalytics } from '../../../react/features/analytics';
  10. import { Avatar } from '../../../react/features/base/avatar';
  11. import theme from '../../../react/features/base/components/themes/participantsPaneTheme.json';
  12. import { i18next } from '../../../react/features/base/i18n';
  13. import { JitsiTrackEvents } from '../../../react/features/base/lib-jitsi-meet';
  14. import { VIDEO_TYPE } from '../../../react/features/base/media';
  15. import {
  16. getLocalParticipant,
  17. getParticipantById,
  18. getParticipantDisplayName,
  19. isLocalScreenshareParticipant,
  20. isScreenShareParticipant
  21. } from '../../../react/features/base/participants';
  22. import { getHideSelfView } from '../../../react/features/base/settings/functions.any';
  23. import {
  24. getVideoTrackByParticipant,
  25. trackStreamingStatusChanged
  26. } from '../../../react/features/base/tracks';
  27. import { CHAT_SIZE } from '../../../react/features/chat';
  28. import {
  29. isTrackStreamingStatusActive,
  30. isTrackStreamingStatusInactive,
  31. isTrackStreamingStatusInterrupted
  32. } from '../../../react/features/connection-indicator/functions';
  33. import { FILMSTRIP_BREAKPOINT } from '../../../react/features/filmstrip/constants';
  34. import { getVerticalViewMaxWidth, isFilmstripResizable } from '../../../react/features/filmstrip/functions';
  35. import {
  36. updateKnownLargeVideoResolution
  37. } from '../../../react/features/large-video/actions';
  38. import { getParticipantsPaneOpen } from '../../../react/features/participants-pane/functions';
  39. import { PresenceLabel } from '../../../react/features/presence-status';
  40. import { shouldDisplayTileView } from '../../../react/features/video-layout';
  41. /* eslint-enable no-unused-vars */
  42. import { createDeferred } from '../../util/helpers';
  43. import AudioLevels from '../audio_levels/AudioLevels';
  44. import { VIDEO_CONTAINER_TYPE, VideoContainer } from './VideoContainer';
  45. const logger = Logger.getLogger(__filename);
  46. const DESKTOP_CONTAINER_TYPE = 'desktop';
  47. /**
  48. * Manager for all Large containers.
  49. */
  50. export default class LargeVideoManager {
  51. /**
  52. * Checks whether given container is a {@link VIDEO_CONTAINER_TYPE}.
  53. * FIXME currently this is a workaround for the problem where video type is
  54. * mixed up with container type.
  55. * @param {string} containerType
  56. * @return {boolean}
  57. */
  58. static isVideoContainer(containerType) {
  59. return containerType === VIDEO_CONTAINER_TYPE
  60. || containerType === DESKTOP_CONTAINER_TYPE;
  61. }
  62. /**
  63. *
  64. */
  65. constructor() {
  66. /**
  67. * The map of <tt>LargeContainer</tt>s where the key is the video
  68. * container type.
  69. * @type {Object.<string, LargeContainer>}
  70. */
  71. this.containers = {};
  72. this.state = VIDEO_CONTAINER_TYPE;
  73. // FIXME: We are passing resizeContainer as parameter which is calling
  74. // Container.resize. Probably there's better way to implement this.
  75. this.videoContainer = new VideoContainer(() => this.resizeContainer(VIDEO_CONTAINER_TYPE));
  76. this.addContainer(VIDEO_CONTAINER_TYPE, this.videoContainer);
  77. // use the same video container to handle desktop tracks
  78. this.addContainer(DESKTOP_CONTAINER_TYPE, this.videoContainer);
  79. /**
  80. * The preferred width passed as an argument to {@link updateContainerSize}.
  81. *
  82. * @type {number|undefined}
  83. */
  84. this.preferredWidth = undefined;
  85. /**
  86. * The preferred height passed as an argument to {@link updateContainerSize}.
  87. *
  88. * @type {number|undefined}
  89. */
  90. this.preferredHeight = undefined;
  91. /**
  92. * The calculated width that will be used for the large video.
  93. * @type {number}
  94. */
  95. this.width = 0;
  96. /**
  97. * The calculated height that will be used for the large video.
  98. * @type {number}
  99. */
  100. this.height = 0;
  101. /**
  102. * Cache the aspect ratio of the video displayed to detect changes to
  103. * the aspect ratio on video resize events.
  104. *
  105. * @type {number}
  106. */
  107. this._videoAspectRatio = 0;
  108. /**
  109. * The video track in effect.
  110. * This is used to add and remove listeners on track streaming status change.
  111. *
  112. * @type {Object}
  113. */
  114. this.videoTrack = undefined;
  115. this.container = document.getElementById('largeVideoContainer');
  116. this.container.style.display = 'inline-block';
  117. this.container.addEventListener('mouseenter', e => this.onHoverIn(e));
  118. this.container.addEventListener('mouseleave', e => this.onHoverOut(e));
  119. // Bind event handler so it is only bound once for every instance.
  120. this._onVideoResolutionUpdate
  121. = this._onVideoResolutionUpdate.bind(this);
  122. this.videoContainer.addResizeListener(this._onVideoResolutionUpdate);
  123. this._dominantSpeakerAvatarContainer
  124. = document.getElementById('dominantSpeakerAvatarContainer');
  125. }
  126. /**
  127. * Removes any listeners registered on child components, including
  128. * React Components.
  129. *
  130. * @returns {void}
  131. */
  132. destroy() {
  133. this.videoContainer.removeResizeListener(this._onVideoResolutionUpdate);
  134. // Remove track streaming status listener.
  135. // TODO: when this class is converted to a function react component,
  136. // use a custom hook to update a local track streaming status.
  137. if (this.videoTrack && !this.videoTrack.local) {
  138. this.videoTrack.jitsiTrack.off(JitsiTrackEvents.TRACK_STREAMING_STATUS_CHANGED,
  139. this.handleTrackStreamingStatusChanged);
  140. APP.store.dispatch(trackStreamingStatusChanged(this.videoTrack.jitsiTrack,
  141. this.videoTrack.jitsiTrack.getTrackStreamingStatus()));
  142. }
  143. this.removePresenceLabel();
  144. ReactDOM.unmountComponentAtNode(this._dominantSpeakerAvatarContainer);
  145. this.container.style.display = 'none';
  146. }
  147. /**
  148. *
  149. */
  150. onHoverIn(e) {
  151. if (!this.state) {
  152. return;
  153. }
  154. const container = this.getCurrentContainer();
  155. container.onHoverIn(e);
  156. }
  157. /**
  158. *
  159. */
  160. onHoverOut(e) {
  161. if (!this.state) {
  162. return;
  163. }
  164. const container = this.getCurrentContainer();
  165. container.onHoverOut(e);
  166. }
  167. /**
  168. *
  169. */
  170. get id() {
  171. const container = this.getCurrentContainer();
  172. // If a user switch for large video is in progress then provide what
  173. // will be the end result of the update.
  174. if (this.updateInProcess
  175. && this.newStreamData
  176. && this.newStreamData.id !== container.id) {
  177. return this.newStreamData.id;
  178. }
  179. return container.id;
  180. }
  181. /**
  182. *
  183. */
  184. scheduleLargeVideoUpdate() {
  185. if (this.updateInProcess || !this.newStreamData) {
  186. return;
  187. }
  188. this.updateInProcess = true;
  189. // Include hide()/fadeOut only if we're switching between users
  190. // eslint-disable-next-line eqeqeq
  191. const container = this.getCurrentContainer();
  192. const isUserSwitch = this.newStreamData.id !== container.id;
  193. const preUpdate = isUserSwitch ? container.hide() : Promise.resolve();
  194. preUpdate.then(() => {
  195. const { id, stream, videoType, resolve } = this.newStreamData;
  196. const state = APP.store.getState();
  197. const shouldHideSelfView = getHideSelfView(state);
  198. const localId = getLocalParticipant(state)?.id;
  199. // FIXME this does not really make sense, because the videoType
  200. // (camera or desktop) is a completely different thing than
  201. // the video container type (Etherpad, SharedVideo, VideoContainer).
  202. const isVideoContainer = LargeVideoManager.isVideoContainer(videoType);
  203. this.newStreamData = null;
  204. logger.debug(`Scheduled large video update for ${id}`);
  205. this.state = videoType;
  206. // eslint-disable-next-line no-shadow
  207. const container = this.getCurrentContainer();
  208. if (shouldHideSelfView && localId === id) {
  209. return container.hide();
  210. }
  211. container.setStream(id, stream, videoType);
  212. // change the avatar url on large
  213. this.updateAvatar();
  214. const isVideoMuted = !stream || stream.isMuted();
  215. const participant = getParticipantById(state, id);
  216. const videoTrack = getVideoTrackByParticipant(state, participant);
  217. // Remove track streaming status listener from the old track and add it to the new track,
  218. // in order to stop updating track streaming status for the old track and start it for the new track.
  219. // TODO: when this class is converted to a function react component,
  220. // use a custom hook to update a local track streaming status.
  221. if (this.videoTrack?.jitsiTrack?.getSourceName() !== videoTrack?.jitsiTrack?.getSourceName()) {
  222. if (this.videoTrack && !this.videoTrack.local) {
  223. this.videoTrack.jitsiTrack.off(JitsiTrackEvents.TRACK_STREAMING_STATUS_CHANGED,
  224. this.handleTrackStreamingStatusChanged);
  225. APP.store.dispatch(trackStreamingStatusChanged(this.videoTrack.jitsiTrack,
  226. this.videoTrack.jitsiTrack.getTrackStreamingStatus()));
  227. }
  228. this.videoTrack = videoTrack;
  229. if (this.videoTrack && !this.videoTrack.local) {
  230. this.videoTrack.jitsiTrack.on(JitsiTrackEvents.TRACK_STREAMING_STATUS_CHANGED,
  231. this.handleTrackStreamingStatusChanged);
  232. APP.store.dispatch(trackStreamingStatusChanged(this.videoTrack.jitsiTrack,
  233. this.videoTrack.jitsiTrack.getTrackStreamingStatus()));
  234. }
  235. }
  236. const streamingStatusActive = isTrackStreamingStatusActive(videoTrack);
  237. const isVideoRenderable = !isVideoMuted
  238. && (APP.conference.isLocalId(id)
  239. || isLocalScreenshareParticipant(participant)
  240. || streamingStatusActive
  241. );
  242. this.videoTrack?.jitsiTrack?.getVideoType() === VIDEO_TYPE.DESKTOP
  243. && logger.debug(`Remote track ${videoTrack?.jitsiTrack}, isVideoMuted=${isVideoMuted},`
  244. + ` streamingStatusActive=${streamingStatusActive}, isVideoRenderable=${isVideoRenderable}`);
  245. const isAudioOnly = APP.conference.isAudioOnly();
  246. // Multi-stream is not supported on plan-b endpoints even if its is enabled via config.js. A virtual
  247. // screenshare tile is still created when a remote endpoint starts screenshare to keep the behavior
  248. // consistent and an avatar is displayed on the original participant thumbnail as long as screenshare is in
  249. // progress.
  250. const legacyScreenshare = videoType === VIDEO_TYPE.DESKTOP && !isScreenShareParticipant(participant);
  251. const showAvatar
  252. = isVideoContainer
  253. && ((isAudioOnly && videoType !== VIDEO_TYPE.DESKTOP) || !isVideoRenderable || legacyScreenshare);
  254. let promise;
  255. // do not show stream if video is muted
  256. // but we still should show watermark
  257. if (showAvatar) {
  258. this.showWatermark(true);
  259. // If the intention of this switch is to show the avatar
  260. // we need to make sure that the video is hidden
  261. promise = container.hide();
  262. if ((!shouldDisplayTileView(state) || participant?.pinned) // In theory the tile view may not be
  263. // enabled yet when we auto pin the participant.
  264. && participant && !participant.local && !participant.fakeParticipant) {
  265. // remote participant only
  266. const track = getVideoTrackByParticipant(state, participant);
  267. const isScreenSharing = track?.videoType === 'desktop';
  268. if (isScreenSharing) {
  269. // send the event
  270. sendAnalytics(createScreenSharingIssueEvent({
  271. source: 'large-video',
  272. isVideoMuted,
  273. isAudioOnly,
  274. isVideoContainer,
  275. videoType
  276. }));
  277. }
  278. }
  279. } else {
  280. promise = container.show();
  281. }
  282. // show the avatar on large if needed
  283. container.showAvatar(showAvatar);
  284. // Clean up audio level after previous speaker.
  285. if (showAvatar) {
  286. this.updateLargeVideoAudioLevel(0);
  287. }
  288. const messageKey = isTrackStreamingStatusInactive(videoTrack) ? 'connection.LOW_BANDWIDTH' : null;
  289. // Do not show connection status message in the audio only mode,
  290. // because it's based on the video playback status.
  291. const overrideAndHide = APP.conference.isAudioOnly();
  292. this.updateParticipantConnStatusIndication(
  293. id,
  294. !overrideAndHide && messageKey);
  295. // Change the participant id the presence label is listening to.
  296. this.updatePresenceLabel(id);
  297. this.videoContainer.positionRemoteStatusMessages();
  298. // resolve updateLargeVideo promise after everything is done
  299. promise.then(resolve);
  300. return promise;
  301. }).then(() => {
  302. // after everything is done check again if there are any pending
  303. // new streams.
  304. this.updateInProcess = false;
  305. this.scheduleLargeVideoUpdate();
  306. });
  307. }
  308. /**
  309. * Handle track streaming status change event by
  310. * by dispatching an action to update track streaming status for the given track in app state.
  311. *
  312. * @param {JitsiTrack} jitsiTrack the track with streaming status updated
  313. * @param {JitsiTrackStreamingStatus} streamingStatus the updated track streaming status
  314. *
  315. * @private
  316. */
  317. handleTrackStreamingStatusChanged(jitsiTrack, streamingStatus) {
  318. APP.store.dispatch(trackStreamingStatusChanged(jitsiTrack, streamingStatus));
  319. }
  320. /**
  321. * Shows/hides notification about participant's connectivity issues to be
  322. * shown on the large video area.
  323. *
  324. * @param {string} id the id of remote participant(MUC nickname)
  325. * @param {string|null} messageKey the i18n key of the message which will be
  326. * displayed on the large video or <tt>null</tt> to hide it.
  327. *
  328. * @private
  329. */
  330. updateParticipantConnStatusIndication(id, messageKey) {
  331. const state = APP.store.getState();
  332. if (messageKey) {
  333. // Get user's display name
  334. const displayName
  335. = getParticipantDisplayName(state, id);
  336. this._setRemoteConnectionMessage(
  337. messageKey,
  338. { displayName });
  339. // Show it now only if the VideoContainer is on top
  340. this.showRemoteConnectionMessage(
  341. LargeVideoManager.isVideoContainer(this.state));
  342. } else {
  343. // Hide the message
  344. this.showRemoteConnectionMessage(false);
  345. }
  346. }
  347. /**
  348. * Update large video.
  349. * Switches to large video even if previously other container was visible.
  350. * @param userID the userID of the participant associated with the stream
  351. * @param {JitsiTrack?} stream new stream
  352. * @param {string?} videoType new video type
  353. * @returns {Promise}
  354. */
  355. updateLargeVideo(userID, stream, videoType) {
  356. if (this.newStreamData) {
  357. this.newStreamData.reject();
  358. }
  359. this.newStreamData = createDeferred();
  360. this.newStreamData.id = userID;
  361. this.newStreamData.stream = stream;
  362. this.newStreamData.videoType = videoType;
  363. this.scheduleLargeVideoUpdate();
  364. return this.newStreamData.promise;
  365. }
  366. /**
  367. * Update container size.
  368. */
  369. updateContainerSize(width, height) {
  370. if (typeof width === 'number') {
  371. this.preferredWidth = width;
  372. }
  373. if (typeof height === 'number') {
  374. this.preferredHeight = height;
  375. }
  376. let widthToUse = this.preferredWidth || window.innerWidth;
  377. const state = APP.store.getState();
  378. const { isOpen } = state['features/chat'];
  379. const { width: filmstripWidth, visible } = state['features/filmstrip'];
  380. const isParticipantsPaneOpen = getParticipantsPaneOpen(state);
  381. const resizableFilmstrip = isFilmstripResizable(state);
  382. if (isParticipantsPaneOpen) {
  383. widthToUse -= theme.participantsPaneWidth;
  384. }
  385. if (isOpen && window.innerWidth > 580) {
  386. /**
  387. * If chat state is open, we re-compute the container width
  388. * by subtracting the default width of the chat.
  389. */
  390. widthToUse -= CHAT_SIZE;
  391. }
  392. if (resizableFilmstrip && visible && filmstripWidth.current >= FILMSTRIP_BREAKPOINT) {
  393. widthToUse -= getVerticalViewMaxWidth(state);
  394. }
  395. this.width = widthToUse;
  396. this.height = this.preferredHeight || window.innerHeight;
  397. }
  398. /**
  399. * Resize Large container of specified type.
  400. * @param {string} type type of container which should be resized.
  401. * @param {boolean} [animate=false] if resize process should be animated.
  402. */
  403. resizeContainer(type, animate = false) {
  404. const container = this.getContainer(type);
  405. container.resize(this.width, this.height, animate);
  406. }
  407. /**
  408. * Resize all Large containers.
  409. * @param {boolean} animate if resize process should be animated.
  410. */
  411. resize(animate) {
  412. // resize all containers
  413. Object.keys(this.containers)
  414. .forEach(type => this.resizeContainer(type, animate));
  415. }
  416. /**
  417. * Updates the src of the dominant speaker avatar
  418. */
  419. updateAvatar() {
  420. ReactDOM.render(
  421. <Provider store = { APP.store }>
  422. <Avatar
  423. id = "dominantSpeakerAvatar"
  424. participantId = { this.id }
  425. size = { 200 } />
  426. </Provider>,
  427. this._dominantSpeakerAvatarContainer
  428. );
  429. }
  430. /**
  431. * Updates the audio level indicator of the large video.
  432. *
  433. * @param lvl the new audio level to set
  434. */
  435. updateLargeVideoAudioLevel(lvl) {
  436. AudioLevels.updateLargeVideoAudioLevel('dominantSpeaker', lvl);
  437. }
  438. /**
  439. * Displays a message of the passed in participant id's presence status. The
  440. * message will not display if the remote connection message is displayed.
  441. *
  442. * @param {string} id - The participant ID whose associated user's presence
  443. * status should be displayed.
  444. * @returns {void}
  445. */
  446. updatePresenceLabel(id) {
  447. const isConnectionMessageVisible = getComputedStyle(
  448. document.getElementById('remoteConnectionMessage')).display !== 'none';
  449. if (isConnectionMessageVisible) {
  450. this.removePresenceLabel();
  451. return;
  452. }
  453. const presenceLabelContainer = document.getElementById('remotePresenceMessage');
  454. if (presenceLabelContainer) {
  455. ReactDOM.render(
  456. <Provider store = { APP.store }>
  457. <I18nextProvider i18n = { i18next }>
  458. <PresenceLabel
  459. participantID = { id }
  460. className = 'presence-label' />
  461. </I18nextProvider>
  462. </Provider>,
  463. presenceLabelContainer);
  464. }
  465. }
  466. /**
  467. * Removes the messages about the displayed participant's presence status.
  468. *
  469. * @returns {void}
  470. */
  471. removePresenceLabel() {
  472. const presenceLabelContainer = document.getElementById('remotePresenceMessage');
  473. if (presenceLabelContainer) {
  474. ReactDOM.unmountComponentAtNode(presenceLabelContainer);
  475. }
  476. }
  477. /**
  478. * Show or hide watermark.
  479. * @param {boolean} show
  480. */
  481. showWatermark(show) {
  482. const watermark = document.querySelectorAll('.watermark');
  483. watermark.forEach(el => {
  484. el.style.visibility = show ? 'visible' : 'hidden';
  485. });
  486. }
  487. /**
  488. * Shows hides the "avatar" message which is to be displayed either in
  489. * the middle of the screen or below the avatar image.
  490. *
  491. * @param {boolean|undefined} [show=undefined] <tt>true</tt> to show
  492. * the avatar message or <tt>false</tt> to hide it. If not provided then
  493. * the connection status of the user currently on the large video will be
  494. * obtained form "APP.conference" and the message will be displayed if
  495. * the user's connection is either interrupted or inactive.
  496. */
  497. showRemoteConnectionMessage(show) {
  498. if (typeof show !== 'boolean') {
  499. const participant = getParticipantById(APP.store.getState(), this.id);
  500. const state = APP.store.getState();
  501. const videoTrack = getVideoTrackByParticipant(state, participant);
  502. // eslint-disable-next-line no-param-reassign
  503. show = !APP.conference.isLocalId(this.id)
  504. && (isTrackStreamingStatusInterrupted(videoTrack) || isTrackStreamingStatusInactive(videoTrack));
  505. }
  506. if (show) {
  507. document.getElementById('remoteConnectionMessage').style.display = 'block';
  508. } else {
  509. document.getElementById('remoteConnectionMessage').style.display = 'none';
  510. }
  511. }
  512. /**
  513. * Updates the text which describes that the remote user is having
  514. * connectivity issues.
  515. *
  516. * @param {string} msgKey the translation key which will be used to get
  517. * the message text.
  518. * @param {object} msgOptions translation options object.
  519. *
  520. * @private
  521. */
  522. _setRemoteConnectionMessage(msgKey, msgOptions) {
  523. if (msgKey) {
  524. $('#remoteConnectionMessage')
  525. .attr('data-i18n', msgKey)
  526. .attr('data-i18n-options', JSON.stringify(msgOptions));
  527. APP.translation.translateElement(
  528. $('#remoteConnectionMessage'), msgOptions);
  529. }
  530. }
  531. /**
  532. * Add container of specified type.
  533. * @param {string} type container type
  534. * @param {LargeContainer} container container to add.
  535. */
  536. addContainer(type, container) {
  537. if (this.containers[type]) {
  538. throw new Error(`container of type ${type} already exist`);
  539. }
  540. this.containers[type] = container;
  541. this.resizeContainer(type);
  542. }
  543. /**
  544. * Get Large container of specified type.
  545. * @param {string} type container type.
  546. * @returns {LargeContainer}
  547. */
  548. getContainer(type) {
  549. const container = this.containers[type];
  550. if (!container) {
  551. throw new Error(`container of type ${type} doesn't exist`);
  552. }
  553. return container;
  554. }
  555. /**
  556. * Returns {@link LargeContainer} for the current {@link state}
  557. *
  558. * @return {LargeContainer}
  559. *
  560. * @throws an <tt>Error</tt> if there is no container for the current
  561. * {@link state}.
  562. */
  563. getCurrentContainer() {
  564. return this.getContainer(this.state);
  565. }
  566. /**
  567. * Returns type of the current {@link LargeContainer}
  568. * @return {string}
  569. */
  570. getCurrentContainerType() {
  571. return this.state;
  572. }
  573. /**
  574. * Remove Large container of specified type.
  575. * @param {string} type container type.
  576. */
  577. removeContainer(type) {
  578. if (!this.containers[type]) {
  579. throw new Error(`container of type ${type} doesn't exist`);
  580. }
  581. delete this.containers[type];
  582. }
  583. /**
  584. * Show Large container of specified type.
  585. * Does nothing if such container is already visible.
  586. * @param {string} type container type.
  587. * @returns {Promise}
  588. */
  589. showContainer(type) {
  590. if (this.state === type) {
  591. return Promise.resolve();
  592. }
  593. const oldContainer = this.containers[this.state];
  594. // FIXME when video is being replaced with other content we need to hide
  595. // companion icons/messages. It would be best if the container would
  596. // be taking care of it by itself, but that is a bigger refactoring
  597. if (LargeVideoManager.isVideoContainer(this.state)) {
  598. this.showWatermark(false);
  599. this.showRemoteConnectionMessage(false);
  600. }
  601. oldContainer.hide();
  602. this.state = type;
  603. const container = this.getContainer(type);
  604. return container.show().then(() => {
  605. if (LargeVideoManager.isVideoContainer(type)) {
  606. // FIXME when video appears on top of other content we need to
  607. // show companion icons/messages. It would be best if
  608. // the container would be taking care of it by itself, but that
  609. // is a bigger refactoring
  610. this.showWatermark(true);
  611. // "avatar" and "video connection" can not be displayed both
  612. // at the same time, but the latter is of higher priority and it
  613. // will hide the avatar one if will be displayed.
  614. this.showRemoteConnectionMessage(/* fetch the current state */);
  615. }
  616. });
  617. }
  618. /**
  619. * Changes the flipX state of the local video.
  620. * @param val {boolean} true if flipped.
  621. */
  622. onLocalFlipXChange(val) {
  623. this.videoContainer.setLocalFlipX(val);
  624. }
  625. /**
  626. * Dispatches an action to update the known resolution state of the large video and adjusts container sizes when the
  627. * resolution changes.
  628. *
  629. * @private
  630. * @returns {void}
  631. */
  632. _onVideoResolutionUpdate() {
  633. const { height, width } = this.videoContainer.getStreamSize();
  634. const { resolution } = APP.store.getState()['features/large-video'];
  635. if (height !== resolution) {
  636. APP.store.dispatch(updateKnownLargeVideoResolution(height));
  637. }
  638. const currentAspectRatio = height === 0 ? 0 : width / height;
  639. if (this._videoAspectRatio !== currentAspectRatio) {
  640. this._videoAspectRatio = currentAspectRatio;
  641. this.resize();
  642. }
  643. }
  644. }