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 31KB

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