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

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