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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  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 && !APP.conference.isAudioOnly();
  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(input) {
  458. // Display name is always and only displayed when user is on the stage
  459. if (input.isCurrentlyOnLargeVideo && !input.tileViewEnabled) {
  460. return input.isVideoPlayable && !input.isAudioOnly ? DISPLAY_BLACKNESS_WITH_NAME : DISPLAY_AVATAR_WITH_NAME;
  461. } else if (input.isVideoPlayable && input.hasVideo && !input.isAudioOnly) {
  462. // check hovering and change state to video with name
  463. return input.isHovered ? DISPLAY_VIDEO_WITH_NAME : DISPLAY_VIDEO;
  464. }
  465. // check hovering and change state to avatar with name
  466. return input.isHovered ? DISPLAY_AVATAR_WITH_NAME : DISPLAY_AVATAR;
  467. };
  468. /**
  469. * Computes information that determine the display mode.
  470. *
  471. * @returns {Object}
  472. */
  473. SmallVideo.prototype.computeDisplayModeInput = function() {
  474. return {
  475. isCurrentlyOnLargeVideo: this.isCurrentlyOnLargeVideo(),
  476. isHovered: this._isHovered(),
  477. isAudioOnly: APP.conference.isAudioOnly(),
  478. tileViewEnabled: shouldDisplayTileView(APP.store.getState()),
  479. isVideoPlayable: this.isVideoPlayable(),
  480. hasVideo: Boolean(this.selectVideoElement().length),
  481. connectionStatus: APP.conference.getParticipantConnectionStatus(this.id),
  482. mutedWhileDisconnected: this.mutedWhileDisconnected,
  483. wasVideoPlayed: this.wasVideoPlayed,
  484. videoStream: Boolean(this.videoStream),
  485. isVideoMuted: this.isVideoMuted,
  486. videoStreamMuted: this.videoStream ? this.videoStream.isMuted() : 'no stream'
  487. };
  488. };
  489. /**
  490. * Checks whether current video is considered hovered. Currently it is hovered
  491. * if the mouse is over the video, or if the connection
  492. * indicator is shown(hovered).
  493. * @private
  494. */
  495. SmallVideo.prototype._isHovered = function() {
  496. return this.videoIsHovered || this._popoverIsHovered;
  497. };
  498. /**
  499. * Hides or shows the user's avatar.
  500. * This update assumes that large video had been updated and we will
  501. * reflect it on this small video.
  502. */
  503. SmallVideo.prototype.updateView = function() {
  504. if (this.id) {
  505. // Init / refresh avatar
  506. this.initializeAvatar();
  507. } else {
  508. logger.error('Unable to init avatar - no id', this);
  509. return;
  510. }
  511. this.$container.removeClass((index, classNames) =>
  512. classNames.split(' ').filter(name => name.startsWith('display-')));
  513. const oldDisplayMode = this.displayMode;
  514. let displayModeString = '';
  515. const displayModeInput = this.computeDisplayModeInput();
  516. // Determine whether video, avatar or blackness should be displayed
  517. this.displayMode = this.selectDisplayMode(displayModeInput);
  518. switch (this.displayMode) {
  519. case DISPLAY_AVATAR_WITH_NAME:
  520. displayModeString = 'avatar-with-name';
  521. this.$container.addClass('display-avatar-with-name');
  522. break;
  523. case DISPLAY_BLACKNESS_WITH_NAME:
  524. displayModeString = 'blackness-with-name';
  525. this.$container.addClass('display-name-on-black');
  526. break;
  527. case DISPLAY_VIDEO:
  528. displayModeString = 'video';
  529. this.$container.addClass('display-video');
  530. break;
  531. case DISPLAY_VIDEO_WITH_NAME:
  532. displayModeString = 'video-with-name';
  533. this.$container.addClass('display-name-on-video');
  534. break;
  535. case DISPLAY_AVATAR:
  536. default:
  537. displayModeString = 'avatar';
  538. this.$container.addClass('display-avatar-only');
  539. break;
  540. }
  541. if (this.displayMode !== oldDisplayMode) {
  542. logger.debug(`Displaying ${displayModeString} for ${this.id}, data: [${JSON.stringify(displayModeInput)}]`);
  543. }
  544. };
  545. /**
  546. * Updates the react component displaying the avatar with the passed in avatar
  547. * url.
  548. *
  549. * @returns {void}
  550. */
  551. SmallVideo.prototype.initializeAvatar = function() {
  552. const thumbnail = this.$avatar().get(0);
  553. this.hasAvatar = true;
  554. if (thumbnail) {
  555. // Maybe add a special case for local participant, as on init of
  556. // LocalVideo.js the id is set to "local" but will get updated later.
  557. ReactDOM.render(
  558. <Provider store = { APP.store }>
  559. <AvatarDisplay
  560. className = 'userAvatar'
  561. participantId = { this.id }
  562. size = { this.$avatar().width() } />
  563. </Provider>,
  564. thumbnail
  565. );
  566. }
  567. };
  568. /**
  569. * Unmounts any attached react components (particular the avatar image) from
  570. * the avatar container.
  571. *
  572. * @returns {void}
  573. */
  574. SmallVideo.prototype.removeAvatar = function() {
  575. const thumbnail = this.$avatar().get(0);
  576. if (thumbnail) {
  577. ReactDOM.unmountComponentAtNode(thumbnail);
  578. }
  579. };
  580. /**
  581. * Shows or hides the dominant speaker indicator.
  582. * @param show whether to show or hide.
  583. */
  584. SmallVideo.prototype.showDominantSpeakerIndicator = function(show) {
  585. // Don't create and show dominant speaker indicator if
  586. // DISABLE_DOMINANT_SPEAKER_INDICATOR is true
  587. if (interfaceConfig.DISABLE_DOMINANT_SPEAKER_INDICATOR) {
  588. return;
  589. }
  590. if (!this.container) {
  591. logger.warn(`Unable to set dominant speaker indicator - ${
  592. this.videoSpanId} does not exist`);
  593. return;
  594. }
  595. if (this._showDominantSpeaker === show) {
  596. return;
  597. }
  598. this._showDominantSpeaker = show;
  599. this.$container.toggleClass('active-speaker', this._showDominantSpeaker);
  600. this.updateIndicators();
  601. this.updateView();
  602. };
  603. /**
  604. * Shows or hides the raised hand indicator.
  605. * @param show whether to show or hide.
  606. */
  607. SmallVideo.prototype.showRaisedHandIndicator = function(show) {
  608. if (!this.container) {
  609. logger.warn(`Unable to raised hand indication - ${
  610. this.videoSpanId} does not exist`);
  611. return;
  612. }
  613. this._showRaisedHand = show;
  614. this.updateIndicators();
  615. };
  616. /**
  617. * Adds a listener for onresize events for this video, which will monitor for
  618. * resolution changes, will calculate the delay since the moment the listened
  619. * is added, and will fire a RESOLUTION_CHANGED event.
  620. */
  621. SmallVideo.prototype.waitForResolutionChange = function() {
  622. const beforeChange = window.performance.now();
  623. const videos = this.selectVideoElement();
  624. if (!videos || !videos.length || videos.length <= 0) {
  625. return;
  626. }
  627. const video = videos[0];
  628. const oldWidth = video.videoWidth;
  629. const oldHeight = video.videoHeight;
  630. video.onresize = () => {
  631. // eslint-disable-next-line eqeqeq
  632. if (video.videoWidth != oldWidth || video.videoHeight != oldHeight) {
  633. // Only run once.
  634. video.onresize = null;
  635. const delay = window.performance.now() - beforeChange;
  636. const emitter = this.VideoLayout.getEventEmitter();
  637. if (emitter) {
  638. emitter.emit(
  639. UIEvents.RESOLUTION_CHANGED,
  640. this.getId(),
  641. `${oldWidth}x${oldHeight}`,
  642. `${video.videoWidth}x${video.videoHeight}`,
  643. delay);
  644. }
  645. }
  646. };
  647. };
  648. /**
  649. * Initalizes any browser specific properties. Currently sets the overflow
  650. * property for Qt browsers on Windows to hidden, thus fixing the following
  651. * problem:
  652. * Some browsers don't have full support of the object-fit property for the
  653. * video element and when we set video object-fit to "cover" the video
  654. * actually overflows the boundaries of its container, so it's important
  655. * to indicate that the "overflow" should be hidden.
  656. *
  657. * Setting this property for all browsers will result in broken audio levels,
  658. * which makes this a temporary solution, before reworking audio levels.
  659. */
  660. SmallVideo.prototype.initBrowserSpecificProperties = function() {
  661. const userAgent = window.navigator.userAgent;
  662. if (userAgent.indexOf('QtWebEngine') > -1
  663. && (userAgent.indexOf('Windows') > -1
  664. || userAgent.indexOf('Linux') > -1)) {
  665. this.$container.css('overflow', 'hidden');
  666. }
  667. };
  668. /**
  669. * Cleans up components on {@code SmallVideo} and removes itself from the DOM.
  670. *
  671. * @returns {void}
  672. */
  673. SmallVideo.prototype.remove = function() {
  674. logger.log('Remove thumbnail', this.id);
  675. this.removeAudioLevelIndicator();
  676. const toolbarContainer
  677. = this.container.querySelector('.videocontainer__toolbar');
  678. if (toolbarContainer) {
  679. ReactDOM.unmountComponentAtNode(toolbarContainer);
  680. }
  681. this.removeConnectionIndicator();
  682. this.removeDisplayName();
  683. this.removeAvatar();
  684. this._unmountIndicators();
  685. // Remove whole container
  686. if (this.container.parentNode) {
  687. this.container.parentNode.removeChild(this.container);
  688. }
  689. };
  690. /**
  691. * Helper function for re-rendering multiple react components of the small
  692. * video.
  693. *
  694. * @returns {void}
  695. */
  696. SmallVideo.prototype.rerender = function() {
  697. this.updateIndicators();
  698. this.updateStatusBar();
  699. this.updateView();
  700. };
  701. /**
  702. * Updates the React element responsible for showing connection status, dominant
  703. * speaker, and raised hand icons. Uses instance variables to get the necessary
  704. * state to display. Will create the React element if not already created.
  705. *
  706. * @private
  707. * @returns {void}
  708. */
  709. SmallVideo.prototype.updateIndicators = function() {
  710. const indicatorToolbar
  711. = this.container.querySelector('.videocontainer__toptoolbar');
  712. if (!indicatorToolbar) {
  713. return;
  714. }
  715. const iconSize = UIUtil.getIndicatorFontSize();
  716. const showConnectionIndicator = this.videoIsHovered
  717. || !interfaceConfig.CONNECTION_INDICATOR_AUTO_HIDE_ENABLED;
  718. const state = APP.store.getState();
  719. const currentLayout = getCurrentLayout(state);
  720. const participantCount = getParticipantCount(state);
  721. let statsPopoverPosition, tooltipPosition;
  722. if (currentLayout === LAYOUTS.TILE_VIEW) {
  723. statsPopoverPosition = 'right top';
  724. tooltipPosition = 'right';
  725. } else if (currentLayout === LAYOUTS.VERTICAL_FILMSTRIP_VIEW) {
  726. statsPopoverPosition = this.statsPopoverLocation;
  727. tooltipPosition = 'left';
  728. } else {
  729. statsPopoverPosition = this.statsPopoverLocation;
  730. tooltipPosition = 'top';
  731. }
  732. ReactDOM.render(
  733. <Provider store = { APP.store }>
  734. <I18nextProvider i18n = { i18next }>
  735. <div>
  736. <AtlasKitThemeProvider mode = 'dark'>
  737. { this._showConnectionIndicator
  738. ? <ConnectionIndicator
  739. alwaysVisible = { showConnectionIndicator }
  740. connectionStatus = { this._connectionStatus }
  741. iconSize = { iconSize }
  742. isLocalVideo = { this.isLocal }
  743. enableStatsDisplay
  744. = { !interfaceConfig.filmStripOnly }
  745. participantId = { this.id }
  746. statsPopoverPosition
  747. = { statsPopoverPosition } />
  748. : null }
  749. <RaisedHandIndicator
  750. iconSize = { iconSize }
  751. participantId = { this.id }
  752. tooltipPosition = { tooltipPosition } />
  753. { this._showDominantSpeaker && participantCount > 2
  754. ? <DominantSpeakerIndicator
  755. iconSize = { iconSize }
  756. tooltipPosition = { tooltipPosition } />
  757. : null }
  758. </AtlasKitThemeProvider>
  759. </div>
  760. </I18nextProvider>
  761. </Provider>,
  762. indicatorToolbar
  763. );
  764. };
  765. /**
  766. * Callback invoked when the thumbnail is clicked and potentially trigger
  767. * pinning of the participant.
  768. *
  769. * @param {MouseEvent} event - The click event to intercept.
  770. * @private
  771. * @returns {void}
  772. */
  773. SmallVideo.prototype._onContainerClick = function(event) {
  774. const triggerPin = this._shouldTriggerPin(event);
  775. if (event.stopPropagation && triggerPin) {
  776. event.stopPropagation();
  777. event.preventDefault();
  778. }
  779. if (triggerPin) {
  780. this.togglePin();
  781. }
  782. return false;
  783. };
  784. /**
  785. * Returns whether or not a click event is targeted at certain elements which
  786. * should not trigger a pin.
  787. *
  788. * @param {MouseEvent} event - The click event to intercept.
  789. * @private
  790. * @returns {boolean}
  791. */
  792. SmallVideo.prototype._shouldTriggerPin = function(event) {
  793. // TODO Checking the classes is a workround to allow events to bubble into
  794. // the DisplayName component if it was clicked. React's synthetic events
  795. // will fire after jQuery handlers execute, so stop propogation at this
  796. // point will prevent DisplayName from getting click events. This workaround
  797. // should be removeable once LocalVideo is a React Component because then
  798. // the components share the same eventing system.
  799. const $source = $(event.target || event.srcElement);
  800. return $source.parents('.displayNameContainer').length === 0
  801. && $source.parents('.popover').length === 0
  802. && !event.target.classList.contains('popover');
  803. };
  804. /**
  805. * Pins the participant displayed by this thumbnail or unpins if already pinned.
  806. *
  807. * @returns {void}
  808. */
  809. SmallVideo.prototype.togglePin = function() {
  810. const pinnedParticipant
  811. = getPinnedParticipant(APP.store.getState()) || {};
  812. const participantIdToPin
  813. = pinnedParticipant && pinnedParticipant.id === this.id
  814. ? null : this.id;
  815. APP.store.dispatch(pinParticipant(participantIdToPin));
  816. };
  817. /**
  818. * Removes the React element responsible for showing connection status, dominant
  819. * speaker, and raised hand icons.
  820. *
  821. * @private
  822. * @returns {void}
  823. */
  824. SmallVideo.prototype._unmountIndicators = function() {
  825. const indicatorToolbar
  826. = this.container.querySelector('.videocontainer__toptoolbar');
  827. if (indicatorToolbar) {
  828. ReactDOM.unmountComponentAtNode(indicatorToolbar);
  829. }
  830. };
  831. /**
  832. * Updates the current state of the connection indicator popover being hovered.
  833. * If hovered, display the small video as if it is hovered.
  834. *
  835. * @param {boolean} popoverIsHovered - Whether or not the mouse cursor is
  836. * currently over the connection indicator popover.
  837. * @returns {void}
  838. */
  839. SmallVideo.prototype._onPopoverHover = function(popoverIsHovered) {
  840. this._popoverIsHovered = popoverIsHovered;
  841. this.updateView();
  842. };
  843. export default SmallVideo;