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

SmallVideo.js 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  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.hasAvatar = false;
  76. this.isVideoMuted = false;
  77. this.videoStream = null;
  78. this.audioStream = null;
  79. this.VideoLayout = VideoLayout;
  80. this.videoIsHovered = false;
  81. /**
  82. * The current state of the user's bridge connection. The value should be
  83. * a string as enumerated in the library's participantConnectionStatus
  84. * constants.
  85. *
  86. * @private
  87. * @type {string|null}
  88. */
  89. this._connectionStatus = null;
  90. /**
  91. * Whether or not the ConnectionIndicator's popover is hovered. Modifies
  92. * how the video overlays display based on hover state.
  93. *
  94. * @private
  95. * @type {boolean}
  96. */
  97. this._popoverIsHovered = false;
  98. /**
  99. * Whether or not the connection indicator should be displayed.
  100. *
  101. * @private
  102. * @type {boolean}
  103. */
  104. this._showConnectionIndicator = !interfaceConfig.CONNECTION_INDICATOR_DISABLED;
  105. /**
  106. * Whether or not the dominant speaker indicator should be displayed.
  107. *
  108. * @private
  109. * @type {boolean}
  110. */
  111. this._showDominantSpeaker = false;
  112. /**
  113. * Whether or not the raised hand indicator should be displayed.
  114. *
  115. * @private
  116. * @type {boolean}
  117. */
  118. this._showRaisedHand = false;
  119. // Bind event handlers so they are only bound once for every instance.
  120. this._onPopoverHover = this._onPopoverHover.bind(this);
  121. this.updateView = this.updateView.bind(this);
  122. this._onContainerClick = this._onContainerClick.bind(this);
  123. }
  124. /**
  125. * Returns the identifier of this small video.
  126. *
  127. * @returns the identifier of this small video
  128. */
  129. getId() {
  130. return this.id;
  131. }
  132. /**
  133. * Indicates if this small video is currently visible.
  134. *
  135. * @return <tt>true</tt> if this small video isn't currently visible and
  136. * <tt>false</tt> - otherwise.
  137. */
  138. isVisible() {
  139. return this.$container.is(':visible');
  140. }
  141. /**
  142. * Sets the type of the video displayed by this instance.
  143. * Note that this is a string without clearly defined or checked values, and
  144. * it is NOT one of the strings defined in service/RTC/VideoType in
  145. * lib-jitsi-meet.
  146. * @param videoType 'camera' or 'desktop', or 'sharedvideo'.
  147. */
  148. setVideoType(videoType) {
  149. this.videoType = videoType;
  150. }
  151. /**
  152. * Returns the type of the video displayed by this instance.
  153. * Note that this is a string without clearly defined or checked values, and
  154. * it is NOT one of the strings defined in service/RTC/VideoType in
  155. * lib-jitsi-meet.
  156. * @returns {String} 'camera', 'screen', 'sharedvideo', or undefined.
  157. */
  158. getVideoType() {
  159. return this.videoType;
  160. }
  161. /**
  162. * Creates an audio or video element for a particular MediaStream.
  163. */
  164. static createStreamElement(stream) {
  165. const isVideo = stream.isVideoTrack();
  166. const element = isVideo ? document.createElement('video') : document.createElement('audio');
  167. if (isVideo) {
  168. element.setAttribute('muted', 'true');
  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. * Hides or shows the user's avatar.
  460. * This update assumes that large video had been updated and we will
  461. * reflect it on this small video.
  462. */
  463. updateView() {
  464. if (this.id) {
  465. // Init / refresh avatar
  466. this.initializeAvatar();
  467. } else {
  468. logger.error('Unable to init avatar - no id', this);
  469. return;
  470. }
  471. this.$container.removeClass((index, classNames) =>
  472. classNames.split(' ').filter(name => name.startsWith('display-')));
  473. const oldDisplayMode = this.displayMode;
  474. let displayModeString = '';
  475. const displayModeInput = this.computeDisplayModeInput();
  476. // Determine whether video, avatar or blackness should be displayed
  477. this.displayMode = this.selectDisplayMode(displayModeInput);
  478. switch (this.displayMode) {
  479. case DISPLAY_AVATAR_WITH_NAME:
  480. displayModeString = 'avatar-with-name';
  481. this.$container.addClass('display-avatar-with-name');
  482. break;
  483. case DISPLAY_BLACKNESS_WITH_NAME:
  484. displayModeString = 'blackness-with-name';
  485. this.$container.addClass('display-name-on-black');
  486. break;
  487. case DISPLAY_VIDEO:
  488. displayModeString = 'video';
  489. this.$container.addClass('display-video');
  490. break;
  491. case DISPLAY_VIDEO_WITH_NAME:
  492. displayModeString = 'video-with-name';
  493. this.$container.addClass('display-name-on-video');
  494. break;
  495. case DISPLAY_AVATAR:
  496. default:
  497. displayModeString = 'avatar';
  498. this.$container.addClass('display-avatar-only');
  499. break;
  500. }
  501. if (this.displayMode !== oldDisplayMode) {
  502. logger.debug(`Displaying ${displayModeString} for ${this.id}, data: [${JSON.stringify(displayModeInput)}]`);
  503. }
  504. }
  505. /**
  506. * Updates the react component displaying the avatar with the passed in avatar
  507. * url.
  508. *
  509. * @returns {void}
  510. */
  511. initializeAvatar() {
  512. const thumbnail = this.$avatar().get(0);
  513. this.hasAvatar = true;
  514. if (thumbnail) {
  515. // Maybe add a special case for local participant, as on init of
  516. // LocalVideo.js the id is set to "local" but will get updated later.
  517. ReactDOM.render(
  518. <Provider store = { APP.store }>
  519. <AvatarDisplay
  520. className = 'userAvatar'
  521. participantId = { this.id } />
  522. </Provider>,
  523. thumbnail
  524. );
  525. }
  526. }
  527. /**
  528. * Unmounts any attached react components (particular the avatar image) from
  529. * the avatar container.
  530. *
  531. * @returns {void}
  532. */
  533. removeAvatar() {
  534. const thumbnail = this.$avatar().get(0);
  535. if (thumbnail) {
  536. ReactDOM.unmountComponentAtNode(thumbnail);
  537. }
  538. }
  539. /**
  540. * Shows or hides the dominant speaker indicator.
  541. * @param show whether to show or hide.
  542. */
  543. showDominantSpeakerIndicator(show) {
  544. // Don't create and show dominant speaker indicator if
  545. // DISABLE_DOMINANT_SPEAKER_INDICATOR is true
  546. if (interfaceConfig.DISABLE_DOMINANT_SPEAKER_INDICATOR) {
  547. return;
  548. }
  549. if (!this.container) {
  550. logger.warn(`Unable to set dominant speaker indicator - ${this.videoSpanId} does not exist`);
  551. return;
  552. }
  553. if (this._showDominantSpeaker === show) {
  554. return;
  555. }
  556. this._showDominantSpeaker = show;
  557. this.$container.toggleClass('active-speaker', this._showDominantSpeaker);
  558. this.updateIndicators();
  559. this.updateView();
  560. }
  561. /**
  562. * Shows or hides the raised hand indicator.
  563. * @param show whether to show or hide.
  564. */
  565. showRaisedHandIndicator(show) {
  566. if (!this.container) {
  567. logger.warn(`Unable to raised hand indication - ${
  568. this.videoSpanId} does not exist`);
  569. return;
  570. }
  571. this._showRaisedHand = show;
  572. this.updateIndicators();
  573. }
  574. /**
  575. * Adds a listener for onresize events for this video, which will monitor for
  576. * resolution changes, will calculate the delay since the moment the listened
  577. * is added, and will fire a RESOLUTION_CHANGED event.
  578. */
  579. waitForResolutionChange() {
  580. const beforeChange = window.performance.now();
  581. const videos = this.selectVideoElement();
  582. if (!videos || !videos.length || videos.length <= 0) {
  583. return;
  584. }
  585. const video = videos[0];
  586. const oldWidth = video.videoWidth;
  587. const oldHeight = video.videoHeight;
  588. video.onresize = () => {
  589. // eslint-disable-next-line eqeqeq
  590. if (video.videoWidth != oldWidth || video.videoHeight != oldHeight) {
  591. // Only run once.
  592. video.onresize = null;
  593. const delay = window.performance.now() - beforeChange;
  594. const emitter = this.VideoLayout.getEventEmitter();
  595. if (emitter) {
  596. emitter.emit(UIEvents.RESOLUTION_CHANGED, this.getId(), `${oldWidth}x${oldHeight}`,
  597. `${video.videoWidth}x${video.videoHeight}`, delay);
  598. }
  599. }
  600. };
  601. }
  602. /**
  603. * Initalizes any browser specific properties. Currently sets the overflow
  604. * property for Qt browsers on Windows to hidden, thus fixing the following
  605. * problem:
  606. * Some browsers don't have full support of the object-fit property for the
  607. * video element and when we set video object-fit to "cover" the video
  608. * actually overflows the boundaries of its container, so it's important
  609. * to indicate that the "overflow" should be hidden.
  610. *
  611. * Setting this property for all browsers will result in broken audio levels,
  612. * which makes this a temporary solution, before reworking audio levels.
  613. */
  614. initBrowserSpecificProperties() {
  615. const userAgent = window.navigator.userAgent;
  616. if (userAgent.indexOf('QtWebEngine') > -1
  617. && (userAgent.indexOf('Windows') > -1 || userAgent.indexOf('Linux') > -1)) {
  618. this.$container.css('overflow', 'hidden');
  619. }
  620. }
  621. /**
  622. * Cleans up components on {@code SmallVideo} and removes itself from the DOM.
  623. *
  624. * @returns {void}
  625. */
  626. remove() {
  627. logger.log('Remove thumbnail', this.id);
  628. this.removeAudioLevelIndicator();
  629. const toolbarContainer
  630. = this.container.querySelector('.videocontainer__toolbar');
  631. if (toolbarContainer) {
  632. ReactDOM.unmountComponentAtNode(toolbarContainer);
  633. }
  634. this.removeConnectionIndicator();
  635. this.removeDisplayName();
  636. this.removeAvatar();
  637. this._unmountIndicators();
  638. // Remove whole container
  639. if (this.container.parentNode) {
  640. this.container.parentNode.removeChild(this.container);
  641. }
  642. }
  643. /**
  644. * Helper function for re-rendering multiple react components of the small
  645. * video.
  646. *
  647. * @returns {void}
  648. */
  649. rerender() {
  650. this.updateIndicators();
  651. this.updateStatusBar();
  652. this.updateView();
  653. }
  654. /**
  655. * Updates the React element responsible for showing connection status, dominant
  656. * speaker, and raised hand icons. Uses instance variables to get the necessary
  657. * state to display. Will create the React element if not already created.
  658. *
  659. * @private
  660. * @returns {void}
  661. */
  662. updateIndicators() {
  663. const indicatorToolbar = this.container.querySelector('.videocontainer__toptoolbar');
  664. if (!indicatorToolbar) {
  665. return;
  666. }
  667. const { NORMAL = 8 } = interfaceConfig.INDICATOR_FONT_SIZES || {};
  668. const iconSize = NORMAL;
  669. const showConnectionIndicator = this.videoIsHovered || !interfaceConfig.CONNECTION_INDICATOR_AUTO_HIDE_ENABLED;
  670. const state = APP.store.getState();
  671. const currentLayout = getCurrentLayout(state);
  672. const participantCount = getParticipantCount(state);
  673. let statsPopoverPosition, tooltipPosition;
  674. if (currentLayout === LAYOUTS.TILE_VIEW) {
  675. statsPopoverPosition = 'right top';
  676. tooltipPosition = 'right';
  677. } else if (currentLayout === LAYOUTS.VERTICAL_FILMSTRIP_VIEW) {
  678. statsPopoverPosition = this.statsPopoverLocation;
  679. tooltipPosition = 'left';
  680. } else {
  681. statsPopoverPosition = this.statsPopoverLocation;
  682. tooltipPosition = 'top';
  683. }
  684. ReactDOM.render(
  685. <Provider store = { APP.store }>
  686. <I18nextProvider i18n = { i18next }>
  687. <div>
  688. <AtlasKitThemeProvider mode = 'dark'>
  689. { this._showConnectionIndicator
  690. ? <ConnectionIndicator
  691. alwaysVisible = { showConnectionIndicator }
  692. connectionStatus = { this._connectionStatus }
  693. iconSize = { iconSize }
  694. isLocalVideo = { this.isLocal }
  695. enableStatsDisplay = { !interfaceConfig.filmStripOnly }
  696. participantId = { this.id }
  697. statsPopoverPosition = { statsPopoverPosition } />
  698. : null }
  699. <RaisedHandIndicator
  700. iconSize = { iconSize }
  701. participantId = { this.id }
  702. tooltipPosition = { tooltipPosition } />
  703. { this._showDominantSpeaker && participantCount > 2
  704. ? <DominantSpeakerIndicator
  705. iconSize = { iconSize }
  706. tooltipPosition = { tooltipPosition } />
  707. : null }
  708. </AtlasKitThemeProvider>
  709. </div>
  710. </I18nextProvider>
  711. </Provider>,
  712. indicatorToolbar
  713. );
  714. }
  715. /**
  716. * Callback invoked when the thumbnail is clicked and potentially trigger
  717. * pinning of the participant.
  718. *
  719. * @param {MouseEvent} event - The click event to intercept.
  720. * @private
  721. * @returns {void}
  722. */
  723. _onContainerClick(event) {
  724. const triggerPin = this._shouldTriggerPin(event);
  725. if (event.stopPropagation && triggerPin) {
  726. event.stopPropagation();
  727. event.preventDefault();
  728. }
  729. if (triggerPin) {
  730. this.togglePin();
  731. }
  732. return false;
  733. }
  734. /**
  735. * Returns whether or not a click event is targeted at certain elements which
  736. * should not trigger a pin.
  737. *
  738. * @param {MouseEvent} event - The click event to intercept.
  739. * @private
  740. * @returns {boolean}
  741. */
  742. _shouldTriggerPin(event) {
  743. // TODO Checking the classes is a workround to allow events to bubble into
  744. // the DisplayName component if it was clicked. React's synthetic events
  745. // will fire after jQuery handlers execute, so stop propogation at this
  746. // point will prevent DisplayName from getting click events. This workaround
  747. // should be removeable once LocalVideo is a React Component because then
  748. // the components share the same eventing system.
  749. const $source = $(event.target || event.srcElement);
  750. return $source.parents('.displayNameContainer').length === 0
  751. && $source.parents('.popover').length === 0
  752. && !event.target.classList.contains('popover');
  753. }
  754. /**
  755. * Pins the participant displayed by this thumbnail or unpins if already pinned.
  756. *
  757. * @returns {void}
  758. */
  759. togglePin() {
  760. const pinnedParticipant = getPinnedParticipant(APP.store.getState()) || {};
  761. const participantIdToPin = pinnedParticipant && pinnedParticipant.id === this.id ? null : this.id;
  762. APP.store.dispatch(pinParticipant(participantIdToPin));
  763. }
  764. /**
  765. * Removes the React element responsible for showing connection status, dominant
  766. * speaker, and raised hand icons.
  767. *
  768. * @private
  769. * @returns {void}
  770. */
  771. _unmountIndicators() {
  772. const indicatorToolbar = this.container.querySelector('.videocontainer__toptoolbar');
  773. if (indicatorToolbar) {
  774. ReactDOM.unmountComponentAtNode(indicatorToolbar);
  775. }
  776. }
  777. /**
  778. * Updates the current state of the connection indicator popover being hovered.
  779. * If hovered, display the small video as if it is hovered.
  780. *
  781. * @param {boolean} popoverIsHovered - Whether or not the mouse cursor is
  782. * currently over the connection indicator popover.
  783. * @returns {void}
  784. */
  785. _onPopoverHover(popoverIsHovered) {
  786. this._popoverIsHovered = popoverIsHovered;
  787. this.updateView();
  788. }
  789. /**
  790. * Sets the size of the thumbnail.
  791. */
  792. _setThumbnailSize() {
  793. const layout = getCurrentLayout(APP.store.getState());
  794. const heightToWidthPercent = 100
  795. / (this.isLocal ? interfaceConfig.LOCAL_THUMBNAIL_RATIO : interfaceConfig.REMOTE_THUMBNAIL_RATIO);
  796. switch (layout) {
  797. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW: {
  798. this.$container.css('padding-top', `${heightToWidthPercent}%`);
  799. this.$avatar().css({
  800. height: '50%',
  801. width: `${heightToWidthPercent / 2}%`
  802. });
  803. break;
  804. }
  805. case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW: {
  806. const state = APP.store.getState();
  807. const { local, remote } = state['features/filmstrip'].horizontalViewDimensions;
  808. const size = this.isLocal ? local : remote;
  809. if (typeof size !== 'undefined') {
  810. const { height, width } = size;
  811. const avatarSize = height / 2;
  812. this.$container.css({
  813. height: `${height}px`,
  814. 'min-height': `${height}px`,
  815. 'min-width': `${width}px`,
  816. width: `${width}px`
  817. });
  818. this.$avatar().css({
  819. height: `${avatarSize}px`,
  820. width: `${avatarSize}px`
  821. });
  822. }
  823. break;
  824. }
  825. case LAYOUTS.TILE_VIEW: {
  826. const state = APP.store.getState();
  827. const { thumbnailSize } = state['features/filmstrip'].tileViewDimensions;
  828. if (typeof thumbnailSize !== 'undefined') {
  829. const { height, width } = thumbnailSize;
  830. const avatarSize = height / 2;
  831. this.$container.css({
  832. height: `${height}px`,
  833. 'min-height': `${height}px`,
  834. 'min-width': `${width}px`,
  835. width: `${width}px`
  836. });
  837. this.$avatar().css({
  838. height: `${avatarSize}px`,
  839. width: `${avatarSize}px`
  840. });
  841. }
  842. break;
  843. }
  844. }
  845. }
  846. }