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

SmallVideo.js 27KB

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