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

LargeVideoManager.js 27KB

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