Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SmallVideo.js 29KB

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