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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  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. mutedWhileDisconnected: this.mutedWhileDisconnected,
  401. canPlayEventReceived: this._canPlayEventReceived,
  402. videoStream: Boolean(this.videoStream),
  403. isScreenSharing,
  404. videoStreamMuted: this.videoStream ? this.videoStream.isMuted() : 'no stream'
  405. };
  406. }
  407. /**
  408. * Checks whether current video is considered hovered. Currently it is hovered
  409. * if the mouse is over the video, or if the connection
  410. * indicator is shown(hovered).
  411. * @private
  412. */
  413. _isHovered() {
  414. return this.videoIsHovered;
  415. }
  416. /**
  417. * Updates the css classes of the thumbnail based on the current state.
  418. */
  419. updateView() {
  420. this.$container.removeClass((index, classNames) =>
  421. classNames.split(' ').filter(name => name.startsWith('display-')));
  422. const oldDisplayMode = this.displayMode;
  423. let displayModeString = '';
  424. const displayModeInput = this.computeDisplayModeInput();
  425. // Determine whether video, avatar or blackness should be displayed
  426. this.displayMode = this.selectDisplayMode(displayModeInput);
  427. switch (this.displayMode) {
  428. case DISPLAY_AVATAR_WITH_NAME:
  429. displayModeString = 'avatar-with-name';
  430. this.$container.addClass('display-avatar-with-name');
  431. break;
  432. case DISPLAY_BLACKNESS_WITH_NAME:
  433. displayModeString = 'blackness-with-name';
  434. this.$container.addClass('display-name-on-black');
  435. break;
  436. case DISPLAY_VIDEO:
  437. displayModeString = 'video';
  438. this.$container.addClass('display-video');
  439. break;
  440. case DISPLAY_VIDEO_WITH_NAME:
  441. displayModeString = 'video-with-name';
  442. this.$container.addClass('display-name-on-video');
  443. break;
  444. case DISPLAY_AVATAR:
  445. default:
  446. displayModeString = 'avatar';
  447. this.$container.addClass('display-avatar-only');
  448. break;
  449. }
  450. if (this.displayMode !== oldDisplayMode) {
  451. logger.debug(`Displaying ${displayModeString} for ${this.id}, data: [${JSON.stringify(displayModeInput)}]`);
  452. }
  453. }
  454. /**
  455. * Updates the react component displaying the avatar with the passed in avatar
  456. * url.
  457. *
  458. * @returns {void}
  459. */
  460. initializeAvatar() {
  461. const thumbnail = this.$avatar().get(0);
  462. if (thumbnail) {
  463. // Maybe add a special case for local participant, as on init of
  464. // LocalVideo.js the id is set to "local" but will get updated later.
  465. ReactDOM.render(
  466. <Provider store = { APP.store }>
  467. <AvatarDisplay
  468. className = 'userAvatar'
  469. participantId = { this.id } />
  470. </Provider>,
  471. thumbnail
  472. );
  473. }
  474. }
  475. /**
  476. * Unmounts any attached react components (particular the avatar image) from
  477. * the avatar container.
  478. *
  479. * @returns {void}
  480. */
  481. removeAvatar() {
  482. const thumbnail = this.$avatar().get(0);
  483. if (thumbnail) {
  484. ReactDOM.unmountComponentAtNode(thumbnail);
  485. }
  486. }
  487. /**
  488. * Shows or hides the dominant speaker indicator.
  489. * @param show whether to show or hide.
  490. */
  491. showDominantSpeakerIndicator(show) {
  492. // Don't create and show dominant speaker indicator if
  493. // DISABLE_DOMINANT_SPEAKER_INDICATOR is true
  494. if (interfaceConfig.DISABLE_DOMINANT_SPEAKER_INDICATOR) {
  495. return;
  496. }
  497. if (!this.container) {
  498. logger.warn(`Unable to set dominant speaker indicator - ${this.videoSpanId} does not exist`);
  499. return;
  500. }
  501. if (this._showDominantSpeaker === show) {
  502. return;
  503. }
  504. this._showDominantSpeaker = show;
  505. this.$container.toggleClass('active-speaker', this._showDominantSpeaker);
  506. this.updateIndicators();
  507. this.updateView();
  508. }
  509. /**
  510. * Shows or hides the raised hand indicator.
  511. * @param show whether to show or hide.
  512. */
  513. showRaisedHandIndicator(show) {
  514. if (!this.container) {
  515. logger.warn(`Unable to raised hand indication - ${
  516. this.videoSpanId} does not exist`);
  517. return;
  518. }
  519. this._showRaisedHand = show;
  520. this.updateIndicators();
  521. }
  522. /**
  523. * Initalizes any browser specific properties. Currently sets the overflow
  524. * property for Qt browsers on Windows to hidden, thus fixing the following
  525. * problem:
  526. * Some browsers don't have full support of the object-fit property for the
  527. * video element and when we set video object-fit to "cover" the video
  528. * actually overflows the boundaries of its container, so it's important
  529. * to indicate that the "overflow" should be hidden.
  530. *
  531. * Setting this property for all browsers will result in broken audio levels,
  532. * which makes this a temporary solution, before reworking audio levels.
  533. */
  534. initBrowserSpecificProperties() {
  535. const userAgent = window.navigator.userAgent;
  536. if (userAgent.indexOf('QtWebEngine') > -1
  537. && (userAgent.indexOf('Windows') > -1 || userAgent.indexOf('Linux') > -1)) {
  538. this.$container.css('overflow', 'hidden');
  539. }
  540. }
  541. /**
  542. * Cleans up components on {@code SmallVideo} and removes itself from the DOM.
  543. *
  544. * @returns {void}
  545. */
  546. remove() {
  547. logger.log('Remove thumbnail', this.id);
  548. this.removeAudioLevelIndicator();
  549. const toolbarContainer
  550. = this.container.querySelector('.videocontainer__toolbar');
  551. if (toolbarContainer) {
  552. ReactDOM.unmountComponentAtNode(toolbarContainer);
  553. }
  554. this.removeConnectionIndicator();
  555. this.removeDisplayName();
  556. this.removeAvatar();
  557. this._unmountIndicators();
  558. // Remove whole container
  559. if (this.container.parentNode) {
  560. this.container.parentNode.removeChild(this.container);
  561. }
  562. }
  563. /**
  564. * Helper function for re-rendering multiple react components of the small
  565. * video.
  566. *
  567. * @returns {void}
  568. */
  569. rerender() {
  570. this.updateIndicators();
  571. this.updateStatusBar();
  572. this.updateView();
  573. }
  574. /**
  575. * Updates the React element responsible for showing connection status, dominant
  576. * speaker, and raised hand icons. Uses instance variables to get the necessary
  577. * state to display. Will create the React element if not already created.
  578. *
  579. * @private
  580. * @returns {void}
  581. */
  582. updateIndicators() {
  583. const indicatorToolbar = this.container.querySelector('.videocontainer__toptoolbar');
  584. if (!indicatorToolbar) {
  585. return;
  586. }
  587. const { NORMAL = 8 } = interfaceConfig.INDICATOR_FONT_SIZES || {};
  588. const iconSize = NORMAL;
  589. const showConnectionIndicator = this.videoIsHovered || !interfaceConfig.CONNECTION_INDICATOR_AUTO_HIDE_ENABLED;
  590. const state = APP.store.getState();
  591. const currentLayout = getCurrentLayout(state);
  592. const participantCount = getParticipantCount(state);
  593. let statsPopoverPosition, tooltipPosition;
  594. if (currentLayout === LAYOUTS.TILE_VIEW) {
  595. statsPopoverPosition = 'right top';
  596. tooltipPosition = 'right';
  597. } else if (currentLayout === LAYOUTS.VERTICAL_FILMSTRIP_VIEW) {
  598. statsPopoverPosition = this.statsPopoverLocation;
  599. tooltipPosition = 'left';
  600. } else {
  601. statsPopoverPosition = this.statsPopoverLocation;
  602. tooltipPosition = 'top';
  603. }
  604. ReactDOM.render(
  605. <Provider store = { APP.store }>
  606. <I18nextProvider i18n = { i18next }>
  607. <div>
  608. <AtlasKitThemeProvider mode = 'dark'>
  609. { this._showConnectionIndicator
  610. ? <ConnectionIndicator
  611. alwaysVisible = { showConnectionIndicator }
  612. iconSize = { iconSize }
  613. isLocalVideo = { this.isLocal }
  614. enableStatsDisplay = { !interfaceConfig.filmStripOnly }
  615. participantId = { this.id }
  616. statsPopoverPosition = { statsPopoverPosition } />
  617. : null }
  618. <RaisedHandIndicator
  619. iconSize = { iconSize }
  620. participantId = { this.id }
  621. tooltipPosition = { tooltipPosition } />
  622. { this._showDominantSpeaker && participantCount > 2
  623. ? <DominantSpeakerIndicator
  624. iconSize = { iconSize }
  625. tooltipPosition = { tooltipPosition } />
  626. : null }
  627. </AtlasKitThemeProvider>
  628. </div>
  629. </I18nextProvider>
  630. </Provider>,
  631. indicatorToolbar
  632. );
  633. }
  634. /**
  635. * Callback invoked when the thumbnail is clicked and potentially trigger
  636. * pinning of the participant.
  637. *
  638. * @param {MouseEvent} event - The click event to intercept.
  639. * @private
  640. * @returns {void}
  641. */
  642. _onContainerClick(event) {
  643. const triggerPin = this._shouldTriggerPin(event);
  644. if (event.stopPropagation && triggerPin) {
  645. event.stopPropagation();
  646. event.preventDefault();
  647. }
  648. if (triggerPin) {
  649. this.togglePin();
  650. }
  651. return false;
  652. }
  653. /**
  654. * Returns whether or not a click event is targeted at certain elements which
  655. * should not trigger a pin.
  656. *
  657. * @param {MouseEvent} event - The click event to intercept.
  658. * @private
  659. * @returns {boolean}
  660. */
  661. _shouldTriggerPin(event) {
  662. // TODO Checking the classes is a workround to allow events to bubble into
  663. // the DisplayName component if it was clicked. React's synthetic events
  664. // will fire after jQuery handlers execute, so stop propogation at this
  665. // point will prevent DisplayName from getting click events. This workaround
  666. // should be removeable once LocalVideo is a React Component because then
  667. // the components share the same eventing system.
  668. const $source = $(event.target || event.srcElement);
  669. return $source.parents('.displayNameContainer').length === 0
  670. && $source.parents('.popover').length === 0
  671. && !event.target.classList.contains('popover');
  672. }
  673. /**
  674. * Pins the participant displayed by this thumbnail or unpins if already pinned.
  675. *
  676. * @returns {void}
  677. */
  678. togglePin() {
  679. const pinnedParticipant = getPinnedParticipant(APP.store.getState()) || {};
  680. const participantIdToPin = pinnedParticipant && pinnedParticipant.id === this.id ? null : this.id;
  681. APP.store.dispatch(pinParticipant(participantIdToPin));
  682. }
  683. /**
  684. * Removes the React element responsible for showing connection status, dominant
  685. * speaker, and raised hand icons.
  686. *
  687. * @private
  688. * @returns {void}
  689. */
  690. _unmountIndicators() {
  691. const indicatorToolbar = this.container.querySelector('.videocontainer__toptoolbar');
  692. if (indicatorToolbar) {
  693. ReactDOM.unmountComponentAtNode(indicatorToolbar);
  694. }
  695. }
  696. /**
  697. * Sets the size of the thumbnail.
  698. */
  699. _setThumbnailSize() {
  700. const layout = getCurrentLayout(APP.store.getState());
  701. const heightToWidthPercent = 100
  702. / (this.isLocal ? interfaceConfig.LOCAL_THUMBNAIL_RATIO : interfaceConfig.REMOTE_THUMBNAIL_RATIO);
  703. switch (layout) {
  704. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW: {
  705. this.$container.css('padding-top', `${heightToWidthPercent}%`);
  706. this.$avatar().css({
  707. height: '50%',
  708. width: `${heightToWidthPercent / 2}%`
  709. });
  710. break;
  711. }
  712. case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW: {
  713. const state = APP.store.getState();
  714. const { local, remote } = state['features/filmstrip'].horizontalViewDimensions;
  715. const size = this.isLocal ? local : remote;
  716. if (typeof size !== 'undefined') {
  717. const { height, width } = size;
  718. const avatarSize = height / 2;
  719. this.$container.css({
  720. height: `${height}px`,
  721. 'min-height': `${height}px`,
  722. 'min-width': `${width}px`,
  723. width: `${width}px`
  724. });
  725. this.$avatar().css({
  726. height: `${avatarSize}px`,
  727. width: `${avatarSize}px`
  728. });
  729. }
  730. break;
  731. }
  732. case LAYOUTS.TILE_VIEW: {
  733. const state = APP.store.getState();
  734. const { thumbnailSize } = state['features/filmstrip'].tileViewDimensions;
  735. if (typeof thumbnailSize !== 'undefined') {
  736. const { height, width } = thumbnailSize;
  737. const avatarSize = height / 2;
  738. this.$container.css({
  739. height: `${height}px`,
  740. 'min-height': `${height}px`,
  741. 'min-width': `${width}px`,
  742. width: `${width}px`
  743. });
  744. this.$avatar().css({
  745. height: `${avatarSize}px`,
  746. width: `${avatarSize}px`
  747. });
  748. }
  749. break;
  750. }
  751. }
  752. }
  753. }