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

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