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

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