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

SmallVideo.js 29KB

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