Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

SmallVideo.js 26KB

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