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.

LargeVideoManager.js 27KB

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