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

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