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

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