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

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