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 28KB

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