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

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