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

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