您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SmallVideo.js 29KB

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