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

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