Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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.$container.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.$container.find('.noMic');
  153. var noVideo = this.$container.find('.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. this.updateIndicators();
  222. },
  223. () => {
  224. this.videoIsHovered = false;
  225. this.updateView();
  226. this.updateIndicators();
  227. }
  228. );
  229. };
  230. /**
  231. * Unmounts the ConnectionIndicator component.
  232. * @returns {void}
  233. */
  234. SmallVideo.prototype.removeConnectionIndicator = function () {
  235. this._showConnectionIndicator = false;
  236. this.updateIndicators();
  237. };
  238. /**
  239. * Updates the connectionStatus stat which displays in the ConnectionIndicator.
  240. * @returns {void}
  241. */
  242. SmallVideo.prototype.updateConnectionStatus = function (connectionStatus) {
  243. this._connectionStatus = connectionStatus;
  244. this.updateIndicators();
  245. };
  246. /**
  247. * Shows / hides the audio muted indicator over small videos.
  248. *
  249. * @param {boolean} isMuted indicates if the muted element should be shown
  250. * or hidden
  251. */
  252. SmallVideo.prototype.showAudioIndicator = function (isMuted) {
  253. this.isAudioMuted = isMuted;
  254. this.updateStatusBar();
  255. };
  256. /**
  257. * Shows video muted indicator over small videos and disables/enables avatar
  258. * if video muted.
  259. *
  260. * @param {boolean} isMuted indicates if we should set the view to muted view
  261. * or not
  262. */
  263. SmallVideo.prototype.setVideoMutedView = function(isMuted) {
  264. this.isVideoMuted = isMuted;
  265. this.updateView();
  266. this.updateStatusBar();
  267. };
  268. /**
  269. * Create or updates the ReactElement for displaying status indicators about
  270. * audio mute, video mute, and moderator status.
  271. *
  272. * @returns {void}
  273. */
  274. SmallVideo.prototype.updateStatusBar = function () {
  275. const statusBarContainer
  276. = this.container.querySelector('.videocontainer__toolbar');
  277. const tooltipPosition = interfaceConfig.VERTICAL_FILMSTRIP ? 'left' : 'top';
  278. /* jshint ignore:start */
  279. ReactDOM.render(
  280. <I18nextProvider i18n = { i18next }>
  281. <div>
  282. { this.isAudioMuted
  283. ? <AudioMutedIndicator
  284. tooltipPosition = { tooltipPosition } />
  285. : null }
  286. { this.isVideoMuted
  287. ? <VideoMutedIndicator
  288. tooltipPosition = { tooltipPosition } />
  289. : null }
  290. { this._isModerator && !interfaceConfig.DISABLE_FOCUS_INDICATOR
  291. ? <ModeratorIndicator
  292. tooltipPosition = { tooltipPosition } />
  293. : null }
  294. </div>
  295. </I18nextProvider>,
  296. statusBarContainer);
  297. /* jshint ignore:end */
  298. };
  299. /**
  300. * Adds the element indicating the moderator(owner) of the conference.
  301. */
  302. SmallVideo.prototype.addModeratorIndicator = function () {
  303. this._isModerator = true;
  304. this.updateStatusBar();
  305. };
  306. /**
  307. * Adds the element indicating the audio level of the participant.
  308. *
  309. * @returns {void}
  310. */
  311. SmallVideo.prototype.addAudioLevelIndicator = function () {
  312. let audioLevelContainer = this._getAudioLevelContainer();
  313. if (audioLevelContainer) {
  314. return;
  315. }
  316. audioLevelContainer = document.createElement('span');
  317. audioLevelContainer.className = 'audioindicator-container';
  318. this.container.appendChild(audioLevelContainer);
  319. this.updateAudioLevelIndicator();
  320. };
  321. /**
  322. * Removes the element indicating the audio level of the participant.
  323. *
  324. * @returns {void}
  325. */
  326. SmallVideo.prototype.removeAudioLevelIndicator = function () {
  327. const audioLevelContainer = this._getAudioLevelContainer();
  328. if (audioLevelContainer) {
  329. ReactDOM.unmountComponentAtNode(audioLevelContainer);
  330. }
  331. };
  332. /**
  333. * Updates the audio level for this small video.
  334. *
  335. * @param lvl the new audio level to set
  336. * @returns {void}
  337. */
  338. SmallVideo.prototype.updateAudioLevelIndicator = function (lvl = 0) {
  339. const audioLevelContainer = this._getAudioLevelContainer();
  340. if (audioLevelContainer) {
  341. /* jshint ignore:start */
  342. ReactDOM.render(
  343. <AudioLevelIndicator
  344. audioLevel = { lvl }/>,
  345. audioLevelContainer);
  346. /* jshint ignore:end */
  347. }
  348. };
  349. /**
  350. * Queries the component's DOM for the element that should be the parent to the
  351. * AudioLevelIndicator.
  352. *
  353. * @returns {HTMLElement} The DOM element that holds the AudioLevelIndicator.
  354. */
  355. SmallVideo.prototype._getAudioLevelContainer = function () {
  356. return this.container.querySelector('.audioindicator-container');
  357. };
  358. /**
  359. * Removes the element indicating the moderator(owner) of the conference.
  360. */
  361. SmallVideo.prototype.removeModeratorIndicator = function () {
  362. this._isModerator = false;
  363. this.updateStatusBar();
  364. };
  365. /**
  366. * This is an especially interesting function. A naive reader might think that
  367. * it returns this SmallVideo's "video" element. But it is much more exciting.
  368. * It first finds this video's parent element using jquery, then uses a utility
  369. * from lib-jitsi-meet to extract the video element from it (with two more
  370. * jquery calls), and finally uses jquery again to encapsulate the video element
  371. * in an array. This last step allows (some might prefer "forces") users of
  372. * this function to access the video element via the 0th element of the returned
  373. * array (after checking its length of course!).
  374. */
  375. SmallVideo.prototype.selectVideoElement = function () {
  376. return $(RTCUIHelper.findVideoElement(this.container));
  377. };
  378. /**
  379. * Selects the HTML image element which displays user's avatar.
  380. *
  381. * @return {jQuery|HTMLElement} a jQuery selector pointing to the HTML image
  382. * element which displays the user's avatar.
  383. */
  384. SmallVideo.prototype.$avatar = function () {
  385. return this.$container.find('.avatar-container');
  386. };
  387. /**
  388. * Returns the display name element, which appears on the video thumbnail.
  389. *
  390. * @return {jQuery} a jQuery selector pointing to the display name element of
  391. * the video thumbnail
  392. */
  393. SmallVideo.prototype.$displayName = function () {
  394. return this.$container.find('.displayNameContainer');
  395. };
  396. /**
  397. * Creates or updates the participant's display name that is shown over the
  398. * video preview.
  399. *
  400. * @returns {void}
  401. */
  402. SmallVideo.prototype.updateDisplayName = function (props) {
  403. const displayNameContainer
  404. = this.container.querySelector('.displayNameContainer');
  405. if (displayNameContainer) {
  406. /* jshint ignore:start */
  407. ReactDOM.render(
  408. <Provider store = { APP.store }>
  409. <I18nextProvider i18n = { i18next }>
  410. <DisplayName { ...props } />
  411. </I18nextProvider>
  412. </Provider>,
  413. displayNameContainer);
  414. /* jshint ignore:end */
  415. }
  416. };
  417. /**
  418. * Removes the component responsible for showing the participant's display name,
  419. * if its container is present.
  420. *
  421. * @returns {void}
  422. */
  423. SmallVideo.prototype.removeDisplayName = function () {
  424. const displayNameContainer
  425. = this.container.querySelector('.displayNameContainer');
  426. if (displayNameContainer) {
  427. ReactDOM.unmountComponentAtNode(displayNameContainer);
  428. }
  429. };
  430. /**
  431. * Enables / disables the css responsible for focusing/pinning a video
  432. * thumbnail.
  433. *
  434. * @param isFocused indicates if the thumbnail should be focused/pinned or not
  435. */
  436. SmallVideo.prototype.focus = function(isFocused) {
  437. var focusedCssClass = "videoContainerFocused";
  438. var isFocusClassEnabled = this.$container.hasClass(focusedCssClass);
  439. if (!isFocused && isFocusClassEnabled) {
  440. this.$container.removeClass(focusedCssClass);
  441. }
  442. else if (isFocused && !isFocusClassEnabled) {
  443. this.$container.addClass(focusedCssClass);
  444. }
  445. };
  446. SmallVideo.prototype.hasVideo = function () {
  447. return this.selectVideoElement().length !== 0;
  448. };
  449. /**
  450. * Checks whether the user associated with this <tt>SmallVideo</tt> is currently
  451. * being displayed on the "large video".
  452. *
  453. * @return {boolean} <tt>true</tt> if the user is displayed on the large video
  454. * or <tt>false</tt> otherwise.
  455. */
  456. SmallVideo.prototype.isCurrentlyOnLargeVideo = function () {
  457. return this.VideoLayout.isCurrentlyOnLarge(this.id);
  458. };
  459. /**
  460. * Checks whether there is a playable video stream available for the user
  461. * associated with this <tt>SmallVideo</tt>.
  462. *
  463. * @return {boolean} <tt>true</tt> if there is a playable video stream available
  464. * or <tt>false</tt> otherwise.
  465. */
  466. SmallVideo.prototype.isVideoPlayable = function() {
  467. return this.videoStream // Is there anything to display ?
  468. && !this.isVideoMuted && !this.videoStream.isMuted(); // Muted ?
  469. };
  470. /**
  471. * Determines what should be display on the thumbnail.
  472. *
  473. * @return {number} one of <tt>DISPLAY_VIDEO</tt>,<tt>DISPLAY_AVATAR</tt>
  474. * or <tt>DISPLAY_BLACKNESS_WITH_NAME</tt>.
  475. */
  476. SmallVideo.prototype.selectDisplayMode = function() {
  477. // Display name is always and only displayed when user is on the stage
  478. if (this.isCurrentlyOnLargeVideo()) {
  479. return DISPLAY_BLACKNESS_WITH_NAME;
  480. } else if (this.isVideoPlayable()
  481. && this.selectVideoElement().length
  482. && !APP.conference.isAudioOnly()) {
  483. // check hovering and change state to video with name
  484. return this._isHovered() ?
  485. DISPLAY_VIDEO_WITH_NAME : DISPLAY_VIDEO;
  486. } else {
  487. // check hovering and change state to avatar with name
  488. return this._isHovered() ?
  489. DISPLAY_AVATAR_WITH_NAME : DISPLAY_AVATAR;
  490. }
  491. };
  492. /**
  493. * Checks whether current video is considered hovered. Currently it is hovered
  494. * if the mouse is over the video, or if the connection
  495. * indicator is shown(hovered).
  496. * @private
  497. */
  498. SmallVideo.prototype._isHovered = function () {
  499. return this.videoIsHovered || this._popoverIsHovered;
  500. };
  501. /**
  502. * Hides or shows the user's avatar.
  503. * This update assumes that large video had been updated and we will
  504. * reflect it on this small video.
  505. *
  506. * @param show whether we should show the avatar or not
  507. * video because there is no dominant speaker and no focused speaker
  508. */
  509. SmallVideo.prototype.updateView = function () {
  510. if (this.disableUpdateView)
  511. return;
  512. if (!this.hasAvatar) {
  513. if (this.id) {
  514. // Init avatar
  515. this.avatarChanged(Avatar.getAvatarUrl(this.id));
  516. } else {
  517. logger.error("Unable to init avatar - no id", this);
  518. return;
  519. }
  520. }
  521. // Determine whether video, avatar or blackness should be displayed
  522. let displayMode = this.selectDisplayMode();
  523. // Show/hide video.
  524. UIUtil.setVisibleBySelector(this.selectVideoElement(),
  525. (displayMode === DISPLAY_VIDEO
  526. || displayMode === DISPLAY_VIDEO_WITH_NAME));
  527. // Show/hide the avatar.
  528. UIUtil.setVisibleBySelector(this.$avatar(),
  529. (displayMode === DISPLAY_AVATAR
  530. || displayMode === DISPLAY_AVATAR_WITH_NAME));
  531. // Show/hide the display name.
  532. UIUtil.setVisibleBySelector(this.$displayName(),
  533. !this.hideDisplayName
  534. && (displayMode === DISPLAY_BLACKNESS_WITH_NAME
  535. || displayMode === DISPLAY_VIDEO_WITH_NAME
  536. || displayMode === DISPLAY_AVATAR_WITH_NAME));
  537. // show hide overlay when there is a video or avatar under
  538. // the display name
  539. UIUtil.setVisibleBySelector(this.$container.find(
  540. '.videocontainer__hoverOverlay'),
  541. (displayMode === DISPLAY_AVATAR_WITH_NAME
  542. || displayMode === DISPLAY_VIDEO_WITH_NAME));
  543. };
  544. /**
  545. * Updates the react component displaying the avatar with the passed in avatar
  546. * url.
  547. *
  548. * @param {string} avatarUrl - The uri to the avatar image.
  549. * @returns {void}
  550. */
  551. SmallVideo.prototype.avatarChanged = function (avatarUrl) {
  552. const thumbnail = this.$avatar().get(0);
  553. this.hasAvatar = true;
  554. if (thumbnail) {
  555. /* jshint ignore:start */
  556. ReactDOM.render(
  557. <AvatarDisplay
  558. className = 'userAvatar'
  559. uri = { avatarUrl } />,
  560. thumbnail
  561. );
  562. /* jshint ignore:end */
  563. }
  564. };
  565. /**
  566. * Unmounts any attached react components (particular the avatar image) from
  567. * the avatar container.
  568. *
  569. * @returns {void}
  570. */
  571. SmallVideo.prototype.removeAvatar = function () {
  572. const thumbnail = this.$avatar().get(0);
  573. if (thumbnail) {
  574. ReactDOM.unmountComponentAtNode(thumbnail);
  575. }
  576. };
  577. /**
  578. * Shows or hides the dominant speaker indicator.
  579. * @param show whether to show or hide.
  580. */
  581. SmallVideo.prototype.showDominantSpeakerIndicator = function (show) {
  582. // Don't create and show dominant speaker indicator if
  583. // DISABLE_DOMINANT_SPEAKER_INDICATOR is true
  584. if (interfaceConfig.DISABLE_DOMINANT_SPEAKER_INDICATOR)
  585. return;
  586. if (!this.container) {
  587. logger.warn( "Unable to set dominant speaker indicator - "
  588. + this.videoSpanId + " does not exist");
  589. return;
  590. }
  591. this._showDominantSpeaker = show;
  592. this.updateIndicators();
  593. };
  594. /**
  595. * Shows or hides the raised hand indicator.
  596. * @param show whether to show or hide.
  597. */
  598. SmallVideo.prototype.showRaisedHandIndicator = function (show) {
  599. if (!this.container) {
  600. logger.warn( "Unable to raised hand indication - "
  601. + this.videoSpanId + " does not exist");
  602. return;
  603. }
  604. this._showRaisedHand = show;
  605. this.updateIndicators();
  606. };
  607. /**
  608. * Adds a listener for onresize events for this video, which will monitor for
  609. * resolution changes, will calculate the delay since the moment the listened
  610. * is added, and will fire a RESOLUTION_CHANGED event.
  611. */
  612. SmallVideo.prototype.waitForResolutionChange = function() {
  613. let beforeChange = window.performance.now();
  614. let videos = this.selectVideoElement();
  615. if (!videos || !videos.length || videos.length <= 0)
  616. return;
  617. let video = videos[0];
  618. let oldWidth = video.videoWidth;
  619. let oldHeight = video.videoHeight;
  620. video.onresize = () => {
  621. if (video.videoWidth != oldWidth || video.videoHeight != oldHeight) {
  622. // Only run once.
  623. video.onresize = null;
  624. let delay = window.performance.now() - beforeChange;
  625. let emitter = this.VideoLayout.getEventEmitter();
  626. if (emitter) {
  627. emitter.emit(
  628. UIEvents.RESOLUTION_CHANGED,
  629. this.getId(),
  630. oldWidth + "x" + oldHeight,
  631. video.videoWidth + "x" + video.videoHeight,
  632. delay);
  633. }
  634. }
  635. };
  636. };
  637. /**
  638. * Initalizes any browser specific properties. Currently sets the overflow
  639. * property for Qt browsers on Windows to hidden, thus fixing the following
  640. * problem:
  641. * Some browsers don't have full support of the object-fit property for the
  642. * video element and when we set video object-fit to "cover" the video
  643. * actually overflows the boundaries of its container, so it's important
  644. * to indicate that the "overflow" should be hidden.
  645. *
  646. * Setting this property for all browsers will result in broken audio levels,
  647. * which makes this a temporary solution, before reworking audio levels.
  648. */
  649. SmallVideo.prototype.initBrowserSpecificProperties = function() {
  650. var userAgent = window.navigator.userAgent;
  651. if (userAgent.indexOf("QtWebEngine") > -1
  652. && (userAgent.indexOf("Windows") > -1
  653. || userAgent.indexOf("Linux") > -1)) {
  654. this.$container.css("overflow", "hidden");
  655. }
  656. };
  657. /**
  658. * Updates the React element responsible for showing connection status, dominant
  659. * speaker, and raised hand icons. Uses instance variables to get the necessary
  660. * state to display. Will create the React element if not already created.
  661. *
  662. * @private
  663. * @returns {void}
  664. */
  665. SmallVideo.prototype.updateIndicators = function () {
  666. const indicatorToolbar
  667. = this.container.querySelector('.videocontainer__toptoolbar');
  668. const iconSize = UIUtil.getIndicatorFontSize();
  669. const showConnectionIndicator = this.videoIsHovered
  670. || !interfaceConfig.CONNECTION_INDICATOR_AUTO_HIDE_ENABLED;
  671. const tooltipPosition = interfaceConfig.VERTICAL_FILMSTRIP ? 'left' : 'top';
  672. /* jshint ignore:start */
  673. ReactDOM.render(
  674. <I18nextProvider i18n = { i18next }>
  675. <div>
  676. { this._showConnectionIndicator
  677. ? <ConnectionIndicator
  678. alwaysVisible = { showConnectionIndicator }
  679. connectionStatus = { this._connectionStatus }
  680. iconSize = { iconSize }
  681. isLocalVideo = { this.isLocal }
  682. enableStatsDisplay = { !interfaceConfig.filmStripOnly }
  683. statsPopoverPosition = { this.statsPopoverLocation }
  684. userID = { this.id } />
  685. : null }
  686. { this._showRaisedHand
  687. ? <RaisedHandIndicator
  688. iconSize = { iconSize }
  689. tooltipPosition = { tooltipPosition } />
  690. : null }
  691. { this._showDominantSpeaker
  692. ? <DominantSpeakerIndicator
  693. iconSize = { iconSize }
  694. tooltipPosition = { tooltipPosition } />
  695. : null }
  696. </div>
  697. </I18nextProvider>,
  698. indicatorToolbar
  699. );
  700. /* jshint ignore:end */
  701. };
  702. /**
  703. * Removes the React element responsible for showing connection status, dominant
  704. * speaker, and raised hand icons.
  705. *
  706. * @private
  707. * @returns {void}
  708. */
  709. SmallVideo.prototype._unmountIndicators = function () {
  710. const indicatorToolbar
  711. = this.container.querySelector('.videocontainer__toptoolbar');
  712. if (indicatorToolbar) {
  713. ReactDOM.unmountComponentAtNode(indicatorToolbar);
  714. }
  715. };
  716. /**
  717. * Updates the current state of the connection indicator popover being hovered.
  718. * If hovered, display the small video as if it is hovered.
  719. *
  720. * @param {boolean} popoverIsHovered - Whether or not the mouse cursor is
  721. * currently over the connection indicator popover.
  722. * @returns {void}
  723. */
  724. SmallVideo.prototype._onPopoverHover = function (popoverIsHovered) {
  725. this._popoverIsHovered = popoverIsHovered;
  726. this.updateView();
  727. };
  728. export default SmallVideo;