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

SmallVideo.js 29KB

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