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

SmallVideo.js 29KB

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