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.

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