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 31KB

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