You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SmallVideo.js 28KB

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