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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  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. 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. } else if (config.startSilent) {
  178. element.muted = true;
  179. }
  180. element.autoplay = true;
  181. element.id = SmallVideo.getStreamElementID(stream);
  182. return element;
  183. };
  184. /**
  185. * Returns the element id for a particular MediaStream.
  186. */
  187. SmallVideo.getStreamElementID = function(stream) {
  188. const isVideo = stream.isVideoTrack();
  189. return (isVideo ? 'remoteVideo_' : 'remoteAudio_') + stream.getId();
  190. };
  191. /**
  192. * Configures hoverIn/hoverOut handlers. Depends on connection indicator.
  193. */
  194. SmallVideo.prototype.bindHoverHandler = function() {
  195. // Add hover handler
  196. this.$container.hover(
  197. () => {
  198. this.videoIsHovered = true;
  199. this.updateView();
  200. this.updateIndicators();
  201. },
  202. () => {
  203. this.videoIsHovered = false;
  204. this.updateView();
  205. this.updateIndicators();
  206. }
  207. );
  208. };
  209. /**
  210. * Unmounts the ConnectionIndicator component.
  211. * @returns {void}
  212. */
  213. SmallVideo.prototype.removeConnectionIndicator = function() {
  214. this._showConnectionIndicator = false;
  215. this.updateIndicators();
  216. };
  217. /**
  218. * Updates the connectionStatus stat which displays in the ConnectionIndicator.
  219. * @returns {void}
  220. */
  221. SmallVideo.prototype.updateConnectionStatus = function(connectionStatus) {
  222. this._connectionStatus = connectionStatus;
  223. this.updateIndicators();
  224. };
  225. /**
  226. * Shows / hides the audio muted indicator over small videos.
  227. *
  228. * @param {boolean} isMuted indicates if the muted element should be shown
  229. * or hidden
  230. */
  231. SmallVideo.prototype.showAudioIndicator = function(isMuted) {
  232. this.isAudioMuted = isMuted;
  233. this.updateStatusBar();
  234. };
  235. /**
  236. * Shows video muted indicator over small videos and disables/enables avatar
  237. * if video muted.
  238. *
  239. * @param {boolean} isMuted indicates if we should set the view to muted view
  240. * or not
  241. */
  242. SmallVideo.prototype.setVideoMutedView = function(isMuted) {
  243. this.isVideoMuted = isMuted;
  244. this.updateView();
  245. this.updateStatusBar();
  246. };
  247. /**
  248. * Create or updates the ReactElement for displaying status indicators about
  249. * audio mute, video mute, and moderator status.
  250. *
  251. * @returns {void}
  252. */
  253. SmallVideo.prototype.updateStatusBar = function() {
  254. const statusBarContainer
  255. = this.container.querySelector('.videocontainer__toolbar');
  256. if (!statusBarContainer) {
  257. return;
  258. }
  259. const currentLayout = getCurrentLayout(APP.store.getState());
  260. let tooltipPosition;
  261. if (currentLayout === LAYOUTS.TILE_VIEW) {
  262. tooltipPosition = 'right';
  263. } else if (currentLayout === LAYOUTS.VERTICAL_FILMSTRIP_VIEW) {
  264. tooltipPosition = 'left';
  265. } else {
  266. tooltipPosition = 'top';
  267. }
  268. ReactDOM.render(
  269. <I18nextProvider i18n = { i18next }>
  270. <div>
  271. { this.isAudioMuted
  272. ? <AudioMutedIndicator
  273. tooltipPosition = { tooltipPosition } />
  274. : null }
  275. { this.isVideoMuted
  276. ? <VideoMutedIndicator
  277. tooltipPosition = { tooltipPosition } />
  278. : null }
  279. { this._isModerator && !interfaceConfig.DISABLE_FOCUS_INDICATOR
  280. ? <ModeratorIndicator
  281. tooltipPosition = { tooltipPosition } />
  282. : null }
  283. </div>
  284. </I18nextProvider>,
  285. statusBarContainer);
  286. };
  287. /**
  288. * Adds the element indicating the moderator(owner) of the conference.
  289. */
  290. SmallVideo.prototype.addModeratorIndicator = function() {
  291. this._isModerator = true;
  292. this.updateStatusBar();
  293. };
  294. /**
  295. * Adds the element indicating the audio level of the participant.
  296. *
  297. * @returns {void}
  298. */
  299. SmallVideo.prototype.addAudioLevelIndicator = function() {
  300. let audioLevelContainer = this._getAudioLevelContainer();
  301. if (audioLevelContainer) {
  302. return;
  303. }
  304. audioLevelContainer = document.createElement('span');
  305. audioLevelContainer.className = 'audioindicator-container';
  306. this.container.appendChild(audioLevelContainer);
  307. this.updateAudioLevelIndicator();
  308. };
  309. /**
  310. * Removes the element indicating the audio level of the participant.
  311. *
  312. * @returns {void}
  313. */
  314. SmallVideo.prototype.removeAudioLevelIndicator = function() {
  315. const audioLevelContainer = this._getAudioLevelContainer();
  316. if (audioLevelContainer) {
  317. ReactDOM.unmountComponentAtNode(audioLevelContainer);
  318. }
  319. };
  320. /**
  321. * Updates the audio level for this small video.
  322. *
  323. * @param lvl the new audio level to set
  324. * @returns {void}
  325. */
  326. SmallVideo.prototype.updateAudioLevelIndicator = function(lvl = 0) {
  327. const audioLevelContainer = this._getAudioLevelContainer();
  328. if (audioLevelContainer) {
  329. ReactDOM.render(
  330. <AudioLevelIndicator
  331. audioLevel = { lvl }/>,
  332. audioLevelContainer);
  333. }
  334. };
  335. /**
  336. * Queries the component's DOM for the element that should be the parent to the
  337. * AudioLevelIndicator.
  338. *
  339. * @returns {HTMLElement} The DOM element that holds the AudioLevelIndicator.
  340. */
  341. SmallVideo.prototype._getAudioLevelContainer = function() {
  342. return this.container.querySelector('.audioindicator-container');
  343. };
  344. /**
  345. * Removes the element indicating the moderator(owner) of the conference.
  346. */
  347. SmallVideo.prototype.removeModeratorIndicator = function() {
  348. this._isModerator = false;
  349. this.updateStatusBar();
  350. };
  351. /**
  352. * This is an especially interesting function. A naive reader might think that
  353. * it returns this SmallVideo's "video" element. But it is much more exciting.
  354. * It first finds this video's parent element using jquery, then uses a utility
  355. * from lib-jitsi-meet to extract the video element from it (with two more
  356. * jquery calls), and finally uses jquery again to encapsulate the video element
  357. * in an array. This last step allows (some might prefer "forces") users of
  358. * this function to access the video element via the 0th element of the returned
  359. * array (after checking its length of course!).
  360. */
  361. SmallVideo.prototype.selectVideoElement = function() {
  362. return $($(this.container).find('video')[0]);
  363. };
  364. /**
  365. * Selects the HTML image element which displays user's avatar.
  366. *
  367. * @return {jQuery|HTMLElement} a jQuery selector pointing to the HTML image
  368. * element which displays the user's avatar.
  369. */
  370. SmallVideo.prototype.$avatar = function() {
  371. return this.$container.find('.avatar-container');
  372. };
  373. /**
  374. * Returns the display name element, which appears on the video thumbnail.
  375. *
  376. * @return {jQuery} a jQuery selector pointing to the display name element of
  377. * the video thumbnail
  378. */
  379. SmallVideo.prototype.$displayName = function() {
  380. return this.$container.find('.displayNameContainer');
  381. };
  382. /**
  383. * Creates or updates the participant's display name that is shown over the
  384. * video preview.
  385. *
  386. * @param {Object} props - The React {@code Component} props to pass into the
  387. * {@code DisplayName} component.
  388. * @returns {void}
  389. */
  390. SmallVideo.prototype._renderDisplayName = function(props) {
  391. const displayNameContainer
  392. = this.container.querySelector('.displayNameContainer');
  393. if (displayNameContainer) {
  394. ReactDOM.render(
  395. <Provider store = { APP.store }>
  396. <I18nextProvider i18n = { i18next }>
  397. <DisplayName { ...props } />
  398. </I18nextProvider>
  399. </Provider>,
  400. displayNameContainer);
  401. }
  402. };
  403. /**
  404. * Removes the component responsible for showing the participant's display name,
  405. * if its container is present.
  406. *
  407. * @returns {void}
  408. */
  409. SmallVideo.prototype.removeDisplayName = function() {
  410. const displayNameContainer
  411. = this.container.querySelector('.displayNameContainer');
  412. if (displayNameContainer) {
  413. ReactDOM.unmountComponentAtNode(displayNameContainer);
  414. }
  415. };
  416. /**
  417. * Enables / disables the css responsible for focusing/pinning a video
  418. * thumbnail.
  419. *
  420. * @param isFocused indicates if the thumbnail should be focused/pinned or not
  421. */
  422. SmallVideo.prototype.focus = function(isFocused) {
  423. const focusedCssClass = 'videoContainerFocused';
  424. const isFocusClassEnabled = this.$container.hasClass(focusedCssClass);
  425. if (!isFocused && isFocusClassEnabled) {
  426. this.$container.removeClass(focusedCssClass);
  427. } else if (isFocused && !isFocusClassEnabled) {
  428. this.$container.addClass(focusedCssClass);
  429. }
  430. };
  431. SmallVideo.prototype.hasVideo = function() {
  432. return this.selectVideoElement().length !== 0;
  433. };
  434. /**
  435. * Checks whether the user associated with this <tt>SmallVideo</tt> is currently
  436. * being displayed on the "large video".
  437. *
  438. * @return {boolean} <tt>true</tt> if the user is displayed on the large video
  439. * or <tt>false</tt> otherwise.
  440. */
  441. SmallVideo.prototype.isCurrentlyOnLargeVideo = function() {
  442. return this.VideoLayout.isCurrentlyOnLarge(this.id);
  443. };
  444. /**
  445. * Checks whether there is a playable video stream available for the user
  446. * associated with this <tt>SmallVideo</tt>.
  447. *
  448. * @return {boolean} <tt>true</tt> if there is a playable video stream available
  449. * or <tt>false</tt> otherwise.
  450. */
  451. SmallVideo.prototype.isVideoPlayable = function() {
  452. return this.videoStream // Is there anything to display ?
  453. && !this.isVideoMuted && !this.videoStream.isMuted(); // Muted ?
  454. };
  455. /**
  456. * Determines what should be display on the thumbnail.
  457. *
  458. * @return {number} one of <tt>DISPLAY_VIDEO</tt>,<tt>DISPLAY_AVATAR</tt>
  459. * or <tt>DISPLAY_BLACKNESS_WITH_NAME</tt>.
  460. */
  461. SmallVideo.prototype.selectDisplayMode = function() {
  462. // Display name is always and only displayed when user is on the stage
  463. if (this.isCurrentlyOnLargeVideo()
  464. && !shouldDisplayTileView(APP.store.getState())) {
  465. return this.isVideoPlayable() && !APP.conference.isAudioOnly()
  466. ? DISPLAY_BLACKNESS_WITH_NAME : DISPLAY_AVATAR_WITH_NAME;
  467. } else if (this.isVideoPlayable()
  468. && this.selectVideoElement().length
  469. && !APP.conference.isAudioOnly()) {
  470. // check hovering and change state to video with name
  471. return this._isHovered()
  472. ? DISPLAY_VIDEO_WITH_NAME : DISPLAY_VIDEO;
  473. }
  474. // check hovering and change state to avatar with name
  475. return this._isHovered()
  476. ? DISPLAY_AVATAR_WITH_NAME : DISPLAY_AVATAR;
  477. };
  478. /**
  479. * Checks whether current video is considered hovered. Currently it is hovered
  480. * if the mouse is over the video, or if the connection
  481. * indicator is shown(hovered).
  482. * @private
  483. */
  484. SmallVideo.prototype._isHovered = function() {
  485. return this.videoIsHovered || this._popoverIsHovered;
  486. };
  487. /**
  488. * Hides or shows the user's avatar.
  489. * This update assumes that large video had been updated and we will
  490. * reflect it on this small video.
  491. *
  492. * @param show whether we should show the avatar or not
  493. * video because there is no dominant speaker and no focused speaker
  494. */
  495. SmallVideo.prototype.updateView = function() {
  496. if (this.disableUpdateView) {
  497. return;
  498. }
  499. if (!this.hasAvatar) {
  500. if (this.id) {
  501. // Init avatar
  502. this.avatarChanged(
  503. getAvatarURLByParticipantId(APP.store.getState(), this.id));
  504. } else {
  505. logger.error('Unable to init avatar - no id', this);
  506. return;
  507. }
  508. }
  509. this.$container.removeClass((index, classNames) =>
  510. classNames.split(' ').filter(name => name.startsWith('display-')));
  511. // Determine whether video, avatar or blackness should be displayed
  512. const displayMode = this.selectDisplayMode();
  513. switch (displayMode) {
  514. case DISPLAY_AVATAR_WITH_NAME:
  515. this.$container.addClass('display-avatar-with-name');
  516. break;
  517. case DISPLAY_BLACKNESS_WITH_NAME:
  518. this.$container.addClass('display-name-on-black');
  519. break;
  520. case DISPLAY_VIDEO:
  521. this.$container.addClass('display-video');
  522. break;
  523. case DISPLAY_VIDEO_WITH_NAME:
  524. this.$container.addClass('display-name-on-video');
  525. break;
  526. case DISPLAY_AVATAR:
  527. default:
  528. this.$container.addClass('display-avatar-only');
  529. break;
  530. }
  531. };
  532. /**
  533. * Updates the react component displaying the avatar with the passed in avatar
  534. * url.
  535. *
  536. * @param {string} avatarUrl - The uri to the avatar image.
  537. * @returns {void}
  538. */
  539. SmallVideo.prototype.avatarChanged = function(avatarUrl) {
  540. const thumbnail = this.$avatar().get(0);
  541. this.hasAvatar = true;
  542. if (thumbnail) {
  543. ReactDOM.render(
  544. <AvatarDisplay
  545. className = 'userAvatar'
  546. uri = { avatarUrl } />,
  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 double clicked. Will pin the
  748. * participant if in tile view.
  749. *
  750. * @param {MouseEvent} event - The click event to intercept.
  751. * @private
  752. * @returns {void}
  753. */
  754. SmallVideo.prototype._onContainerDoubleClick = function(event) {
  755. if (this._pinningRequiresDoubleClick() && this._shouldTriggerPin(event)) {
  756. APP.store.dispatch(pinParticipant(this.id));
  757. }
  758. };
  759. /**
  760. * Callback invoked when the thumbnail is clicked and potentially trigger
  761. * pinning of the participant.
  762. *
  763. * @param {MouseEvent} event - The click event to intercept.
  764. * @private
  765. * @returns {void}
  766. */
  767. SmallVideo.prototype._onContainerClick = function(event) {
  768. const triggerPin = this._shouldTriggerPin(event)
  769. && !this._pinningRequiresDoubleClick();
  770. if (event.stopPropagation && triggerPin) {
  771. event.stopPropagation();
  772. event.preventDefault();
  773. }
  774. if (triggerPin) {
  775. this.togglePin();
  776. }
  777. return false;
  778. };
  779. /**
  780. * Returns whether or not a click event is targeted at certain elements which
  781. * should not trigger a pin.
  782. *
  783. * @param {MouseEvent} event - The click event to intercept.
  784. * @private
  785. * @returns {boolean}
  786. */
  787. SmallVideo.prototype._shouldTriggerPin = function(event) {
  788. // TODO Checking the classes is a workround to allow events to bubble into
  789. // the DisplayName component if it was clicked. React's synthetic events
  790. // will fire after jQuery handlers execute, so stop propogation at this
  791. // point will prevent DisplayName from getting click events. This workaround
  792. // should be removeable once LocalVideo is a React Component because then
  793. // the components share the same eventing system.
  794. const $source = $(event.target || event.srcElement);
  795. return $source.parents('.displayNameContainer').length === 0
  796. && $source.parents('.popover').length === 0
  797. && !event.target.classList.contains('popover');
  798. };
  799. /**
  800. * Pins the participant displayed by this thumbnail or unpins if already pinned.
  801. *
  802. * @returns {void}
  803. */
  804. SmallVideo.prototype.togglePin = function() {
  805. const pinnedParticipant
  806. = getPinnedParticipant(APP.store.getState()) || {};
  807. const participantIdToPin
  808. = pinnedParticipant && pinnedParticipant.id === this.id
  809. ? null : this.id;
  810. APP.store.dispatch(pinParticipant(participantIdToPin));
  811. };
  812. /**
  813. * Returns whether or not clicking to pin the participant needs to be a double
  814. * click instead of a single click.
  815. *
  816. * @private
  817. * @returns {boolean}
  818. */
  819. SmallVideo.prototype._pinningRequiresDoubleClick = function() {
  820. return shouldDisplayTileView(APP.store.getState());
  821. };
  822. /**
  823. * Removes the React element responsible for showing connection status, dominant
  824. * speaker, and raised hand icons.
  825. *
  826. * @private
  827. * @returns {void}
  828. */
  829. SmallVideo.prototype._unmountIndicators = function() {
  830. const indicatorToolbar
  831. = this.container.querySelector('.videocontainer__toptoolbar');
  832. if (indicatorToolbar) {
  833. ReactDOM.unmountComponentAtNode(indicatorToolbar);
  834. }
  835. };
  836. /**
  837. * Updates the current state of the connection indicator popover being hovered.
  838. * If hovered, display the small video as if it is hovered.
  839. *
  840. * @param {boolean} popoverIsHovered - Whether or not the mouse cursor is
  841. * currently over the connection indicator popover.
  842. * @returns {void}
  843. */
  844. SmallVideo.prototype._onPopoverHover = function(popoverIsHovered) {
  845. this._popoverIsHovered = popoverIsHovered;
  846. this.updateView();
  847. };
  848. export default SmallVideo;