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

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