You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SmallVideo.js 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  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. * @param show whether we should show the avatar or not
  491. * video because there is no dominant speaker and no focused speaker
  492. */
  493. SmallVideo.prototype.updateView = function() {
  494. if (this.disableUpdateView) {
  495. return;
  496. }
  497. if (!this.hasAvatar) {
  498. if (this.id) {
  499. // Init avatar
  500. this.initializeAvatar();
  501. } else {
  502. logger.error('Unable to init avatar - no id', this);
  503. return;
  504. }
  505. }
  506. this.$container.removeClass((index, classNames) =>
  507. classNames.split(' ').filter(name => name.startsWith('display-')));
  508. // Determine whether video, avatar or blackness should be displayed
  509. const displayMode = this.selectDisplayMode();
  510. switch (displayMode) {
  511. case DISPLAY_AVATAR_WITH_NAME:
  512. this.$container.addClass('display-avatar-with-name');
  513. break;
  514. case DISPLAY_BLACKNESS_WITH_NAME:
  515. this.$container.addClass('display-name-on-black');
  516. break;
  517. case DISPLAY_VIDEO:
  518. this.$container.addClass('display-video');
  519. break;
  520. case DISPLAY_VIDEO_WITH_NAME:
  521. this.$container.addClass('display-name-on-video');
  522. break;
  523. case DISPLAY_AVATAR:
  524. default:
  525. this.$container.addClass('display-avatar-only');
  526. break;
  527. }
  528. };
  529. /**
  530. * Updates the react component displaying the avatar with the passed in avatar
  531. * url.
  532. *
  533. * @returns {void}
  534. */
  535. SmallVideo.prototype.initializeAvatar = function() {
  536. const thumbnail = this.$avatar().get(0);
  537. this.hasAvatar = true;
  538. if (thumbnail) {
  539. // Maybe add a special case for local participant, as on init of
  540. // LocalVideo.js the id is set to "local" but will get updated later.
  541. ReactDOM.render(
  542. <Provider store = { APP.store }>
  543. <AvatarDisplay
  544. className = 'userAvatar'
  545. participantId = { this.id } />
  546. </Provider>,
  547. thumbnail
  548. );
  549. }
  550. };
  551. /**
  552. * Unmounts any attached react components (particular the avatar image) from
  553. * the avatar container.
  554. *
  555. * @returns {void}
  556. */
  557. SmallVideo.prototype.removeAvatar = function() {
  558. const thumbnail = this.$avatar().get(0);
  559. if (thumbnail) {
  560. ReactDOM.unmountComponentAtNode(thumbnail);
  561. }
  562. };
  563. /**
  564. * Shows or hides the dominant speaker indicator.
  565. * @param show whether to show or hide.
  566. */
  567. SmallVideo.prototype.showDominantSpeakerIndicator = function(show) {
  568. // Don't create and show dominant speaker indicator if
  569. // DISABLE_DOMINANT_SPEAKER_INDICATOR is true
  570. if (interfaceConfig.DISABLE_DOMINANT_SPEAKER_INDICATOR) {
  571. return;
  572. }
  573. if (!this.container) {
  574. logger.warn(`Unable to set dominant speaker indicator - ${
  575. this.videoSpanId} does not exist`);
  576. return;
  577. }
  578. if (this._showDominantSpeaker === show) {
  579. return;
  580. }
  581. this._showDominantSpeaker = show;
  582. this.$container.toggleClass('active-speaker', this._showDominantSpeaker);
  583. this.updateIndicators();
  584. this.updateView();
  585. };
  586. /**
  587. * Shows or hides the raised hand indicator.
  588. * @param show whether to show or hide.
  589. */
  590. SmallVideo.prototype.showRaisedHandIndicator = function(show) {
  591. if (!this.container) {
  592. logger.warn(`Unable to raised hand indication - ${
  593. this.videoSpanId} does not exist`);
  594. return;
  595. }
  596. this._showRaisedHand = show;
  597. this.updateIndicators();
  598. };
  599. /**
  600. * Adds a listener for onresize events for this video, which will monitor for
  601. * resolution changes, will calculate the delay since the moment the listened
  602. * is added, and will fire a RESOLUTION_CHANGED event.
  603. */
  604. SmallVideo.prototype.waitForResolutionChange = function() {
  605. const beforeChange = window.performance.now();
  606. const videos = this.selectVideoElement();
  607. if (!videos || !videos.length || videos.length <= 0) {
  608. return;
  609. }
  610. const video = videos[0];
  611. const oldWidth = video.videoWidth;
  612. const oldHeight = video.videoHeight;
  613. video.onresize = () => {
  614. // eslint-disable-next-line eqeqeq
  615. if (video.videoWidth != oldWidth || video.videoHeight != oldHeight) {
  616. // Only run once.
  617. video.onresize = null;
  618. const delay = window.performance.now() - beforeChange;
  619. const emitter = this.VideoLayout.getEventEmitter();
  620. if (emitter) {
  621. emitter.emit(
  622. UIEvents.RESOLUTION_CHANGED,
  623. this.getId(),
  624. `${oldWidth}x${oldHeight}`,
  625. `${video.videoWidth}x${video.videoHeight}`,
  626. delay);
  627. }
  628. }
  629. };
  630. };
  631. /**
  632. * Initalizes any browser specific properties. Currently sets the overflow
  633. * property for Qt browsers on Windows to hidden, thus fixing the following
  634. * problem:
  635. * Some browsers don't have full support of the object-fit property for the
  636. * video element and when we set video object-fit to "cover" the video
  637. * actually overflows the boundaries of its container, so it's important
  638. * to indicate that the "overflow" should be hidden.
  639. *
  640. * Setting this property for all browsers will result in broken audio levels,
  641. * which makes this a temporary solution, before reworking audio levels.
  642. */
  643. SmallVideo.prototype.initBrowserSpecificProperties = function() {
  644. const userAgent = window.navigator.userAgent;
  645. if (userAgent.indexOf('QtWebEngine') > -1
  646. && (userAgent.indexOf('Windows') > -1
  647. || userAgent.indexOf('Linux') > -1)) {
  648. this.$container.css('overflow', 'hidden');
  649. }
  650. };
  651. /**
  652. * Cleans up components on {@code SmallVideo} and removes itself from the DOM.
  653. *
  654. * @returns {void}
  655. */
  656. SmallVideo.prototype.remove = function() {
  657. logger.log('Remove thumbnail', this.id);
  658. this.removeAudioLevelIndicator();
  659. const toolbarContainer
  660. = this.container.querySelector('.videocontainer__toolbar');
  661. if (toolbarContainer) {
  662. ReactDOM.unmountComponentAtNode(toolbarContainer);
  663. }
  664. this.removeConnectionIndicator();
  665. this.removeDisplayName();
  666. this.removeAvatar();
  667. this._unmountIndicators();
  668. // Remove whole container
  669. if (this.container.parentNode) {
  670. this.container.parentNode.removeChild(this.container);
  671. }
  672. };
  673. /**
  674. * Helper function for re-rendering multiple react components of the small
  675. * video.
  676. *
  677. * @returns {void}
  678. */
  679. SmallVideo.prototype.rerender = function() {
  680. this.updateIndicators();
  681. this.updateStatusBar();
  682. this.updateView();
  683. };
  684. /**
  685. * Updates the React element responsible for showing connection status, dominant
  686. * speaker, and raised hand icons. Uses instance variables to get the necessary
  687. * state to display. Will create the React element if not already created.
  688. *
  689. * @private
  690. * @returns {void}
  691. */
  692. SmallVideo.prototype.updateIndicators = function() {
  693. const indicatorToolbar
  694. = this.container.querySelector('.videocontainer__toptoolbar');
  695. if (!indicatorToolbar) {
  696. return;
  697. }
  698. const iconSize = UIUtil.getIndicatorFontSize();
  699. const showConnectionIndicator = this.videoIsHovered
  700. || !interfaceConfig.CONNECTION_INDICATOR_AUTO_HIDE_ENABLED;
  701. const currentLayout = getCurrentLayout(APP.store.getState());
  702. let statsPopoverPosition, tooltipPosition;
  703. if (currentLayout === LAYOUTS.TILE_VIEW) {
  704. statsPopoverPosition = 'right top';
  705. tooltipPosition = 'right';
  706. } else if (currentLayout === LAYOUTS.VERTICAL_FILMSTRIP_VIEW) {
  707. statsPopoverPosition = this.statsPopoverLocation;
  708. tooltipPosition = 'left';
  709. } else {
  710. statsPopoverPosition = this.statsPopoverLocation;
  711. tooltipPosition = 'top';
  712. }
  713. ReactDOM.render(
  714. <Provider store = { APP.store }>
  715. <I18nextProvider i18n = { i18next }>
  716. <div>
  717. <AtlasKitThemeProvider mode = 'dark'>
  718. { this._showConnectionIndicator
  719. ? <ConnectionIndicator
  720. alwaysVisible = { showConnectionIndicator }
  721. connectionStatus = { this._connectionStatus }
  722. iconSize = { iconSize }
  723. isLocalVideo = { this.isLocal }
  724. enableStatsDisplay
  725. = { !interfaceConfig.filmStripOnly }
  726. participantId = { this.id }
  727. statsPopoverPosition
  728. = { statsPopoverPosition } />
  729. : null }
  730. <RaisedHandIndicator
  731. iconSize = { iconSize }
  732. participantId = { this.id }
  733. tooltipPosition = { tooltipPosition } />
  734. { this._showDominantSpeaker
  735. ? <DominantSpeakerIndicator
  736. iconSize = { iconSize }
  737. tooltipPosition = { tooltipPosition } />
  738. : null }
  739. </AtlasKitThemeProvider>
  740. </div>
  741. </I18nextProvider>
  742. </Provider>,
  743. indicatorToolbar
  744. );
  745. };
  746. /**
  747. * Callback invoked when the thumbnail is clicked and potentially trigger
  748. * pinning of the participant.
  749. *
  750. * @param {MouseEvent} event - The click event to intercept.
  751. * @private
  752. * @returns {void}
  753. */
  754. SmallVideo.prototype._onContainerClick = function(event) {
  755. const triggerPin = this._shouldTriggerPin(event);
  756. if (event.stopPropagation && triggerPin) {
  757. event.stopPropagation();
  758. event.preventDefault();
  759. }
  760. if (triggerPin) {
  761. this.togglePin();
  762. }
  763. return false;
  764. };
  765. /**
  766. * Returns whether or not a click event is targeted at certain elements which
  767. * should not trigger a pin.
  768. *
  769. * @param {MouseEvent} event - The click event to intercept.
  770. * @private
  771. * @returns {boolean}
  772. */
  773. SmallVideo.prototype._shouldTriggerPin = function(event) {
  774. // TODO Checking the classes is a workround to allow events to bubble into
  775. // the DisplayName component if it was clicked. React's synthetic events
  776. // will fire after jQuery handlers execute, so stop propogation at this
  777. // point will prevent DisplayName from getting click events. This workaround
  778. // should be removeable once LocalVideo is a React Component because then
  779. // the components share the same eventing system.
  780. const $source = $(event.target || event.srcElement);
  781. return $source.parents('.displayNameContainer').length === 0
  782. && $source.parents('.popover').length === 0
  783. && !event.target.classList.contains('popover');
  784. };
  785. /**
  786. * Pins the participant displayed by this thumbnail or unpins if already pinned.
  787. *
  788. * @returns {void}
  789. */
  790. SmallVideo.prototype.togglePin = function() {
  791. const pinnedParticipant
  792. = getPinnedParticipant(APP.store.getState()) || {};
  793. const participantIdToPin
  794. = pinnedParticipant && pinnedParticipant.id === this.id
  795. ? null : this.id;
  796. APP.store.dispatch(pinParticipant(participantIdToPin));
  797. };
  798. /**
  799. * Removes the React element responsible for showing connection status, dominant
  800. * speaker, and raised hand icons.
  801. *
  802. * @private
  803. * @returns {void}
  804. */
  805. SmallVideo.prototype._unmountIndicators = function() {
  806. const indicatorToolbar
  807. = this.container.querySelector('.videocontainer__toptoolbar');
  808. if (indicatorToolbar) {
  809. ReactDOM.unmountComponentAtNode(indicatorToolbar);
  810. }
  811. };
  812. /**
  813. * Updates the current state of the connection indicator popover being hovered.
  814. * If hovered, display the small video as if it is hovered.
  815. *
  816. * @param {boolean} popoverIsHovered - Whether or not the mouse cursor is
  817. * currently over the connection indicator popover.
  818. * @returns {void}
  819. */
  820. SmallVideo.prototype._onPopoverHover = function(popoverIsHovered) {
  821. this._popoverIsHovered = popoverIsHovered;
  822. this.updateView();
  823. };
  824. export default SmallVideo;