Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SmallVideo.js 28KB

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