Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

SmallVideo.js 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  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 { Provider } from 'react-redux';
  7. import { i18next } from '../../../react/features/base/i18n';
  8. import { AudioLevelIndicator }
  9. from '../../../react/features/audio-level-indicator';
  10. import {
  11. Avatar as AvatarDisplay
  12. } from '../../../react/features/base/participants';
  13. import {
  14. ConnectionIndicator
  15. } from '../../../react/features/connection-indicator';
  16. import { DisplayName } from '../../../react/features/display-name';
  17. import {
  18. AudioMutedIndicator,
  19. DominantSpeakerIndicator,
  20. ModeratorIndicator,
  21. RaisedHandIndicator,
  22. VideoMutedIndicator
  23. } from '../../../react/features/filmstrip';
  24. /* eslint-enable no-unused-vars */
  25. const logger = require("jitsi-meet-logger").getLogger(__filename);
  26. import Avatar from "../avatar/Avatar";
  27. import UIUtil from "../util/UIUtil";
  28. import UIEvents from "../../../service/UI/UIEvents";
  29. const RTCUIHelper = JitsiMeetJS.util.RTCUIHelper;
  30. /**
  31. * Display mode constant used when video is being displayed on the small video.
  32. * @type {number}
  33. * @constant
  34. */
  35. const DISPLAY_VIDEO = 0;
  36. /**
  37. * Display mode constant used when the user's avatar is being displayed on
  38. * the small video.
  39. * @type {number}
  40. * @constant
  41. */
  42. const DISPLAY_AVATAR = 1;
  43. /**
  44. * Display mode constant used when neither video nor avatar is being displayed
  45. * on the small video. And we just show the display name.
  46. * @type {number}
  47. * @constant
  48. */
  49. const DISPLAY_BLACKNESS_WITH_NAME = 2;
  50. /**
  51. * Display mode constant used when video is displayed and display name
  52. * at the same time.
  53. * @type {number}
  54. * @constant
  55. */
  56. const DISPLAY_VIDEO_WITH_NAME = 3;
  57. /**
  58. * Display mode constant used when neither video nor avatar is being displayed
  59. * on the small video. And we just show the display name.
  60. * @type {number}
  61. * @constant
  62. */
  63. const DISPLAY_AVATAR_WITH_NAME = 4;
  64. function SmallVideo(VideoLayout) {
  65. this._isModerator = false;
  66. this.isAudioMuted = false;
  67. this.hasAvatar = false;
  68. this.isVideoMuted = false;
  69. this.videoStream = null;
  70. this.audioStream = null;
  71. this.VideoLayout = VideoLayout;
  72. this.videoIsHovered = false;
  73. this.hideDisplayName = false;
  74. // we can stop updating the thumbnail
  75. this.disableUpdateView = false;
  76. /**
  77. * The current state of the user's bridge connection. The value should be
  78. * a string as enumerated in the library's participantConnectionStatus
  79. * constants.
  80. *
  81. * @private
  82. * @type {string|null}
  83. */
  84. this._connectionStatus = null;
  85. /**
  86. * Whether or not the ConnectionIndicator's popover is hovered. Modifies
  87. * how the video overlays display based on hover state.
  88. *
  89. * @private
  90. * @type {boolean}
  91. */
  92. this._popoverIsHovered = false;
  93. /**
  94. * Whether or not the connection indicator should be displayed.
  95. *
  96. * @private
  97. * @type {boolean}
  98. */
  99. this._showConnectionIndicator = true;
  100. /**
  101. * Whether or not the dominant speaker indicator should be displayed.
  102. *
  103. * @private
  104. * @type {boolean}
  105. */
  106. this._showDominantSpeaker = false;
  107. /**
  108. * Whether or not the raised hand indicator should be displayed.
  109. *
  110. * @private
  111. * @type {boolean}
  112. */
  113. this._showRaisedHand = false;
  114. // Bind event handlers so they are only bound once for every instance.
  115. this._onPopoverHover = this._onPopoverHover.bind(this);
  116. this.updateView = this.updateView.bind(this);
  117. }
  118. /**
  119. * Returns the identifier of this small video.
  120. *
  121. * @returns the identifier of this small video
  122. */
  123. SmallVideo.prototype.getId = function () {
  124. return this.id;
  125. };
  126. /* Indicates if this small video is currently visible.
  127. *
  128. * @return <tt>true</tt> if this small video isn't currently visible and
  129. * <tt>false</tt> - otherwise.
  130. */
  131. SmallVideo.prototype.isVisible = function () {
  132. return this.$container.is(':visible');
  133. };
  134. /**
  135. * Enables / disables the device availability icons for this small video.
  136. * @param {enable} set to {true} to enable and {false} to disable
  137. */
  138. SmallVideo.prototype.enableDeviceAvailabilityIcons = function (enable) {
  139. if (typeof enable === "undefined")
  140. return;
  141. this.deviceAvailabilityIconsEnabled = enable;
  142. };
  143. /**
  144. * Sets the device "non" availability icons.
  145. * @param devices the devices, which will be checked for availability
  146. */
  147. SmallVideo.prototype.setDeviceAvailabilityIcons = function (devices) {
  148. if (!this.deviceAvailabilityIconsEnabled)
  149. return;
  150. if(!this.container)
  151. return;
  152. var noMic = this.$container.find('.noMic');
  153. var noVideo = this.$container.find('.noVideo');
  154. noMic.remove();
  155. noVideo.remove();
  156. if (!devices.audio) {
  157. this.container.appendChild(
  158. document.createElement("div")).setAttribute("class", "noMic");
  159. }
  160. if (!devices.video) {
  161. this.container.appendChild(
  162. document.createElement("div")).setAttribute("class", "noVideo");
  163. }
  164. if (!devices.audio && !devices.video) {
  165. noMic.css("background-position", "75%");
  166. noVideo.css("background-position", "25%");
  167. noVideo.css("background-color", "transparent");
  168. }
  169. };
  170. /**
  171. * Sets the type of the video displayed by this instance.
  172. * Note that this is a string without clearly defined or checked values, and
  173. * it is NOT one of the strings defined in service/RTC/VideoType in
  174. * lib-jitsi-meet.
  175. * @param videoType 'camera' or 'desktop', or 'sharedvideo'.
  176. */
  177. SmallVideo.prototype.setVideoType = function (videoType) {
  178. this.videoType = videoType;
  179. };
  180. /**
  181. * Returns the type of the video displayed by this instance.
  182. * Note that this is a string without clearly defined or checked values, and
  183. * it is NOT one of the strings defined in service/RTC/VideoType in
  184. * lib-jitsi-meet.
  185. * @returns {String} 'camera', 'screen', 'sharedvideo', or undefined.
  186. */
  187. SmallVideo.prototype.getVideoType = function () {
  188. return this.videoType;
  189. };
  190. /**
  191. * Creates an audio or video element for a particular MediaStream.
  192. */
  193. SmallVideo.createStreamElement = function (stream) {
  194. let isVideo = stream.isVideoTrack();
  195. let element = isVideo
  196. ? document.createElement('video')
  197. : document.createElement('audio');
  198. if (isVideo) {
  199. element.setAttribute("muted", "true");
  200. }
  201. RTCUIHelper.setAutoPlay(element, true);
  202. element.id = SmallVideo.getStreamElementID(stream);
  203. return element;
  204. };
  205. /**
  206. * Returns the element id for a particular MediaStream.
  207. */
  208. SmallVideo.getStreamElementID = function (stream) {
  209. let isVideo = stream.isVideoTrack();
  210. return (isVideo ? 'remoteVideo_' : 'remoteAudio_') + stream.getId();
  211. };
  212. /**
  213. * Configures hoverIn/hoverOut handlers. Depends on connection indicator.
  214. */
  215. SmallVideo.prototype.bindHoverHandler = function () {
  216. // Add hover handler
  217. this.$container.hover(
  218. () => {
  219. this.videoIsHovered = true;
  220. this.updateView();
  221. this.updateIndicators();
  222. },
  223. () => {
  224. this.videoIsHovered = false;
  225. this.updateView();
  226. this.updateIndicators();
  227. }
  228. );
  229. };
  230. /**
  231. * Unmounts the ConnectionIndicator component.
  232. * @returns {void}
  233. */
  234. SmallVideo.prototype.removeConnectionIndicator = function () {
  235. this._showConnectionIndicator = false;
  236. this.updateIndicators();
  237. };
  238. /**
  239. * Updates the connectionStatus stat which displays in the ConnectionIndicator.
  240. * @returns {void}
  241. */
  242. SmallVideo.prototype.updateConnectionStatus = function (connectionStatus) {
  243. this._connectionStatus = connectionStatus;
  244. this.updateIndicators();
  245. };
  246. /**
  247. * Shows / hides the audio muted indicator over small videos.
  248. *
  249. * @param {boolean} isMuted indicates if the muted element should be shown
  250. * or hidden
  251. */
  252. SmallVideo.prototype.showAudioIndicator = function (isMuted) {
  253. this.isAudioMuted = isMuted;
  254. this.updateStatusBar();
  255. };
  256. /**
  257. * Shows video muted indicator over small videos and disables/enables avatar
  258. * if video muted.
  259. *
  260. * @param {boolean} isMuted indicates if we should set the view to muted view
  261. * or not
  262. */
  263. SmallVideo.prototype.setVideoMutedView = function(isMuted) {
  264. this.isVideoMuted = isMuted;
  265. this.updateView();
  266. this.updateStatusBar();
  267. };
  268. /**
  269. * Create or updates the ReactElement for displaying status indicators about
  270. * audio mute, video mute, and moderator status.
  271. *
  272. * @returns {void}
  273. */
  274. SmallVideo.prototype.updateStatusBar = function () {
  275. const statusBarContainer
  276. = this.container.querySelector('.videocontainer__toolbar');
  277. const tooltipPosition = interfaceConfig.VERTICAL_FILMSTRIP ? 'left' : 'top';
  278. /* jshint ignore:start */
  279. ReactDOM.render(
  280. <I18nextProvider i18n = { i18next }>
  281. <div>
  282. { this.isAudioMuted
  283. ? <AudioMutedIndicator
  284. tooltipPosition = { tooltipPosition } />
  285. : null }
  286. { this.isVideoMuted
  287. ? <VideoMutedIndicator
  288. tooltipPosition = { tooltipPosition } />
  289. : null }
  290. { this._isModerator
  291. && !interfaceConfig.DISABLE_FOCUS_INDICATOR
  292. ? <ModeratorIndicator
  293. tooltipPosition = { tooltipPosition } />
  294. : null }
  295. </div>
  296. </I18nextProvider>,
  297. statusBarContainer);
  298. /* jshint ignore:end */
  299. };
  300. /**
  301. * Adds the element indicating the moderator(owner) of the conference.
  302. */
  303. SmallVideo.prototype.addModeratorIndicator = function () {
  304. this._isModerator = true;
  305. this.updateStatusBar();
  306. };
  307. /**
  308. * Adds the element indicating the audio level of the participant.
  309. *
  310. * @returns {void}
  311. */
  312. SmallVideo.prototype.addAudioLevelIndicator = function () {
  313. let audioLevelContainer = this._getAudioLevelContainer();
  314. if (audioLevelContainer) {
  315. return;
  316. }
  317. audioLevelContainer = document.createElement('span');
  318. audioLevelContainer.className = 'audioindicator-container';
  319. this.container.appendChild(audioLevelContainer);
  320. this.updateAudioLevelIndicator();
  321. };
  322. /**
  323. * Removes the element indicating the audio level of the participant.
  324. *
  325. * @returns {void}
  326. */
  327. SmallVideo.prototype.removeAudioLevelIndicator = function () {
  328. const audioLevelContainer = this._getAudioLevelContainer();
  329. if (audioLevelContainer) {
  330. ReactDOM.unmountComponentAtNode(audioLevelContainer);
  331. }
  332. };
  333. /**
  334. * Updates the audio level for this small video.
  335. *
  336. * @param lvl the new audio level to set
  337. * @returns {void}
  338. */
  339. SmallVideo.prototype.updateAudioLevelIndicator = function (lvl = 0) {
  340. const audioLevelContainer = this._getAudioLevelContainer();
  341. if (audioLevelContainer) {
  342. /* jshint ignore:start */
  343. ReactDOM.render(
  344. <AudioLevelIndicator
  345. audioLevel = { lvl }/>,
  346. audioLevelContainer);
  347. /* jshint ignore:end */
  348. }
  349. };
  350. /**
  351. * Queries the component's DOM for the element that should be the parent to the
  352. * AudioLevelIndicator.
  353. *
  354. * @returns {HTMLElement} The DOM element that holds the AudioLevelIndicator.
  355. */
  356. SmallVideo.prototype._getAudioLevelContainer = function () {
  357. return this.container.querySelector('.audioindicator-container');
  358. };
  359. /**
  360. * Removes the element indicating the moderator(owner) of the conference.
  361. */
  362. SmallVideo.prototype.removeModeratorIndicator = function () {
  363. this._isModerator = false;
  364. this.updateStatusBar();
  365. };
  366. /**
  367. * This is an especially interesting function. A naive reader might think that
  368. * it returns this SmallVideo's "video" element. But it is much more exciting.
  369. * It first finds this video's parent element using jquery, then uses a utility
  370. * from lib-jitsi-meet to extract the video element from it (with two more
  371. * jquery calls), and finally uses jquery again to encapsulate the video element
  372. * in an array. This last step allows (some might prefer "forces") users of
  373. * this function to access the video element via the 0th element of the returned
  374. * array (after checking its length of course!).
  375. */
  376. SmallVideo.prototype.selectVideoElement = function () {
  377. return $(RTCUIHelper.findVideoElement(this.container));
  378. };
  379. /**
  380. * Selects the HTML image element which displays user's avatar.
  381. *
  382. * @return {jQuery|HTMLElement} a jQuery selector pointing to the HTML image
  383. * element which displays the user's avatar.
  384. */
  385. SmallVideo.prototype.$avatar = function () {
  386. return this.$container.find('.avatar-container');
  387. };
  388. /**
  389. * Returns the display name element, which appears on the video thumbnail.
  390. *
  391. * @return {jQuery} a jQuery selector pointing to the display name element of
  392. * the video thumbnail
  393. */
  394. SmallVideo.prototype.$displayName = function () {
  395. return this.$container.find('.displayNameContainer');
  396. };
  397. /**
  398. * Creates or updates the participant's display name that is shown over the
  399. * video preview.
  400. *
  401. * @returns {void}
  402. */
  403. SmallVideo.prototype.updateDisplayName = function (props) {
  404. const displayNameContainer
  405. = this.container.querySelector('.displayNameContainer');
  406. if (displayNameContainer) {
  407. /* jshint ignore:start */
  408. ReactDOM.render(
  409. <Provider store = { APP.store }>
  410. <I18nextProvider i18n = { i18next }>
  411. <DisplayName { ...props } />
  412. </I18nextProvider>
  413. </Provider>,
  414. displayNameContainer);
  415. /* jshint ignore:end */
  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. var focusedCssClass = "videoContainerFocused";
  439. var isFocusClassEnabled = this.$container.hasClass(focusedCssClass);
  440. if (!isFocused && isFocusClassEnabled) {
  441. this.$container.removeClass(focusedCssClass);
  442. }
  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 DISPLAY_BLACKNESS_WITH_NAME;
  481. } else if (this.isVideoPlayable()
  482. && this.selectVideoElement().length
  483. && !APP.conference.isAudioOnly()) {
  484. // check hovering and change state to video with name
  485. return this._isHovered() ?
  486. DISPLAY_VIDEO_WITH_NAME : DISPLAY_VIDEO;
  487. } else {
  488. // check hovering and change state to avatar with name
  489. return this._isHovered() ?
  490. DISPLAY_AVATAR_WITH_NAME : DISPLAY_AVATAR;
  491. }
  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. if (!this.hasAvatar) {
  514. if (this.id) {
  515. // Init avatar
  516. this.avatarChanged(Avatar.getAvatarUrl(this.id));
  517. } else {
  518. logger.error("Unable to init avatar - no id", this);
  519. return;
  520. }
  521. }
  522. // Determine whether video, avatar or blackness should be displayed
  523. let displayMode = this.selectDisplayMode();
  524. // Show/hide video.
  525. UIUtil.setVisibleBySelector(this.selectVideoElement(),
  526. (displayMode === DISPLAY_VIDEO
  527. || displayMode === DISPLAY_VIDEO_WITH_NAME));
  528. // Show/hide the avatar.
  529. UIUtil.setVisibleBySelector(this.$avatar(),
  530. (displayMode === DISPLAY_AVATAR
  531. || displayMode === DISPLAY_AVATAR_WITH_NAME));
  532. // Show/hide the display name.
  533. UIUtil.setVisibleBySelector(this.$displayName(),
  534. !this.hideDisplayName
  535. && (displayMode === DISPLAY_BLACKNESS_WITH_NAME
  536. || displayMode === DISPLAY_VIDEO_WITH_NAME
  537. || displayMode === DISPLAY_AVATAR_WITH_NAME));
  538. // show hide overlay when there is a video or avatar under
  539. // the display name
  540. UIUtil.setVisibleBySelector(this.$container.find(
  541. '.videocontainer__hoverOverlay'),
  542. (displayMode === DISPLAY_AVATAR_WITH_NAME
  543. || displayMode === DISPLAY_VIDEO_WITH_NAME));
  544. };
  545. /**
  546. * Updates the react component displaying the avatar with the passed in avatar
  547. * url.
  548. *
  549. * @param {string} avatarUrl - The uri to the avatar image.
  550. * @returns {void}
  551. */
  552. SmallVideo.prototype.avatarChanged = function (avatarUrl) {
  553. const thumbnail = this.$avatar().get(0);
  554. this.hasAvatar = true;
  555. if (thumbnail) {
  556. /* jshint ignore:start */
  557. ReactDOM.render(
  558. <AvatarDisplay
  559. className = 'userAvatar'
  560. uri = { avatarUrl } />,
  561. thumbnail
  562. );
  563. /* jshint ignore:end */
  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. if (!this.container) {
  588. logger.warn( "Unable to set dominant speaker indicator - "
  589. + this.videoSpanId + " does not exist");
  590. return;
  591. }
  592. this._showDominantSpeaker = show;
  593. this.updateIndicators();
  594. };
  595. /**
  596. * Shows or hides the raised hand indicator.
  597. * @param show whether to show or hide.
  598. */
  599. SmallVideo.prototype.showRaisedHandIndicator = function (show) {
  600. if (!this.container) {
  601. logger.warn( "Unable to raised hand indication - "
  602. + this.videoSpanId + " does not exist");
  603. return;
  604. }
  605. this._showRaisedHand = show;
  606. this.updateIndicators();
  607. };
  608. /**
  609. * Adds a listener for onresize events for this video, which will monitor for
  610. * resolution changes, will calculate the delay since the moment the listened
  611. * is added, and will fire a RESOLUTION_CHANGED event.
  612. */
  613. SmallVideo.prototype.waitForResolutionChange = function() {
  614. let beforeChange = window.performance.now();
  615. let videos = this.selectVideoElement();
  616. if (!videos || !videos.length || videos.length <= 0)
  617. return;
  618. let video = videos[0];
  619. let oldWidth = video.videoWidth;
  620. let oldHeight = video.videoHeight;
  621. video.onresize = () => {
  622. if (video.videoWidth != oldWidth || video.videoHeight != oldHeight) {
  623. // Only run once.
  624. video.onresize = null;
  625. let delay = window.performance.now() - beforeChange;
  626. let 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. var 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. /* jshint ignore:start */
  674. ReactDOM.render(
  675. <I18nextProvider i18n = { i18next }>
  676. <div>
  677. { this._showConnectionIndicator
  678. ? <ConnectionIndicator
  679. alwaysVisible = { showConnectionIndicator }
  680. connectionStatus = { this._connectionStatus }
  681. iconSize = { iconSize }
  682. isLocalVideo = { this.isLocal }
  683. enableStatsDisplay = { !interfaceConfig.filmStripOnly }
  684. statsPopoverPosition = { this.statsPopoverLocation }
  685. userID = { this.id } />
  686. : null }
  687. { this._showRaisedHand
  688. ? <RaisedHandIndicator
  689. iconSize = { iconSize }
  690. tooltipPosition = { tooltipPosition } />
  691. : null }
  692. { this._showDominantSpeaker
  693. ? <DominantSpeakerIndicator
  694. iconSize = { iconSize }
  695. tooltipPosition = { tooltipPosition } />
  696. : null }
  697. </div>
  698. </I18nextProvider>,
  699. indicatorToolbar
  700. );
  701. /* jshint ignore:end */
  702. };
  703. /**
  704. * Removes the React element responsible for showing connection status, dominant
  705. * speaker, and raised hand icons.
  706. *
  707. * @private
  708. * @returns {void}
  709. */
  710. SmallVideo.prototype._unmountIndicators = function () {
  711. const indicatorToolbar
  712. = this.container.querySelector('.videocontainer__toptoolbar');
  713. if (indicatorToolbar) {
  714. ReactDOM.unmountComponentAtNode(indicatorToolbar);
  715. }
  716. };
  717. /**
  718. * Updates the current state of the connection indicator popover being hovered.
  719. * If hovered, display the small video as if it is hovered.
  720. *
  721. * @param {boolean} popoverIsHovered - Whether or not the mouse cursor is
  722. * currently over the connection indicator popover.
  723. * @returns {void}
  724. */
  725. SmallVideo.prototype._onPopoverHover = function (popoverIsHovered) {
  726. this._popoverIsHovered = popoverIsHovered;
  727. this.updateView();
  728. };
  729. export default SmallVideo;