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

SmallVideo.js 24KB

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