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.

SmallVideo.js 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. /* global $, APP, config, interfaceConfig */
  2. /* eslint-disable no-unused-vars */
  3. import { AtlasKitThemeProvider } from '@atlaskit/theme';
  4. import Logger from 'jitsi-meet-logger';
  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 { AudioLevelIndicator } from '../../../react/features/audio-level-indicator';
  10. import { Avatar as AvatarDisplay } from '../../../react/features/base/avatar';
  11. import { i18next } from '../../../react/features/base/i18n';
  12. import { MEDIA_TYPE } from '../../../react/features/base/media';
  13. import {
  14. getLocalParticipant,
  15. getParticipantById,
  16. getParticipantCount,
  17. getPinnedParticipant,
  18. pinParticipant
  19. } from '../../../react/features/base/participants';
  20. import { isLocalTrackMuted, isRemoteTrackMuted } from '../../../react/features/base/tracks';
  21. import { ConnectionIndicator } from '../../../react/features/connection-indicator';
  22. import { DisplayName } from '../../../react/features/display-name';
  23. import {
  24. DominantSpeakerIndicator,
  25. RaisedHandIndicator,
  26. StatusIndicators
  27. } from '../../../react/features/filmstrip';
  28. import {
  29. LAYOUTS,
  30. getCurrentLayout,
  31. setTileView,
  32. shouldDisplayTileView
  33. } from '../../../react/features/video-layout';
  34. /* eslint-enable no-unused-vars */
  35. const logger = Logger.getLogger(__filename);
  36. /**
  37. * Display mode constant used when video is being displayed on the small video.
  38. * @type {number}
  39. * @constant
  40. */
  41. const DISPLAY_VIDEO = 0;
  42. /**
  43. * Display mode constant used when the user's avatar is being displayed on
  44. * the small video.
  45. * @type {number}
  46. * @constant
  47. */
  48. const DISPLAY_AVATAR = 1;
  49. /**
  50. * Display mode constant used when neither video nor avatar is being displayed
  51. * on the small video. And we just show the display name.
  52. * @type {number}
  53. * @constant
  54. */
  55. const DISPLAY_BLACKNESS_WITH_NAME = 2;
  56. /**
  57. * Display mode constant used when video is displayed and display name
  58. * at the same time.
  59. * @type {number}
  60. * @constant
  61. */
  62. const DISPLAY_VIDEO_WITH_NAME = 3;
  63. /**
  64. * Display mode constant used when neither video nor avatar is being displayed
  65. * on the small video. And we just show the display name.
  66. * @type {number}
  67. * @constant
  68. */
  69. const DISPLAY_AVATAR_WITH_NAME = 4;
  70. /**
  71. *
  72. */
  73. export default class SmallVideo {
  74. /**
  75. * Constructor.
  76. */
  77. constructor(VideoLayout) {
  78. this.isAudioMuted = false;
  79. this.isScreenSharing = false;
  80. this.videoStream = null;
  81. this.audioStream = null;
  82. this.VideoLayout = VideoLayout;
  83. this.videoIsHovered = false;
  84. this.videoType = undefined;
  85. /**
  86. * The current state of the user's bridge connection. The value should be
  87. * a string as enumerated in the library's participantConnectionStatus
  88. * constants.
  89. *
  90. * @private
  91. * @type {string|null}
  92. */
  93. this._connectionStatus = null;
  94. /**
  95. * Whether or not the connection indicator should be displayed.
  96. *
  97. * @private
  98. * @type {boolean}
  99. */
  100. this._showConnectionIndicator = !interfaceConfig.CONNECTION_INDICATOR_DISABLED;
  101. /**
  102. * Whether or not the dominant speaker indicator should be displayed.
  103. *
  104. * @private
  105. * @type {boolean}
  106. */
  107. this._showDominantSpeaker = false;
  108. /**
  109. * Whether or not the raised hand indicator should be displayed.
  110. *
  111. * @private
  112. * @type {boolean}
  113. */
  114. this._showRaisedHand = false;
  115. // Bind event handlers so they are only bound once for every instance.
  116. this.updateView = this.updateView.bind(this);
  117. this._onContainerClick = this._onContainerClick.bind(this);
  118. }
  119. /**
  120. * Returns the identifier of this small video.
  121. *
  122. * @returns the identifier of this small video
  123. */
  124. getId() {
  125. return this.id;
  126. }
  127. /**
  128. * Indicates if this small video is currently visible.
  129. *
  130. * @return <tt>true</tt> if this small video isn't currently visible and
  131. * <tt>false</tt> - otherwise.
  132. */
  133. isVisible() {
  134. return this.$container.is(':visible');
  135. }
  136. /**
  137. * Creates an audio or video element for a particular MediaStream.
  138. */
  139. static createStreamElement(stream) {
  140. const isVideo = stream.isVideoTrack();
  141. const element = isVideo ? document.createElement('video') : document.createElement('audio');
  142. if (isVideo) {
  143. element.setAttribute('muted', 'true');
  144. element.setAttribute('playsInline', 'true'); /* for Safari on iOS to work */
  145. } else if (config.startSilent) {
  146. element.muted = true;
  147. }
  148. element.autoplay = !config.testing?.noAutoPlayVideo;
  149. element.id = SmallVideo.getStreamElementID(stream);
  150. return element;
  151. }
  152. /**
  153. * Returns the element id for a particular MediaStream.
  154. */
  155. static getStreamElementID(stream) {
  156. return (stream.isVideoTrack() ? 'remoteVideo_' : 'remoteAudio_') + stream.getId();
  157. }
  158. /**
  159. * Configures hoverIn/hoverOut handlers. Depends on connection indicator.
  160. */
  161. bindHoverHandler() {
  162. // Add hover handler
  163. this.$container.hover(
  164. () => {
  165. this.videoIsHovered = true;
  166. this.updateView();
  167. this.updateIndicators();
  168. },
  169. () => {
  170. this.videoIsHovered = false;
  171. this.updateView();
  172. this.updateIndicators();
  173. }
  174. );
  175. }
  176. /**
  177. * Unmounts the ConnectionIndicator component.
  178. * @returns {void}
  179. */
  180. removeConnectionIndicator() {
  181. this._showConnectionIndicator = false;
  182. this.updateIndicators();
  183. }
  184. /**
  185. * Updates the connectionStatus stat which displays in the ConnectionIndicator.
  186. * @returns {void}
  187. */
  188. updateConnectionStatus(connectionStatus) {
  189. this._connectionStatus = connectionStatus;
  190. this.updateIndicators();
  191. }
  192. /**
  193. * Shows / hides the audio muted indicator over small videos.
  194. *
  195. * @param {boolean} isMuted indicates if the muted element should be shown
  196. * or hidden
  197. */
  198. showAudioIndicator(isMuted) {
  199. this.isAudioMuted = isMuted;
  200. this.updateStatusBar();
  201. }
  202. /**
  203. * Shows / hides the screen-share indicator over small videos.
  204. *
  205. * @param {boolean} isScreenSharing indicates if the screen-share element should be shown
  206. * or hidden
  207. */
  208. setScreenSharing(isScreenSharing) {
  209. if (isScreenSharing === this.isScreenSharing) {
  210. return;
  211. }
  212. this.isScreenSharing = isScreenSharing;
  213. this.updateView();
  214. this.updateStatusBar();
  215. }
  216. /**
  217. * Create or updates the ReactElement for displaying status indicators about
  218. * audio mute, video mute, and moderator status.
  219. *
  220. * @returns {void}
  221. */
  222. updateStatusBar() {
  223. const statusBarContainer = this.container.querySelector('.videocontainer__toolbar');
  224. if (!statusBarContainer) {
  225. return;
  226. }
  227. ReactDOM.render(
  228. <Provider store = { APP.store }>
  229. <I18nextProvider i18n = { i18next }>
  230. <StatusIndicators
  231. showAudioMutedIndicator = { this.isAudioMuted }
  232. showScreenShareIndicator = { this.isScreenSharing }
  233. participantID = { this.id } />
  234. </I18nextProvider>
  235. </Provider>,
  236. statusBarContainer);
  237. }
  238. /**
  239. * Adds the element indicating the audio level of the participant.
  240. *
  241. * @returns {void}
  242. */
  243. addAudioLevelIndicator() {
  244. let audioLevelContainer = this._getAudioLevelContainer();
  245. if (audioLevelContainer) {
  246. return;
  247. }
  248. audioLevelContainer = document.createElement('span');
  249. audioLevelContainer.className = 'audioindicator-container';
  250. this.container.appendChild(audioLevelContainer);
  251. this.updateAudioLevelIndicator();
  252. }
  253. /**
  254. * Removes the element indicating the audio level of the participant.
  255. *
  256. * @returns {void}
  257. */
  258. removeAudioLevelIndicator() {
  259. const audioLevelContainer = this._getAudioLevelContainer();
  260. if (audioLevelContainer) {
  261. ReactDOM.unmountComponentAtNode(audioLevelContainer);
  262. }
  263. }
  264. /**
  265. * Updates the audio level for this small video.
  266. *
  267. * @param lvl the new audio level to set
  268. * @returns {void}
  269. */
  270. updateAudioLevelIndicator(lvl = 0) {
  271. const audioLevelContainer = this._getAudioLevelContainer();
  272. if (audioLevelContainer) {
  273. ReactDOM.render(<AudioLevelIndicator audioLevel = { lvl }/>, audioLevelContainer);
  274. }
  275. }
  276. /**
  277. * Queries the component's DOM for the element that should be the parent to the
  278. * AudioLevelIndicator.
  279. *
  280. * @returns {HTMLElement} The DOM element that holds the AudioLevelIndicator.
  281. */
  282. _getAudioLevelContainer() {
  283. return this.container.querySelector('.audioindicator-container');
  284. }
  285. /**
  286. * This is an especially interesting function. A naive reader might think that
  287. * it returns this SmallVideo's "video" element. But it is much more exciting.
  288. * It first finds this video's parent element using jquery, then uses a utility
  289. * from lib-jitsi-meet to extract the video element from it (with two more
  290. * jquery calls), and finally uses jquery again to encapsulate the video element
  291. * in an array. This last step allows (some might prefer "forces") users of
  292. * this function to access the video element via the 0th element of the returned
  293. * array (after checking its length of course!).
  294. */
  295. selectVideoElement() {
  296. return $($(this.container).find('video')[0]);
  297. }
  298. /**
  299. * Selects the HTML image element which displays user's avatar.
  300. *
  301. * @return {jQuery|HTMLElement} a jQuery selector pointing to the HTML image
  302. * element which displays the user's avatar.
  303. */
  304. $avatar() {
  305. return this.$container.find('.avatar-container');
  306. }
  307. /**
  308. * Returns the display name element, which appears on the video thumbnail.
  309. *
  310. * @return {jQuery} a jQuery selector pointing to the display name element of
  311. * the video thumbnail
  312. */
  313. $displayName() {
  314. return this.$container.find('.displayNameContainer');
  315. }
  316. /**
  317. * Creates or updates the participant's display name that is shown over the
  318. * video preview.
  319. *
  320. * @param {Object} props - The React {@code Component} props to pass into the
  321. * {@code DisplayName} component.
  322. * @returns {void}
  323. */
  324. _renderDisplayName(props) {
  325. const displayNameContainer = this.container.querySelector('.displayNameContainer');
  326. if (displayNameContainer) {
  327. ReactDOM.render(
  328. <Provider store = { APP.store }>
  329. <I18nextProvider i18n = { i18next }>
  330. <DisplayName { ...props } />
  331. </I18nextProvider>
  332. </Provider>,
  333. displayNameContainer);
  334. }
  335. }
  336. /**
  337. * Removes the component responsible for showing the participant's display name,
  338. * if its container is present.
  339. *
  340. * @returns {void}
  341. */
  342. removeDisplayName() {
  343. const displayNameContainer = this.container.querySelector('.displayNameContainer');
  344. if (displayNameContainer) {
  345. ReactDOM.unmountComponentAtNode(displayNameContainer);
  346. }
  347. }
  348. /**
  349. * Enables / disables the css responsible for focusing/pinning a video
  350. * thumbnail.
  351. *
  352. * @param isFocused indicates if the thumbnail should be focused/pinned or not
  353. */
  354. focus(isFocused) {
  355. const focusedCssClass = 'videoContainerFocused';
  356. const isFocusClassEnabled = this.$container.hasClass(focusedCssClass);
  357. if (!isFocused && isFocusClassEnabled) {
  358. this.$container.removeClass(focusedCssClass);
  359. } else if (isFocused && !isFocusClassEnabled) {
  360. this.$container.addClass(focusedCssClass);
  361. }
  362. }
  363. /**
  364. *
  365. */
  366. hasVideo() {
  367. return this.selectVideoElement().length !== 0;
  368. }
  369. /**
  370. * Checks whether the user associated with this <tt>SmallVideo</tt> is currently
  371. * being displayed on the "large video".
  372. *
  373. * @return {boolean} <tt>true</tt> if the user is displayed on the large video
  374. * or <tt>false</tt> otherwise.
  375. */
  376. isCurrentlyOnLargeVideo() {
  377. return APP.store.getState()['features/large-video']?.participantId === this.id;
  378. }
  379. /**
  380. * Checks whether there is a playable video stream available for the user
  381. * associated with this <tt>SmallVideo</tt>.
  382. *
  383. * @return {boolean} <tt>true</tt> if there is a playable video stream available
  384. * or <tt>false</tt> otherwise.
  385. */
  386. isVideoPlayable() {
  387. const state = APP.store.getState();
  388. const tracks = state['features/base/tracks'];
  389. const participant = this.id ? getParticipantById(state, this.id) : getLocalParticipant(state);
  390. let isVideoMuted = true;
  391. if (participant?.local) {
  392. isVideoMuted = isLocalTrackMuted(tracks, MEDIA_TYPE.VIDEO);
  393. } else if (!participant?.isFakeParticipant) { // remote participants excluding shared video
  394. isVideoMuted = isRemoteTrackMuted(tracks, MEDIA_TYPE.VIDEO, this.id);
  395. }
  396. return this.videoStream && !isVideoMuted && !APP.conference.isAudioOnly();
  397. }
  398. /**
  399. * Determines what should be display on the thumbnail.
  400. *
  401. * @return {number} one of <tt>DISPLAY_VIDEO</tt>,<tt>DISPLAY_AVATAR</tt>
  402. * or <tt>DISPLAY_BLACKNESS_WITH_NAME</tt>.
  403. */
  404. selectDisplayMode(input) {
  405. if (!input.tileViewActive && input.isScreenSharing) {
  406. return input.isHovered ? DISPLAY_AVATAR_WITH_NAME : DISPLAY_AVATAR;
  407. } else if (input.isCurrentlyOnLargeVideo && !input.tileViewActive) {
  408. // Display name is always and only displayed when user is on the stage
  409. return input.isVideoPlayable && !input.isAudioOnly ? DISPLAY_BLACKNESS_WITH_NAME : DISPLAY_AVATAR_WITH_NAME;
  410. } else if (input.isVideoPlayable && input.hasVideo && !input.isAudioOnly) {
  411. // check hovering and change state to video with name
  412. return input.isHovered ? DISPLAY_VIDEO_WITH_NAME : DISPLAY_VIDEO;
  413. }
  414. // check hovering and change state to avatar with name
  415. return input.isHovered ? DISPLAY_AVATAR_WITH_NAME : DISPLAY_AVATAR;
  416. }
  417. /**
  418. * Computes information that determine the display mode.
  419. *
  420. * @returns {Object}
  421. */
  422. computeDisplayModeInput() {
  423. return {
  424. isCurrentlyOnLargeVideo: this.isCurrentlyOnLargeVideo(),
  425. isHovered: this._isHovered(),
  426. isAudioOnly: APP.conference.isAudioOnly(),
  427. tileViewActive: shouldDisplayTileView(APP.store.getState()),
  428. isVideoPlayable: this.isVideoPlayable(),
  429. hasVideo: Boolean(this.selectVideoElement().length),
  430. connectionStatus: APP.conference.getParticipantConnectionStatus(this.id),
  431. mutedWhileDisconnected: this.mutedWhileDisconnected,
  432. canPlayEventReceived: this._canPlayEventReceived,
  433. videoStream: Boolean(this.videoStream),
  434. isScreenSharing: this.isScreenSharing,
  435. videoStreamMuted: this.videoStream ? this.videoStream.isMuted() : 'no stream'
  436. };
  437. }
  438. /**
  439. * Checks whether current video is considered hovered. Currently it is hovered
  440. * if the mouse is over the video, or if the connection
  441. * indicator is shown(hovered).
  442. * @private
  443. */
  444. _isHovered() {
  445. return this.videoIsHovered;
  446. }
  447. /**
  448. * Updates the css classes of the thumbnail based on the current state.
  449. */
  450. updateView() {
  451. this.$container.removeClass((index, classNames) =>
  452. classNames.split(' ').filter(name => name.startsWith('display-')));
  453. const oldDisplayMode = this.displayMode;
  454. let displayModeString = '';
  455. const displayModeInput = this.computeDisplayModeInput();
  456. // Determine whether video, avatar or blackness should be displayed
  457. this.displayMode = this.selectDisplayMode(displayModeInput);
  458. switch (this.displayMode) {
  459. case DISPLAY_AVATAR_WITH_NAME:
  460. displayModeString = 'avatar-with-name';
  461. this.$container.addClass('display-avatar-with-name');
  462. break;
  463. case DISPLAY_BLACKNESS_WITH_NAME:
  464. displayModeString = 'blackness-with-name';
  465. this.$container.addClass('display-name-on-black');
  466. break;
  467. case DISPLAY_VIDEO:
  468. displayModeString = 'video';
  469. this.$container.addClass('display-video');
  470. break;
  471. case DISPLAY_VIDEO_WITH_NAME:
  472. displayModeString = 'video-with-name';
  473. this.$container.addClass('display-name-on-video');
  474. break;
  475. case DISPLAY_AVATAR:
  476. default:
  477. displayModeString = 'avatar';
  478. this.$container.addClass('display-avatar-only');
  479. break;
  480. }
  481. if (this.displayMode !== oldDisplayMode) {
  482. logger.debug(`Displaying ${displayModeString} for ${this.id}, data: [${JSON.stringify(displayModeInput)}]`);
  483. }
  484. }
  485. /**
  486. * Updates the react component displaying the avatar with the passed in avatar
  487. * url.
  488. *
  489. * @returns {void}
  490. */
  491. initializeAvatar() {
  492. const thumbnail = this.$avatar().get(0);
  493. if (thumbnail) {
  494. // Maybe add a special case for local participant, as on init of
  495. // LocalVideo.js the id is set to "local" but will get updated later.
  496. ReactDOM.render(
  497. <Provider store = { APP.store }>
  498. <AvatarDisplay
  499. className = 'userAvatar'
  500. participantId = { this.id } />
  501. </Provider>,
  502. thumbnail
  503. );
  504. }
  505. }
  506. /**
  507. * Unmounts any attached react components (particular the avatar image) from
  508. * the avatar container.
  509. *
  510. * @returns {void}
  511. */
  512. removeAvatar() {
  513. const thumbnail = this.$avatar().get(0);
  514. if (thumbnail) {
  515. ReactDOM.unmountComponentAtNode(thumbnail);
  516. }
  517. }
  518. /**
  519. * Shows or hides the dominant speaker indicator.
  520. * @param show whether to show or hide.
  521. */
  522. showDominantSpeakerIndicator(show) {
  523. // Don't create and show dominant speaker indicator if
  524. // DISABLE_DOMINANT_SPEAKER_INDICATOR is true
  525. if (interfaceConfig.DISABLE_DOMINANT_SPEAKER_INDICATOR) {
  526. return;
  527. }
  528. if (!this.container) {
  529. logger.warn(`Unable to set dominant speaker indicator - ${this.videoSpanId} does not exist`);
  530. return;
  531. }
  532. if (this._showDominantSpeaker === show) {
  533. return;
  534. }
  535. this._showDominantSpeaker = show;
  536. this.$container.toggleClass('active-speaker', this._showDominantSpeaker);
  537. this.updateIndicators();
  538. this.updateView();
  539. }
  540. /**
  541. * Shows or hides the raised hand indicator.
  542. * @param show whether to show or hide.
  543. */
  544. showRaisedHandIndicator(show) {
  545. if (!this.container) {
  546. logger.warn(`Unable to raised hand indication - ${
  547. this.videoSpanId} does not exist`);
  548. return;
  549. }
  550. this._showRaisedHand = show;
  551. this.updateIndicators();
  552. }
  553. /**
  554. * Initalizes any browser specific properties. Currently sets the overflow
  555. * property for Qt browsers on Windows to hidden, thus fixing the following
  556. * problem:
  557. * Some browsers don't have full support of the object-fit property for the
  558. * video element and when we set video object-fit to "cover" the video
  559. * actually overflows the boundaries of its container, so it's important
  560. * to indicate that the "overflow" should be hidden.
  561. *
  562. * Setting this property for all browsers will result in broken audio levels,
  563. * which makes this a temporary solution, before reworking audio levels.
  564. */
  565. initBrowserSpecificProperties() {
  566. const userAgent = window.navigator.userAgent;
  567. if (userAgent.indexOf('QtWebEngine') > -1
  568. && (userAgent.indexOf('Windows') > -1 || userAgent.indexOf('Linux') > -1)) {
  569. this.$container.css('overflow', 'hidden');
  570. }
  571. }
  572. /**
  573. * Cleans up components on {@code SmallVideo} and removes itself from the DOM.
  574. *
  575. * @returns {void}
  576. */
  577. remove() {
  578. logger.log('Remove thumbnail', this.id);
  579. this.removeAudioLevelIndicator();
  580. const toolbarContainer
  581. = this.container.querySelector('.videocontainer__toolbar');
  582. if (toolbarContainer) {
  583. ReactDOM.unmountComponentAtNode(toolbarContainer);
  584. }
  585. this.removeConnectionIndicator();
  586. this.removeDisplayName();
  587. this.removeAvatar();
  588. this._unmountIndicators();
  589. // Remove whole container
  590. if (this.container.parentNode) {
  591. this.container.parentNode.removeChild(this.container);
  592. }
  593. }
  594. /**
  595. * Helper function for re-rendering multiple react components of the small
  596. * video.
  597. *
  598. * @returns {void}
  599. */
  600. rerender() {
  601. this.updateIndicators();
  602. this.updateStatusBar();
  603. this.updateView();
  604. }
  605. /**
  606. * Updates the React element responsible for showing connection status, dominant
  607. * speaker, and raised hand icons. Uses instance variables to get the necessary
  608. * state to display. Will create the React element if not already created.
  609. *
  610. * @private
  611. * @returns {void}
  612. */
  613. updateIndicators() {
  614. const indicatorToolbar = this.container.querySelector('.videocontainer__toptoolbar');
  615. if (!indicatorToolbar) {
  616. return;
  617. }
  618. const { NORMAL = 8 } = interfaceConfig.INDICATOR_FONT_SIZES || {};
  619. const iconSize = NORMAL;
  620. const showConnectionIndicator = this.videoIsHovered || !interfaceConfig.CONNECTION_INDICATOR_AUTO_HIDE_ENABLED;
  621. const state = APP.store.getState();
  622. const currentLayout = getCurrentLayout(state);
  623. const participantCount = getParticipantCount(state);
  624. let statsPopoverPosition, tooltipPosition;
  625. if (currentLayout === LAYOUTS.TILE_VIEW) {
  626. statsPopoverPosition = 'right top';
  627. tooltipPosition = 'right';
  628. } else if (currentLayout === LAYOUTS.VERTICAL_FILMSTRIP_VIEW) {
  629. statsPopoverPosition = this.statsPopoverLocation;
  630. tooltipPosition = 'left';
  631. } else {
  632. statsPopoverPosition = this.statsPopoverLocation;
  633. tooltipPosition = 'top';
  634. }
  635. ReactDOM.render(
  636. <Provider store = { APP.store }>
  637. <I18nextProvider i18n = { i18next }>
  638. <div>
  639. <AtlasKitThemeProvider mode = 'dark'>
  640. { this._showConnectionIndicator
  641. ? <ConnectionIndicator
  642. alwaysVisible = { showConnectionIndicator }
  643. connectionStatus = { this._connectionStatus }
  644. iconSize = { iconSize }
  645. isLocalVideo = { this.isLocal }
  646. enableStatsDisplay = { !interfaceConfig.filmStripOnly }
  647. participantId = { this.id }
  648. statsPopoverPosition = { statsPopoverPosition } />
  649. : null }
  650. <RaisedHandIndicator
  651. iconSize = { iconSize }
  652. participantId = { this.id }
  653. tooltipPosition = { tooltipPosition } />
  654. { this._showDominantSpeaker && participantCount > 2
  655. ? <DominantSpeakerIndicator
  656. iconSize = { iconSize }
  657. tooltipPosition = { tooltipPosition } />
  658. : null }
  659. </AtlasKitThemeProvider>
  660. </div>
  661. </I18nextProvider>
  662. </Provider>,
  663. indicatorToolbar
  664. );
  665. }
  666. /**
  667. * Callback invoked when the thumbnail is clicked and potentially trigger
  668. * pinning of the participant.
  669. *
  670. * @param {MouseEvent} event - The click event to intercept.
  671. * @private
  672. * @returns {void}
  673. */
  674. _onContainerClick(event) {
  675. const triggerPin = this._shouldTriggerPin(event);
  676. if (event.stopPropagation && triggerPin) {
  677. event.stopPropagation();
  678. event.preventDefault();
  679. }
  680. if (triggerPin) {
  681. this.togglePin();
  682. }
  683. return false;
  684. }
  685. /**
  686. * Returns whether or not a click event is targeted at certain elements which
  687. * should not trigger a pin.
  688. *
  689. * @param {MouseEvent} event - The click event to intercept.
  690. * @private
  691. * @returns {boolean}
  692. */
  693. _shouldTriggerPin(event) {
  694. // TODO Checking the classes is a workround to allow events to bubble into
  695. // the DisplayName component if it was clicked. React's synthetic events
  696. // will fire after jQuery handlers execute, so stop propogation at this
  697. // point will prevent DisplayName from getting click events. This workaround
  698. // should be removeable once LocalVideo is a React Component because then
  699. // the components share the same eventing system.
  700. const $source = $(event.target || event.srcElement);
  701. return $source.parents('.displayNameContainer').length === 0
  702. && $source.parents('.popover').length === 0
  703. && !event.target.classList.contains('popover');
  704. }
  705. /**
  706. * Pins the participant displayed by this thumbnail or unpins if already pinned.
  707. *
  708. * @returns {void}
  709. */
  710. togglePin() {
  711. const pinnedParticipant = getPinnedParticipant(APP.store.getState()) || {};
  712. const participantIdToPin = pinnedParticipant && pinnedParticipant.id === this.id ? null : this.id;
  713. APP.store.dispatch(pinParticipant(participantIdToPin));
  714. }
  715. /**
  716. * Removes the React element responsible for showing connection status, dominant
  717. * speaker, and raised hand icons.
  718. *
  719. * @private
  720. * @returns {void}
  721. */
  722. _unmountIndicators() {
  723. const indicatorToolbar = this.container.querySelector('.videocontainer__toptoolbar');
  724. if (indicatorToolbar) {
  725. ReactDOM.unmountComponentAtNode(indicatorToolbar);
  726. }
  727. }
  728. /**
  729. * Sets the size of the thumbnail.
  730. */
  731. _setThumbnailSize() {
  732. const layout = getCurrentLayout(APP.store.getState());
  733. const heightToWidthPercent = 100
  734. / (this.isLocal ? interfaceConfig.LOCAL_THUMBNAIL_RATIO : interfaceConfig.REMOTE_THUMBNAIL_RATIO);
  735. switch (layout) {
  736. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW: {
  737. this.$container.css('padding-top', `${heightToWidthPercent}%`);
  738. this.$avatar().css({
  739. height: '50%',
  740. width: `${heightToWidthPercent / 2}%`
  741. });
  742. break;
  743. }
  744. case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW: {
  745. const state = APP.store.getState();
  746. const { local, remote } = state['features/filmstrip'].horizontalViewDimensions;
  747. const size = this.isLocal ? local : remote;
  748. if (typeof size !== 'undefined') {
  749. const { height, width } = size;
  750. const avatarSize = height / 2;
  751. this.$container.css({
  752. height: `${height}px`,
  753. 'min-height': `${height}px`,
  754. 'min-width': `${width}px`,
  755. width: `${width}px`
  756. });
  757. this.$avatar().css({
  758. height: `${avatarSize}px`,
  759. width: `${avatarSize}px`
  760. });
  761. }
  762. break;
  763. }
  764. case LAYOUTS.TILE_VIEW: {
  765. const state = APP.store.getState();
  766. const { thumbnailSize } = state['features/filmstrip'].tileViewDimensions;
  767. if (typeof thumbnailSize !== 'undefined') {
  768. const { height, width } = thumbnailSize;
  769. const avatarSize = height / 2;
  770. this.$container.css({
  771. height: `${height}px`,
  772. 'min-height': `${height}px`,
  773. 'min-width': `${width}px`,
  774. width: `${width}px`
  775. });
  776. this.$avatar().css({
  777. height: `${avatarSize}px`,
  778. width: `${avatarSize}px`
  779. });
  780. }
  781. break;
  782. }
  783. }
  784. }
  785. }