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.

middleware.ts 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { IStore } from '../app/types';
  2. import { CONFERENCE_JOINED } from '../base/conference/actionTypes';
  3. import { MEDIA_TYPE } from '../base/media/constants';
  4. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  5. import { SET_SCREENSHARE_CAPTURE_FRAME_RATE, SET_SCREEN_AUDIO_SHARE_STATE } from './actionTypes';
  6. import logger from './logger';
  7. /**
  8. * Implements the middleware of the feature screen-share.
  9. *
  10. * @param {Store} store - The redux store.
  11. * @returns {Function}
  12. */
  13. MiddlewareRegistry.register(store => next => action => {
  14. const result = next(action);
  15. const { getState } = store;
  16. const state = getState();
  17. switch (action.type) {
  18. case CONFERENCE_JOINED: {
  19. _setScreenshareCaptureFps(store);
  20. break;
  21. }
  22. case SET_SCREENSHARE_CAPTURE_FRAME_RATE: {
  23. const { captureFrameRate } = action;
  24. _setScreenshareCaptureFps(store, captureFrameRate);
  25. break;
  26. }
  27. case SET_SCREEN_AUDIO_SHARE_STATE: {
  28. const { isSharingAudio } = action;
  29. const { participantId } = state['features/large-video'];
  30. if (isSharingAudio) {
  31. logger.debug(`User with id: ${participantId} playing audio sharing.`);
  32. APP.API.notifyAudioOrVideoSharingToggled(MEDIA_TYPE.AUDIO, 'playing', participantId);
  33. } else {
  34. logger.debug(`User with id: ${participantId} stop audio sharing.`);
  35. APP.API.notifyAudioOrVideoSharingToggled(MEDIA_TYPE.AUDIO, 'stop', participantId);
  36. }
  37. }
  38. }
  39. return result;
  40. });
  41. /**
  42. * Sets the capture frame rate for screenshare.
  43. *
  44. * @param {Store} store - The redux store.
  45. * @param {number} frameRate - Frame rate to be configured.
  46. * @private
  47. * @returns {void}
  48. */
  49. function _setScreenshareCaptureFps(store: IStore, frameRate?: number) {
  50. const state = store.getState();
  51. const { conference } = state['features/base/conference'];
  52. const { captureFrameRate } = state['features/screen-share'];
  53. const screenShareFps = frameRate ?? captureFrameRate;
  54. if (!conference) {
  55. return;
  56. }
  57. if (screenShareFps) {
  58. logger.debug(`Setting screenshare capture frame rate as ${screenShareFps}`);
  59. conference.setDesktopSharingFrameRate(screenShareFps);
  60. }
  61. }