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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  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. * @param {Object} props - The React {@code Component} props to pass into the
  385. * {@code DisplayName} component.
  386. * @returns {void}
  387. */
  388. SmallVideo.prototype._renderDisplayName = function(props) {
  389. const displayNameContainer
  390. = this.container.querySelector('.displayNameContainer');
  391. if (displayNameContainer) {
  392. ReactDOM.render(
  393. <Provider store = { APP.store }>
  394. <I18nextProvider i18n = { i18next }>
  395. <DisplayName { ...props } />
  396. </I18nextProvider>
  397. </Provider>,
  398. displayNameContainer);
  399. }
  400. };
  401. /**
  402. * Removes the component responsible for showing the participant's display name,
  403. * if its container is present.
  404. *
  405. * @returns {void}
  406. */
  407. SmallVideo.prototype.removeDisplayName = function() {
  408. const displayNameContainer
  409. = this.container.querySelector('.displayNameContainer');
  410. if (displayNameContainer) {
  411. ReactDOM.unmountComponentAtNode(displayNameContainer);
  412. }
  413. };
  414. /**
  415. * Enables / disables the css responsible for focusing/pinning a video
  416. * thumbnail.
  417. *
  418. * @param isFocused indicates if the thumbnail should be focused/pinned or not
  419. */
  420. SmallVideo.prototype.focus = function(isFocused) {
  421. const focusedCssClass = 'videoContainerFocused';
  422. const isFocusClassEnabled = this.$container.hasClass(focusedCssClass);
  423. if (!isFocused && isFocusClassEnabled) {
  424. this.$container.removeClass(focusedCssClass);
  425. } else if (isFocused && !isFocusClassEnabled) {
  426. this.$container.addClass(focusedCssClass);
  427. }
  428. };
  429. SmallVideo.prototype.hasVideo = function() {
  430. return this.selectVideoElement().length !== 0;
  431. };
  432. /**
  433. * Checks whether the user associated with this <tt>SmallVideo</tt> is currently
  434. * being displayed on the "large video".
  435. *
  436. * @return {boolean} <tt>true</tt> if the user is displayed on the large video
  437. * or <tt>false</tt> otherwise.
  438. */
  439. SmallVideo.prototype.isCurrentlyOnLargeVideo = function() {
  440. return this.VideoLayout.isCurrentlyOnLarge(this.id);
  441. };
  442. /**
  443. * Checks whether there is a playable video stream available for the user
  444. * associated with this <tt>SmallVideo</tt>.
  445. *
  446. * @return {boolean} <tt>true</tt> if there is a playable video stream available
  447. * or <tt>false</tt> otherwise.
  448. */
  449. SmallVideo.prototype.isVideoPlayable = function() {
  450. return this.videoStream // Is there anything to display ?
  451. && !this.isVideoMuted && !this.videoStream.isMuted(); // Muted ?
  452. };
  453. /**
  454. * Determines what should be display on the thumbnail.
  455. *
  456. * @return {number} one of <tt>DISPLAY_VIDEO</tt>,<tt>DISPLAY_AVATAR</tt>
  457. * or <tt>DISPLAY_BLACKNESS_WITH_NAME</tt>.
  458. */
  459. SmallVideo.prototype.selectDisplayMode = function() {
  460. // Display name is always and only displayed when user is on the stage
  461. if (this.isCurrentlyOnLargeVideo()
  462. && !shouldDisplayTileView(APP.store.getState())) {
  463. return this.isVideoPlayable() && !APP.conference.isAudioOnly()
  464. ? DISPLAY_BLACKNESS_WITH_NAME : DISPLAY_AVATAR_WITH_NAME;
  465. } else if (this.isVideoPlayable()
  466. && this.selectVideoElement().length
  467. && !APP.conference.isAudioOnly()) {
  468. // check hovering and change state to video with name
  469. return this._isHovered()
  470. ? DISPLAY_VIDEO_WITH_NAME : DISPLAY_VIDEO;
  471. }
  472. // check hovering and change state to avatar with name
  473. return this._isHovered()
  474. ? DISPLAY_AVATAR_WITH_NAME : DISPLAY_AVATAR;
  475. };
  476. /**
  477. * Checks whether current video is considered hovered. Currently it is hovered
  478. * if the mouse is over the video, or if the connection
  479. * indicator is shown(hovered).
  480. * @private
  481. */
  482. SmallVideo.prototype._isHovered = function() {
  483. return this.videoIsHovered || this._popoverIsHovered;
  484. };
  485. /**
  486. * Hides or shows the user's avatar.
  487. * This update assumes that large video had been updated and we will
  488. * reflect it on this small video.
  489. *
  490. * @param show whether we should show the avatar or not
  491. * video because there is no dominant speaker and no focused speaker
  492. */
  493. SmallVideo.prototype.updateView = function() {
  494. if (this.disableUpdateView) {
  495. return;
  496. }
  497. if (!this.hasAvatar) {
  498. if (this.id) {
  499. // Init avatar
  500. this.avatarChanged(
  501. getAvatarURLByParticipantId(APP.store.getState(), this.id));
  502. } else {
  503. logger.error('Unable to init avatar - no id', this);
  504. return;
  505. }
  506. }
  507. this.$container.removeClass((index, classNames) =>
  508. classNames.split(' ').filter(name => name.startsWith('display-')));
  509. // Determine whether video, avatar or blackness should be displayed
  510. const displayMode = this.selectDisplayMode();
  511. switch (displayMode) {
  512. case DISPLAY_AVATAR_WITH_NAME:
  513. this.$container.addClass('display-avatar-with-name');
  514. break;
  515. case DISPLAY_BLACKNESS_WITH_NAME:
  516. this.$container.addClass('display-name-on-black');
  517. break;
  518. case DISPLAY_VIDEO:
  519. this.$container.addClass('display-video');
  520. break;
  521. case DISPLAY_VIDEO_WITH_NAME:
  522. this.$container.addClass('display-name-on-video');
  523. break;
  524. case DISPLAY_AVATAR:
  525. default:
  526. this.$container.addClass('display-avatar-only');
  527. break;
  528. }
  529. };
  530. /**
  531. * Updates the react component displaying the avatar with the passed in avatar
  532. * url.
  533. *
  534. * @param {string} avatarUrl - The uri to the avatar image.
  535. * @returns {void}
  536. */
  537. SmallVideo.prototype.avatarChanged = function(avatarUrl) {
  538. const thumbnail = this.$avatar().get(0);
  539. this.hasAvatar = true;
  540. if (thumbnail) {
  541. ReactDOM.render(
  542. <AvatarDisplay
  543. className = 'userAvatar'
  544. uri = { avatarUrl } />,
  545. thumbnail
  546. );
  547. }
  548. };
  549. /**
  550. * Unmounts any attached react components (particular the avatar image) from
  551. * the avatar container.
  552. *
  553. * @returns {void}
  554. */
  555. SmallVideo.prototype.removeAvatar = function() {
  556. const thumbnail = this.$avatar().get(0);
  557. if (thumbnail) {
  558. ReactDOM.unmountComponentAtNode(thumbnail);
  559. }
  560. };
  561. /**
  562. * Shows or hides the dominant speaker indicator.
  563. * @param show whether to show or hide.
  564. */
  565. SmallVideo.prototype.showDominantSpeakerIndicator = function(show) {
  566. // Don't create and show dominant speaker indicator if
  567. // DISABLE_DOMINANT_SPEAKER_INDICATOR is true
  568. if (interfaceConfig.DISABLE_DOMINANT_SPEAKER_INDICATOR) {
  569. return;
  570. }
  571. if (!this.container) {
  572. logger.warn(`Unable to set dominant speaker indicator - ${
  573. this.videoSpanId} does not exist`);
  574. return;
  575. }
  576. if (this._showDominantSpeaker === show) {
  577. return;
  578. }
  579. this._showDominantSpeaker = show;
  580. this.$container.toggleClass('active-speaker', this._showDominantSpeaker);
  581. this.updateIndicators();
  582. this.updateView();
  583. };
  584. /**
  585. * Shows or hides the raised hand indicator.
  586. * @param show whether to show or hide.
  587. */
  588. SmallVideo.prototype.showRaisedHandIndicator = function(show) {
  589. if (!this.container) {
  590. logger.warn(`Unable to raised hand indication - ${
  591. this.videoSpanId} does not exist`);
  592. return;
  593. }
  594. this._showRaisedHand = show;
  595. this.updateIndicators();
  596. };
  597. /**
  598. * Adds a listener for onresize events for this video, which will monitor for
  599. * resolution changes, will calculate the delay since the moment the listened
  600. * is added, and will fire a RESOLUTION_CHANGED event.
  601. */
  602. SmallVideo.prototype.waitForResolutionChange = function() {
  603. const beforeChange = window.performance.now();
  604. const videos = this.selectVideoElement();
  605. if (!videos || !videos.length || videos.length <= 0) {
  606. return;
  607. }
  608. const video = videos[0];
  609. const oldWidth = video.videoWidth;
  610. const oldHeight = video.videoHeight;
  611. video.onresize = () => {
  612. // eslint-disable-next-line eqeqeq
  613. if (video.videoWidth != oldWidth || video.videoHeight != oldHeight) {
  614. // Only run once.
  615. video.onresize = null;
  616. const delay = window.performance.now() - beforeChange;
  617. const emitter = this.VideoLayout.getEventEmitter();
  618. if (emitter) {
  619. emitter.emit(
  620. UIEvents.RESOLUTION_CHANGED,
  621. this.getId(),
  622. `${oldWidth}x${oldHeight}`,
  623. `${video.videoWidth}x${video.videoHeight}`,
  624. delay);
  625. }
  626. }
  627. };
  628. };
  629. /**
  630. * Initalizes any browser specific properties. Currently sets the overflow
  631. * property for Qt browsers on Windows to hidden, thus fixing the following
  632. * problem:
  633. * Some browsers don't have full support of the object-fit property for the
  634. * video element and when we set video object-fit to "cover" the video
  635. * actually overflows the boundaries of its container, so it's important
  636. * to indicate that the "overflow" should be hidden.
  637. *
  638. * Setting this property for all browsers will result in broken audio levels,
  639. * which makes this a temporary solution, before reworking audio levels.
  640. */
  641. SmallVideo.prototype.initBrowserSpecificProperties = function() {
  642. const userAgent = window.navigator.userAgent;
  643. if (userAgent.indexOf('QtWebEngine') > -1
  644. && (userAgent.indexOf('Windows') > -1
  645. || userAgent.indexOf('Linux') > -1)) {
  646. this.$container.css('overflow', 'hidden');
  647. }
  648. };
  649. /**
  650. * Cleans up components on {@code SmallVideo} and removes itself from the DOM.
  651. *
  652. * @returns {void}
  653. */
  654. SmallVideo.prototype.remove = function() {
  655. logger.log('Remove thumbnail', this.id);
  656. this.removeAudioLevelIndicator();
  657. const toolbarContainer
  658. = this.container.querySelector('.videocontainer__toolbar');
  659. if (toolbarContainer) {
  660. ReactDOM.unmountComponentAtNode(toolbarContainer);
  661. }
  662. this.removeConnectionIndicator();
  663. this.removeDisplayName();
  664. this.removeAvatar();
  665. this._unmountIndicators();
  666. // Remove whole container
  667. if (this.container.parentNode) {
  668. this.container.parentNode.removeChild(this.container);
  669. }
  670. };
  671. /**
  672. * Helper function for re-rendering multiple react components of the small
  673. * video.
  674. *
  675. * @returns {void}
  676. */
  677. SmallVideo.prototype.rerender = function() {
  678. this.updateIndicators();
  679. this.updateStatusBar();
  680. this.updateView();
  681. };
  682. /**
  683. * Updates the React element responsible for showing connection status, dominant
  684. * speaker, and raised hand icons. Uses instance variables to get the necessary
  685. * state to display. Will create the React element if not already created.
  686. *
  687. * @private
  688. * @returns {void}
  689. */
  690. SmallVideo.prototype.updateIndicators = function() {
  691. const indicatorToolbar
  692. = this.container.querySelector('.videocontainer__toptoolbar');
  693. if (!indicatorToolbar) {
  694. return;
  695. }
  696. const iconSize = UIUtil.getIndicatorFontSize();
  697. const showConnectionIndicator = this.videoIsHovered
  698. || !interfaceConfig.CONNECTION_INDICATOR_AUTO_HIDE_ENABLED;
  699. const currentLayout = getCurrentLayout(APP.store.getState());
  700. let statsPopoverPosition, tooltipPosition;
  701. if (currentLayout === LAYOUTS.TILE_VIEW) {
  702. statsPopoverPosition = 'right top';
  703. tooltipPosition = 'right';
  704. } else if (currentLayout === LAYOUTS.VERTICAL_FILMSTRIP_VIEW) {
  705. statsPopoverPosition = this.statsPopoverLocation;
  706. tooltipPosition = 'left';
  707. } else {
  708. statsPopoverPosition = this.statsPopoverLocation;
  709. tooltipPosition = 'top';
  710. }
  711. ReactDOM.render(
  712. <Provider store = { APP.store }>
  713. <I18nextProvider i18n = { i18next }>
  714. <div>
  715. <AtlasKitThemeProvider mode = 'dark'>
  716. { this._showConnectionIndicator
  717. ? <ConnectionIndicator
  718. alwaysVisible = { showConnectionIndicator }
  719. connectionStatus = { this._connectionStatus }
  720. iconSize = { iconSize }
  721. isLocalVideo = { this.isLocal }
  722. enableStatsDisplay
  723. = { !interfaceConfig.filmStripOnly }
  724. statsPopoverPosition
  725. = { statsPopoverPosition }
  726. userID = { this.id } />
  727. : null }
  728. <RaisedHandIndicator
  729. iconSize = { iconSize }
  730. participantId = { this.id }
  731. tooltipPosition = { tooltipPosition } />
  732. { this._showDominantSpeaker
  733. ? <DominantSpeakerIndicator
  734. iconSize = { iconSize }
  735. tooltipPosition = { tooltipPosition } />
  736. : null }
  737. </AtlasKitThemeProvider>
  738. </div>
  739. </I18nextProvider>
  740. </Provider>,
  741. indicatorToolbar
  742. );
  743. };
  744. /**
  745. * Callback invoked when the thumbnail is double clicked. Will pin the
  746. * participant if in tile view.
  747. *
  748. * @param {MouseEvent} event - The click event to intercept.
  749. * @private
  750. * @returns {void}
  751. */
  752. SmallVideo.prototype._onContainerDoubleClick = function(event) {
  753. if (this._pinningRequiresDoubleClick() && this._shouldTriggerPin(event)) {
  754. APP.store.dispatch(pinParticipant(this.id));
  755. }
  756. };
  757. /**
  758. * Callback invoked when the thumbnail is clicked and potentially trigger
  759. * pinning of the participant.
  760. *
  761. * @param {MouseEvent} event - The click event to intercept.
  762. * @private
  763. * @returns {void}
  764. */
  765. SmallVideo.prototype._onContainerClick = function(event) {
  766. const triggerPin = this._shouldTriggerPin(event)
  767. && !this._pinningRequiresDoubleClick();
  768. if (event.stopPropagation && triggerPin) {
  769. event.stopPropagation();
  770. event.preventDefault();
  771. }
  772. if (triggerPin) {
  773. this.togglePin();
  774. }
  775. return false;
  776. };
  777. /**
  778. * Returns whether or not a click event is targeted at certain elements which
  779. * should not trigger a pin.
  780. *
  781. * @param {MouseEvent} event - The click event to intercept.
  782. * @private
  783. * @returns {boolean}
  784. */
  785. SmallVideo.prototype._shouldTriggerPin = function(event) {
  786. // TODO Checking the classes is a workround to allow events to bubble into
  787. // the DisplayName component if it was clicked. React's synthetic events
  788. // will fire after jQuery handlers execute, so stop propogation at this
  789. // point will prevent DisplayName from getting click events. This workaround
  790. // should be removeable once LocalVideo is a React Component because then
  791. // the components share the same eventing system.
  792. const $source = $(event.target || event.srcElement);
  793. return $source.parents('.displayNameContainer').length === 0
  794. && $source.parents('.popover').length === 0
  795. && !event.target.classList.contains('popover');
  796. };
  797. /**
  798. * Pins the participant displayed by this thumbnail or unpins if already pinned.
  799. *
  800. * @returns {void}
  801. */
  802. SmallVideo.prototype.togglePin = function() {
  803. const pinnedParticipant
  804. = getPinnedParticipant(APP.store.getState()) || {};
  805. const participantIdToPin
  806. = pinnedParticipant && pinnedParticipant.id === this.id
  807. ? null : this.id;
  808. APP.store.dispatch(pinParticipant(participantIdToPin));
  809. };
  810. /**
  811. * Returns whether or not clicking to pin the participant needs to be a double
  812. * click instead of a single click.
  813. *
  814. * @private
  815. * @returns {boolean}
  816. */
  817. SmallVideo.prototype._pinningRequiresDoubleClick = function() {
  818. return shouldDisplayTileView(APP.store.getState());
  819. };
  820. /**
  821. * Removes the React element responsible for showing connection status, dominant
  822. * speaker, and raised hand icons.
  823. *
  824. * @private
  825. * @returns {void}
  826. */
  827. SmallVideo.prototype._unmountIndicators = function() {
  828. const indicatorToolbar
  829. = this.container.querySelector('.videocontainer__toptoolbar');
  830. if (indicatorToolbar) {
  831. ReactDOM.unmountComponentAtNode(indicatorToolbar);
  832. }
  833. };
  834. /**
  835. * Updates the current state of the connection indicator popover being hovered.
  836. * If hovered, display the small video as if it is hovered.
  837. *
  838. * @param {boolean} popoverIsHovered - Whether or not the mouse cursor is
  839. * currently over the connection indicator popover.
  840. * @returns {void}
  841. */
  842. SmallVideo.prototype._onPopoverHover = function(popoverIsHovered) {
  843. this._popoverIsHovered = popoverIsHovered;
  844. this.updateView();
  845. };
  846. export default SmallVideo;