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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  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. if (getSourceNameSignalingFeatureFlag(APP.store.getState())) {
  141. // Remove track streaming status listener.
  142. // TODO: when this class is converted to a function react component,
  143. // use a custom hook to update a local track streaming status.
  144. if (this.videoTrack && !this.videoTrack.local) {
  145. this.videoTrack.jitsiTrack.off(JitsiTrackEvents.TRACK_STREAMING_STATUS_CHANGED,
  146. this.handleTrackStreamingStatusChanged);
  147. APP.store.dispatch(trackStreamingStatusChanged(this.videoTrack.jitsiTrack,
  148. this.videoTrack.jitsiTrack.getTrackStreamingStatus()));
  149. }
  150. }
  151. this.removePresenceLabel();
  152. ReactDOM.unmountComponentAtNode(this._dominantSpeakerAvatarContainer);
  153. this.$container.css({ display: 'none' });
  154. }
  155. /**
  156. *
  157. */
  158. onHoverIn(e) {
  159. if (!this.state) {
  160. return;
  161. }
  162. const container = this.getCurrentContainer();
  163. container.onHoverIn(e);
  164. }
  165. /**
  166. *
  167. */
  168. onHoverOut(e) {
  169. if (!this.state) {
  170. return;
  171. }
  172. const container = this.getCurrentContainer();
  173. container.onHoverOut(e);
  174. }
  175. /**
  176. *
  177. */
  178. get id() {
  179. const container = this.getCurrentContainer();
  180. // If a user switch for large video is in progress then provide what
  181. // will be the end result of the update.
  182. if (this.updateInProcess
  183. && this.newStreamData
  184. && this.newStreamData.id !== container.id) {
  185. return this.newStreamData.id;
  186. }
  187. return container.id;
  188. }
  189. /**
  190. *
  191. */
  192. scheduleLargeVideoUpdate() {
  193. if (this.updateInProcess || !this.newStreamData) {
  194. return;
  195. }
  196. this.updateInProcess = true;
  197. // Include hide()/fadeOut only if we're switching between users
  198. // eslint-disable-next-line eqeqeq
  199. const container = this.getCurrentContainer();
  200. const isUserSwitch = this.newStreamData.id !== container.id;
  201. const preUpdate = isUserSwitch ? container.hide() : Promise.resolve();
  202. preUpdate.then(() => {
  203. const { id, stream, videoType, resolve } = this.newStreamData;
  204. // FIXME this does not really make sense, because the videoType
  205. // (camera or desktop) is a completely different thing than
  206. // the video container type (Etherpad, SharedVideo, VideoContainer).
  207. const isVideoContainer = LargeVideoManager.isVideoContainer(videoType);
  208. this.newStreamData = null;
  209. logger.info(`hover in ${id}`);
  210. this.state = videoType;
  211. // eslint-disable-next-line no-shadow
  212. const container = this.getCurrentContainer();
  213. container.setStream(id, stream, videoType);
  214. // change the avatar url on large
  215. this.updateAvatar();
  216. const isVideoMuted = !stream || stream.isMuted();
  217. const state = APP.store.getState();
  218. const participant = getParticipantById(state, id);
  219. const connectionStatus = participant?.connectionStatus;
  220. let isVideoRenderable;
  221. if (getSourceNameSignalingFeatureFlag(state)) {
  222. const tracks = state['features/base/tracks'];
  223. const videoTrack = getVideoTrackByParticipant(tracks, participant);
  224. // Remove track streaming status listener from the old track and add it to the new track,
  225. // in order to stop updating track streaming status for the old track and start it for the new track.
  226. // TODO: when this class is converted to a function react component,
  227. // use a custom hook to update a local track streaming status.
  228. if (this.videoTrack?.jitsiTrack?.getSourceName() !== videoTrack?.jitsiTrack?.getSourceName()) {
  229. if (this.videoTrack && !this.videoTrack.local) {
  230. this.videoTrack.jitsiTrack.off(JitsiTrackEvents.TRACK_STREAMING_STATUS_CHANGED,
  231. this.handleTrackStreamingStatusChanged);
  232. APP.store.dispatch(trackStreamingStatusChanged(this.videoTrack.jitsiTrack,
  233. this.videoTrack.jitsiTrack.getTrackStreamingStatus()));
  234. }
  235. this.videoTrack = videoTrack;
  236. if (this.videoTrack && !this.videoTrack.local) {
  237. this.videoTrack.jitsiTrack.on(JitsiTrackEvents.TRACK_STREAMING_STATUS_CHANGED,
  238. this.handleTrackStreamingStatusChanged);
  239. APP.store.dispatch(trackStreamingStatusChanged(this.videoTrack.jitsiTrack,
  240. this.videoTrack.jitsiTrack.getTrackStreamingStatus()));
  241. }
  242. }
  243. isVideoRenderable = !isVideoMuted && (
  244. APP.conference.isLocalId(id)
  245. || participant?.isLocalScreenShare
  246. || isTrackStreamingStatusActive(videoTrack)
  247. );
  248. } else {
  249. isVideoRenderable = !isVideoMuted
  250. && (APP.conference.isLocalId(id) || isParticipantConnectionStatusActive(participant));
  251. }
  252. const isAudioOnly = APP.conference.isAudioOnly();
  253. // Multi-stream is not supported on plan-b endpoints even if its is enabled via config.js. A virtual
  254. // screenshare tile is still created when a remote endpoint starts screenshare to keep the behavior
  255. // consistent and an avatar is displayed on the original participant thumbnail as long as screenshare is in
  256. // progress.
  257. const legacyScreenshare = getMultipleVideoSupportFeatureFlag(state)
  258. && videoType === VIDEO_TYPE.DESKTOP
  259. && !participant.isVirtualScreenshareParticipant;
  260. const showAvatar
  261. = isVideoContainer
  262. && ((isAudioOnly && videoType !== VIDEO_TYPE.DESKTOP) || !isVideoRenderable || legacyScreenshare);
  263. let promise;
  264. // do not show stream if video is muted
  265. // but we still should show watermark
  266. if (showAvatar) {
  267. this.showWatermark(true);
  268. // If the intention of this switch is to show the avatar
  269. // we need to make sure that the video is hidden
  270. promise = container.hide();
  271. if ((!shouldDisplayTileView(state) || participant?.pinned) // In theory the tile view may not be
  272. // enabled yet when we auto pin the participant.
  273. && participant && !participant.local && !participant.isFakeParticipant) {
  274. // remote participant only
  275. const tracks = state['features/base/tracks'];
  276. const track = getVideoTrackByParticipant(tracks, participant);
  277. const isScreenSharing = track?.videoType === 'desktop';
  278. if (isScreenSharing) {
  279. // send the event
  280. sendAnalytics(createScreenSharingIssueEvent({
  281. source: 'large-video',
  282. connectionStatus,
  283. isVideoMuted,
  284. isAudioOnly,
  285. isVideoContainer,
  286. videoType
  287. }));
  288. }
  289. }
  290. } else {
  291. promise = container.show();
  292. }
  293. // show the avatar on large if needed
  294. container.showAvatar(showAvatar);
  295. // Clean up audio level after previous speaker.
  296. if (showAvatar) {
  297. this.updateLargeVideoAudioLevel(0);
  298. }
  299. let messageKey;
  300. if (getSourceNameSignalingFeatureFlag(state)) {
  301. const tracks = state['features/base/tracks'];
  302. const videoTrack = getVideoTrackByParticipant(tracks, participant);
  303. messageKey = isTrackStreamingStatusInactive(videoTrack) ? 'connection.LOW_BANDWIDTH' : null;
  304. } else {
  305. messageKey = isParticipantConnectionStatusInactive(participant) ? 'connection.LOW_BANDWIDTH' : null;
  306. }
  307. // Do not show connection status message in the audio only mode,
  308. // because it's based on the video playback status.
  309. const overrideAndHide = APP.conference.isAudioOnly();
  310. this.updateParticipantConnStatusIndication(
  311. id,
  312. !overrideAndHide && messageKey);
  313. // Change the participant id the presence label is listening to.
  314. this.updatePresenceLabel(id);
  315. this.videoContainer.positionRemoteStatusMessages();
  316. // resolve updateLargeVideo promise after everything is done
  317. promise.then(resolve);
  318. return promise;
  319. }).then(() => {
  320. // after everything is done check again if there are any pending
  321. // new streams.
  322. this.updateInProcess = false;
  323. this.scheduleLargeVideoUpdate();
  324. });
  325. }
  326. /**
  327. * Handle track streaming status change event by
  328. * by dispatching an action to update track streaming status for the given track in app state.
  329. *
  330. * @param {JitsiTrack} jitsiTrack the track with streaming status updated
  331. * @param {JitsiTrackStreamingStatus} streamingStatus the updated track streaming status
  332. *
  333. * @private
  334. */
  335. handleTrackStreamingStatusChanged(jitsiTrack, streamingStatus) {
  336. APP.store.dispatch(trackStreamingStatusChanged(jitsiTrack, streamingStatus));
  337. }
  338. /**
  339. * Shows/hides notification about participant's connectivity issues to be
  340. * shown on the large video area.
  341. *
  342. * @param {string} id the id of remote participant(MUC nickname)
  343. * @param {string|null} messageKey the i18n key of the message which will be
  344. * displayed on the large video or <tt>null</tt> to hide it.
  345. *
  346. * @private
  347. */
  348. updateParticipantConnStatusIndication(id, messageKey) {
  349. const state = APP.store.getState();
  350. if (messageKey) {
  351. // Get user's display name
  352. const displayName
  353. = getParticipantDisplayName(state, id);
  354. this._setRemoteConnectionMessage(
  355. messageKey,
  356. { displayName });
  357. // Show it now only if the VideoContainer is on top
  358. this.showRemoteConnectionMessage(
  359. LargeVideoManager.isVideoContainer(this.state));
  360. } else {
  361. // Hide the message
  362. this.showRemoteConnectionMessage(false);
  363. }
  364. }
  365. /**
  366. * Update large video.
  367. * Switches to large video even if previously other container was visible.
  368. * @param userID the userID of the participant associated with the stream
  369. * @param {JitsiTrack?} stream new stream
  370. * @param {string?} videoType new video type
  371. * @returns {Promise}
  372. */
  373. updateLargeVideo(userID, stream, videoType) {
  374. if (this.newStreamData) {
  375. this.newStreamData.reject();
  376. }
  377. this.newStreamData = createDeferred();
  378. this.newStreamData.id = userID;
  379. this.newStreamData.stream = stream;
  380. this.newStreamData.videoType = videoType;
  381. this.scheduleLargeVideoUpdate();
  382. return this.newStreamData.promise;
  383. }
  384. /**
  385. * Update container size.
  386. */
  387. updateContainerSize(width, height) {
  388. if (typeof width === 'number') {
  389. this.preferredWidth = width;
  390. }
  391. if (typeof height === 'number') {
  392. this.preferredHeight = height;
  393. }
  394. let widthToUse = this.preferredWidth || window.innerWidth;
  395. const state = APP.store.getState();
  396. const { isOpen } = state['features/chat'];
  397. const { width: filmstripWidth, visible } = state['features/filmstrip'];
  398. const isParticipantsPaneOpen = getParticipantsPaneOpen(state);
  399. const resizableFilmstrip = isFilmstripResizable(state);
  400. if (isParticipantsPaneOpen) {
  401. widthToUse -= theme.participantsPaneWidth;
  402. }
  403. if (isOpen && window.innerWidth > 580) {
  404. /**
  405. * If chat state is open, we re-compute the container width
  406. * by subtracting the default width of the chat.
  407. */
  408. widthToUse -= CHAT_SIZE;
  409. }
  410. if (resizableFilmstrip && visible && filmstripWidth.current >= FILMSTRIP_BREAKPOINT) {
  411. widthToUse -= getVerticalViewMaxWidth(state);
  412. }
  413. this.width = widthToUse;
  414. this.height = this.preferredHeight || window.innerHeight;
  415. }
  416. /**
  417. * Resize Large container of specified type.
  418. * @param {string} type type of container which should be resized.
  419. * @param {boolean} [animate=false] if resize process should be animated.
  420. */
  421. resizeContainer(type, animate = false) {
  422. const container = this.getContainer(type);
  423. container.resize(this.width, this.height, animate);
  424. }
  425. /**
  426. * Resize all Large containers.
  427. * @param {boolean} animate if resize process should be animated.
  428. */
  429. resize(animate) {
  430. // resize all containers
  431. Object.keys(this.containers)
  432. .forEach(type => this.resizeContainer(type, animate));
  433. }
  434. /**
  435. * Updates the src of the dominant speaker avatar
  436. */
  437. updateAvatar() {
  438. ReactDOM.render(
  439. <Provider store = { APP.store }>
  440. <Avatar
  441. id = "dominantSpeakerAvatar"
  442. participantId = { this.id }
  443. size = { 200 } />
  444. </Provider>,
  445. this._dominantSpeakerAvatarContainer
  446. );
  447. }
  448. /**
  449. * Updates the audio level indicator of the large video.
  450. *
  451. * @param lvl the new audio level to set
  452. */
  453. updateLargeVideoAudioLevel(lvl) {
  454. AudioLevels.updateLargeVideoAudioLevel('dominantSpeaker', lvl);
  455. }
  456. /**
  457. * Displays a message of the passed in participant id's presence status. The
  458. * message will not display if the remote connection message is displayed.
  459. *
  460. * @param {string} id - The participant ID whose associated user's presence
  461. * status should be displayed.
  462. * @returns {void}
  463. */
  464. updatePresenceLabel(id) {
  465. const isConnectionMessageVisible
  466. = $('#remoteConnectionMessage').is(':visible');
  467. if (isConnectionMessageVisible) {
  468. this.removePresenceLabel();
  469. return;
  470. }
  471. const presenceLabelContainer = $('#remotePresenceMessage');
  472. if (presenceLabelContainer.length) {
  473. ReactDOM.render(
  474. <Provider store = { APP.store }>
  475. <I18nextProvider i18n = { i18next }>
  476. <PresenceLabel
  477. participantID = { id }
  478. className = 'presence-label' />
  479. </I18nextProvider>
  480. </Provider>,
  481. presenceLabelContainer.get(0));
  482. }
  483. }
  484. /**
  485. * Removes the messages about the displayed participant's presence status.
  486. *
  487. * @returns {void}
  488. */
  489. removePresenceLabel() {
  490. const presenceLabelContainer = $('#remotePresenceMessage');
  491. if (presenceLabelContainer.length) {
  492. ReactDOM.unmountComponentAtNode(presenceLabelContainer.get(0));
  493. }
  494. }
  495. /**
  496. * Show or hide watermark.
  497. * @param {boolean} show
  498. */
  499. showWatermark(show) {
  500. $('.watermark').css('visibility', show ? 'visible' : 'hidden');
  501. }
  502. /**
  503. * Shows hides the "avatar" message which is to be displayed either in
  504. * the middle of the screen or below the avatar image.
  505. *
  506. * @param {boolean|undefined} [show=undefined] <tt>true</tt> to show
  507. * the avatar message or <tt>false</tt> to hide it. If not provided then
  508. * the connection status of the user currently on the large video will be
  509. * obtained form "APP.conference" and the message will be displayed if
  510. * the user's connection is either interrupted or inactive.
  511. */
  512. showRemoteConnectionMessage(show) {
  513. if (typeof show !== 'boolean') {
  514. const participant = getParticipantById(APP.store.getState(), this.id);
  515. const state = APP.store.getState();
  516. if (getSourceNameSignalingFeatureFlag(state)) {
  517. const tracks = state['features/base/tracks'];
  518. const videoTrack = getVideoTrackByParticipant(tracks, participant);
  519. // eslint-disable-next-line no-param-reassign
  520. show = !APP.conference.isLocalId(this.id)
  521. && (isTrackStreamingStatusInterrupted(videoTrack)
  522. || isTrackStreamingStatusInactive(videoTrack));
  523. } else {
  524. // eslint-disable-next-line no-param-reassign
  525. show = !APP.conference.isLocalId(this.id)
  526. && (isParticipantConnectionStatusInterrupted(participant)
  527. || isParticipantConnectionStatusInactive(participant));
  528. }
  529. }
  530. if (show) {
  531. $('#remoteConnectionMessage').css({ display: 'block' });
  532. } else {
  533. $('#remoteConnectionMessage').hide();
  534. }
  535. }
  536. /**
  537. * Updates the text which describes that the remote user is having
  538. * connectivity issues.
  539. *
  540. * @param {string} msgKey the translation key which will be used to get
  541. * the message text.
  542. * @param {object} msgOptions translation options object.
  543. *
  544. * @private
  545. */
  546. _setRemoteConnectionMessage(msgKey, msgOptions) {
  547. if (msgKey) {
  548. $('#remoteConnectionMessage')
  549. .attr('data-i18n', msgKey)
  550. .attr('data-i18n-options', JSON.stringify(msgOptions));
  551. APP.translation.translateElement(
  552. $('#remoteConnectionMessage'), msgOptions);
  553. }
  554. }
  555. /**
  556. * Add container of specified type.
  557. * @param {string} type container type
  558. * @param {LargeContainer} container container to add.
  559. */
  560. addContainer(type, container) {
  561. if (this.containers[type]) {
  562. throw new Error(`container of type ${type} already exist`);
  563. }
  564. this.containers[type] = container;
  565. this.resizeContainer(type);
  566. }
  567. /**
  568. * Get Large container of specified type.
  569. * @param {string} type container type.
  570. * @returns {LargeContainer}
  571. */
  572. getContainer(type) {
  573. const container = this.containers[type];
  574. if (!container) {
  575. throw new Error(`container of type ${type} doesn't exist`);
  576. }
  577. return container;
  578. }
  579. /**
  580. * Returns {@link LargeContainer} for the current {@link state}
  581. *
  582. * @return {LargeContainer}
  583. *
  584. * @throws an <tt>Error</tt> if there is no container for the current
  585. * {@link state}.
  586. */
  587. getCurrentContainer() {
  588. return this.getContainer(this.state);
  589. }
  590. /**
  591. * Returns type of the current {@link LargeContainer}
  592. * @return {string}
  593. */
  594. getCurrentContainerType() {
  595. return this.state;
  596. }
  597. /**
  598. * Remove Large container of specified type.
  599. * @param {string} type container type.
  600. */
  601. removeContainer(type) {
  602. if (!this.containers[type]) {
  603. throw new Error(`container of type ${type} doesn't exist`);
  604. }
  605. delete this.containers[type];
  606. }
  607. /**
  608. * Show Large container of specified type.
  609. * Does nothing if such container is already visible.
  610. * @param {string} type container type.
  611. * @returns {Promise}
  612. */
  613. showContainer(type) {
  614. if (this.state === type) {
  615. return Promise.resolve();
  616. }
  617. const oldContainer = this.containers[this.state];
  618. // FIXME when video is being replaced with other content we need to hide
  619. // companion icons/messages. It would be best if the container would
  620. // be taking care of it by itself, but that is a bigger refactoring
  621. if (LargeVideoManager.isVideoContainer(this.state)) {
  622. this.showWatermark(false);
  623. this.showRemoteConnectionMessage(false);
  624. }
  625. oldContainer.hide();
  626. this.state = type;
  627. const container = this.getContainer(type);
  628. return container.show().then(() => {
  629. if (LargeVideoManager.isVideoContainer(type)) {
  630. // FIXME when video appears on top of other content we need to
  631. // show companion icons/messages. It would be best if
  632. // the container would be taking care of it by itself, but that
  633. // is a bigger refactoring
  634. this.showWatermark(true);
  635. // "avatar" and "video connection" can not be displayed both
  636. // at the same time, but the latter is of higher priority and it
  637. // will hide the avatar one if will be displayed.
  638. this.showRemoteConnectionMessage(/* fetch the current state */);
  639. }
  640. });
  641. }
  642. /**
  643. * Changes the flipX state of the local video.
  644. * @param val {boolean} true if flipped.
  645. */
  646. onLocalFlipXChange(val) {
  647. this.videoContainer.setLocalFlipX(val);
  648. }
  649. /**
  650. * Dispatches an action to update the known resolution state of the large video and adjusts container sizes when the
  651. * resolution changes.
  652. *
  653. * @private
  654. * @returns {void}
  655. */
  656. _onVideoResolutionUpdate() {
  657. const { height, width } = this.videoContainer.getStreamSize();
  658. const { resolution } = APP.store.getState()['features/large-video'];
  659. if (height !== resolution) {
  660. APP.store.dispatch(updateKnownLargeVideoResolution(height));
  661. }
  662. const currentAspectRatio = height === 0 ? 0 : width / height;
  663. if (this._videoAspectRatio !== currentAspectRatio) {
  664. this._videoAspectRatio = currentAspectRatio;
  665. this.resize();
  666. }
  667. }
  668. }