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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. /* global $, APP, 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. this._onContainerDoubleClick = this._onContainerDoubleClick.bind(this);
  130. }
  131. /**
  132. * Returns the identifier of this small video.
  133. *
  134. * @returns the identifier of this small video
  135. */
  136. SmallVideo.prototype.getId = function() {
  137. return this.id;
  138. };
  139. /* Indicates if this small video is currently visible.
  140. *
  141. * @return <tt>true</tt> if this small video isn't currently visible and
  142. * <tt>false</tt> - otherwise.
  143. */
  144. SmallVideo.prototype.isVisible = function() {
  145. return this.$container.is(':visible');
  146. };
  147. /**
  148. * Sets the type of the video displayed by this instance.
  149. * Note that this is a string without clearly defined or checked values, and
  150. * it is NOT one of the strings defined in service/RTC/VideoType in
  151. * lib-jitsi-meet.
  152. * @param videoType 'camera' or 'desktop', or 'sharedvideo'.
  153. */
  154. SmallVideo.prototype.setVideoType = function(videoType) {
  155. this.videoType = videoType;
  156. };
  157. /**
  158. * Returns the type of the video displayed by this instance.
  159. * Note that this is a string without clearly defined or checked values, and
  160. * it is NOT one of the strings defined in service/RTC/VideoType in
  161. * lib-jitsi-meet.
  162. * @returns {String} 'camera', 'screen', 'sharedvideo', or undefined.
  163. */
  164. SmallVideo.prototype.getVideoType = function() {
  165. return this.videoType;
  166. };
  167. /**
  168. * Creates an audio or video element for a particular MediaStream.
  169. */
  170. SmallVideo.createStreamElement = function(stream) {
  171. const isVideo = stream.isVideoTrack();
  172. const element = isVideo
  173. ? document.createElement('video')
  174. : document.createElement('audio');
  175. if (isVideo) {
  176. element.setAttribute('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. * @returns {void}
  385. */
  386. SmallVideo.prototype.updateDisplayName = function(props) {
  387. const displayNameContainer
  388. = this.container.querySelector('.displayNameContainer');
  389. if (displayNameContainer) {
  390. ReactDOM.render(
  391. <Provider store = { APP.store }>
  392. <I18nextProvider i18n = { i18next }>
  393. <DisplayName { ...props } />
  394. </I18nextProvider>
  395. </Provider>,
  396. displayNameContainer);
  397. }
  398. };
  399. /**
  400. * Removes the component responsible for showing the participant's display name,
  401. * if its container is present.
  402. *
  403. * @returns {void}
  404. */
  405. SmallVideo.prototype.removeDisplayName = function() {
  406. const displayNameContainer
  407. = this.container.querySelector('.displayNameContainer');
  408. if (displayNameContainer) {
  409. ReactDOM.unmountComponentAtNode(displayNameContainer);
  410. }
  411. };
  412. /**
  413. * Enables / disables the css responsible for focusing/pinning a video
  414. * thumbnail.
  415. *
  416. * @param isFocused indicates if the thumbnail should be focused/pinned or not
  417. */
  418. SmallVideo.prototype.focus = function(isFocused) {
  419. const focusedCssClass = 'videoContainerFocused';
  420. const isFocusClassEnabled = this.$container.hasClass(focusedCssClass);
  421. if (!isFocused && isFocusClassEnabled) {
  422. this.$container.removeClass(focusedCssClass);
  423. } else if (isFocused && !isFocusClassEnabled) {
  424. this.$container.addClass(focusedCssClass);
  425. }
  426. };
  427. SmallVideo.prototype.hasVideo = function() {
  428. return this.selectVideoElement().length !== 0;
  429. };
  430. /**
  431. * Checks whether the user associated with this <tt>SmallVideo</tt> is currently
  432. * being displayed on the "large video".
  433. *
  434. * @return {boolean} <tt>true</tt> if the user is displayed on the large video
  435. * or <tt>false</tt> otherwise.
  436. */
  437. SmallVideo.prototype.isCurrentlyOnLargeVideo = function() {
  438. return this.VideoLayout.isCurrentlyOnLarge(this.id);
  439. };
  440. /**
  441. * Checks whether there is a playable video stream available for the user
  442. * associated with this <tt>SmallVideo</tt>.
  443. *
  444. * @return {boolean} <tt>true</tt> if there is a playable video stream available
  445. * or <tt>false</tt> otherwise.
  446. */
  447. SmallVideo.prototype.isVideoPlayable = function() {
  448. return this.videoStream // Is there anything to display ?
  449. && !this.isVideoMuted && !this.videoStream.isMuted(); // Muted ?
  450. };
  451. /**
  452. * Determines what should be display on the thumbnail.
  453. *
  454. * @return {number} one of <tt>DISPLAY_VIDEO</tt>,<tt>DISPLAY_AVATAR</tt>
  455. * or <tt>DISPLAY_BLACKNESS_WITH_NAME</tt>.
  456. */
  457. SmallVideo.prototype.selectDisplayMode = function() {
  458. // Display name is always and only displayed when user is on the stage
  459. if (this.isCurrentlyOnLargeVideo()
  460. && !shouldDisplayTileView(APP.store.getState())) {
  461. return this.isVideoPlayable() && !APP.conference.isAudioOnly()
  462. ? DISPLAY_BLACKNESS_WITH_NAME : DISPLAY_AVATAR_WITH_NAME;
  463. } else if (this.isVideoPlayable()
  464. && this.selectVideoElement().length
  465. && !APP.conference.isAudioOnly()) {
  466. // check hovering and change state to video with name
  467. return this._isHovered()
  468. ? DISPLAY_VIDEO_WITH_NAME : DISPLAY_VIDEO;
  469. }
  470. // check hovering and change state to avatar with name
  471. return this._isHovered()
  472. ? DISPLAY_AVATAR_WITH_NAME : DISPLAY_AVATAR;
  473. };
  474. /**
  475. * Checks whether current video is considered hovered. Currently it is hovered
  476. * if the mouse is over the video, or if the connection
  477. * indicator is shown(hovered).
  478. * @private
  479. */
  480. SmallVideo.prototype._isHovered = function() {
  481. return this.videoIsHovered || this._popoverIsHovered;
  482. };
  483. /**
  484. * Hides or shows the user's avatar.
  485. * This update assumes that large video had been updated and we will
  486. * reflect it on this small video.
  487. *
  488. * @param show whether we should show the avatar or not
  489. * video because there is no dominant speaker and no focused speaker
  490. */
  491. SmallVideo.prototype.updateView = function() {
  492. if (this.disableUpdateView) {
  493. return;
  494. }
  495. if (!this.hasAvatar) {
  496. if (this.id) {
  497. // Init avatar
  498. this.avatarChanged(
  499. getAvatarURLByParticipantId(APP.store.getState(), this.id));
  500. } else {
  501. logger.error('Unable to init avatar - no id', this);
  502. return;
  503. }
  504. }
  505. this.$container.removeClass((index, classNames) =>
  506. classNames.split(' ').filter(name => name.startsWith('display-')));
  507. // Determine whether video, avatar or blackness should be displayed
  508. const displayMode = this.selectDisplayMode();
  509. switch (displayMode) {
  510. case DISPLAY_AVATAR_WITH_NAME:
  511. this.$container.addClass('display-avatar-with-name');
  512. break;
  513. case DISPLAY_BLACKNESS_WITH_NAME:
  514. this.$container.addClass('display-name-on-black');
  515. break;
  516. case DISPLAY_VIDEO:
  517. this.$container.addClass('display-video');
  518. break;
  519. case DISPLAY_VIDEO_WITH_NAME:
  520. this.$container.addClass('display-name-on-video');
  521. break;
  522. case DISPLAY_AVATAR:
  523. default:
  524. this.$container.addClass('display-avatar-only');
  525. break;
  526. }
  527. };
  528. /**
  529. * Updates the react component displaying the avatar with the passed in avatar
  530. * url.
  531. *
  532. * @param {string} avatarUrl - The uri to the avatar image.
  533. * @returns {void}
  534. */
  535. SmallVideo.prototype.avatarChanged = function(avatarUrl) {
  536. const thumbnail = this.$avatar().get(0);
  537. this.hasAvatar = true;
  538. if (thumbnail) {
  539. ReactDOM.render(
  540. <AvatarDisplay
  541. className = 'userAvatar'
  542. uri = { avatarUrl } />,
  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. <I18nextProvider i18n = { i18next }>
  711. <div>
  712. <AtlasKitThemeProvider mode = 'dark'>
  713. { this._showConnectionIndicator
  714. ? <ConnectionIndicator
  715. alwaysVisible = { showConnectionIndicator }
  716. connectionStatus = { this._connectionStatus }
  717. iconSize = { iconSize }
  718. isLocalVideo = { this.isLocal }
  719. enableStatsDisplay
  720. = { !interfaceConfig.filmStripOnly }
  721. statsPopoverPosition
  722. = { statsPopoverPosition }
  723. userID = { this.id } />
  724. : null }
  725. { this._showRaisedHand
  726. ? <RaisedHandIndicator
  727. iconSize = { iconSize }
  728. tooltipPosition = { tooltipPosition } />
  729. : null }
  730. { this._showDominantSpeaker
  731. ? <DominantSpeakerIndicator
  732. iconSize = { iconSize }
  733. tooltipPosition = { tooltipPosition } />
  734. : null }
  735. </AtlasKitThemeProvider>
  736. </div>
  737. </I18nextProvider>,
  738. indicatorToolbar
  739. );
  740. };
  741. /**
  742. * Callback invoked when the thumbnail is double clicked. Will pin the
  743. * participant if in tile view.
  744. *
  745. * @param {MouseEvent} event - The click event to intercept.
  746. * @private
  747. * @returns {void}
  748. */
  749. SmallVideo.prototype._onContainerDoubleClick = function(event) {
  750. if (this._pinningRequiresDoubleClick() && this._shouldTriggerPin(event)) {
  751. APP.store.dispatch(pinParticipant(this.id));
  752. }
  753. };
  754. /**
  755. * Callback invoked when the thumbnail is clicked and potentially trigger
  756. * pinning of the participant.
  757. *
  758. * @param {MouseEvent} event - The click event to intercept.
  759. * @private
  760. * @returns {void}
  761. */
  762. SmallVideo.prototype._onContainerClick = function(event) {
  763. const triggerPin = this._shouldTriggerPin(event)
  764. && !this._pinningRequiresDoubleClick();
  765. if (event.stopPropagation && triggerPin) {
  766. event.stopPropagation();
  767. event.preventDefault();
  768. }
  769. if (triggerPin) {
  770. this.togglePin();
  771. }
  772. return false;
  773. };
  774. /**
  775. * Returns whether or not a click event is targeted at certain elements which
  776. * should not trigger a pin.
  777. *
  778. * @param {MouseEvent} event - The click event to intercept.
  779. * @private
  780. * @returns {boolean}
  781. */
  782. SmallVideo.prototype._shouldTriggerPin = function(event) {
  783. // TODO Checking the classes is a workround to allow events to bubble into
  784. // the DisplayName component if it was clicked. React's synthetic events
  785. // will fire after jQuery handlers execute, so stop propogation at this
  786. // point will prevent DisplayName from getting click events. This workaround
  787. // should be removeable once LocalVideo is a React Component because then
  788. // the components share the same eventing system.
  789. const $source = $(event.target || event.srcElement);
  790. return $source.parents('.displayNameContainer').length === 0
  791. && $source.parents('.popover').length === 0
  792. && !event.target.classList.contains('popover');
  793. };
  794. /**
  795. * Pins the participant displayed by this thumbnail or unpins if already pinned.
  796. *
  797. * @returns {void}
  798. */
  799. SmallVideo.prototype.togglePin = function() {
  800. const pinnedParticipant
  801. = getPinnedParticipant(APP.store.getState()) || {};
  802. const participantIdToPin
  803. = pinnedParticipant && pinnedParticipant.id === this.id
  804. ? null : this.id;
  805. APP.store.dispatch(pinParticipant(participantIdToPin));
  806. };
  807. /**
  808. * Returns whether or not clicking to pin the participant needs to be a double
  809. * click instead of a single click.
  810. *
  811. * @private
  812. * @returns {boolean}
  813. */
  814. SmallVideo.prototype._pinningRequiresDoubleClick = function() {
  815. return shouldDisplayTileView(APP.store.getState());
  816. };
  817. /**
  818. * Removes the React element responsible for showing connection status, dominant
  819. * speaker, and raised hand icons.
  820. *
  821. * @private
  822. * @returns {void}
  823. */
  824. SmallVideo.prototype._unmountIndicators = function() {
  825. const indicatorToolbar
  826. = this.container.querySelector('.videocontainer__toptoolbar');
  827. if (indicatorToolbar) {
  828. ReactDOM.unmountComponentAtNode(indicatorToolbar);
  829. }
  830. };
  831. /**
  832. * Updates the current state of the connection indicator popover being hovered.
  833. * If hovered, display the small video as if it is hovered.
  834. *
  835. * @param {boolean} popoverIsHovered - Whether or not the mouse cursor is
  836. * currently over the connection indicator popover.
  837. * @returns {void}
  838. */
  839. SmallVideo.prototype._onPopoverHover = function(popoverIsHovered) {
  840. this._popoverIsHovered = popoverIsHovered;
  841. this.updateView();
  842. };
  843. export default SmallVideo;