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

SmallVideo.js 29KB

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