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

middleware.js 2.1KB

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