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

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