Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

SmallVideo.js 32KB

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