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

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