您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SmallVideo.js 24KB

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