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

SmallVideo.js 30KB

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