您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

LargeVideoManager.js 27KB

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