您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SmallVideo.js 26KB

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