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

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