Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SmallVideo.js 29KB

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