Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

LargeVideoManager.js 28KB

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