2022-10-21 07:33:10 +00:00
|
|
|
import { IStore } from '../app/types';
|
|
|
|
import { CONFERENCE_JOINED } from '../base/conference/actionTypes';
|
|
|
|
import { MEDIA_TYPE } from '../base/media/constants';
|
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
2021-06-28 07:48:16 +00:00
|
|
|
|
2022-08-23 12:17:18 +00:00
|
|
|
import { SET_SCREENSHARE_CAPTURE_FRAME_RATE, SET_SCREEN_AUDIO_SHARE_STATE } from './actionTypes';
|
2021-06-28 07:48:16 +00:00
|
|
|
import logger from './logger';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements the middleware of the feature screen-share.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
const result = next(action);
|
2022-08-23 12:17:18 +00:00
|
|
|
const { getState } = store;
|
|
|
|
const state = getState();
|
2021-06-28 07:48:16 +00:00
|
|
|
|
|
|
|
switch (action.type) {
|
|
|
|
case CONFERENCE_JOINED: {
|
|
|
|
_setScreenshareCaptureFps(store);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SET_SCREENSHARE_CAPTURE_FRAME_RATE: {
|
|
|
|
const { captureFrameRate } = action;
|
|
|
|
|
|
|
|
_setScreenshareCaptureFps(store, captureFrameRate);
|
|
|
|
break;
|
|
|
|
}
|
2022-08-23 12:17:18 +00:00
|
|
|
|
|
|
|
case SET_SCREEN_AUDIO_SHARE_STATE: {
|
|
|
|
const { isSharingAudio } = action;
|
|
|
|
const { participantId } = state['features/large-video'];
|
|
|
|
|
|
|
|
if (isSharingAudio) {
|
|
|
|
logger.debug(`User with id: ${participantId} playing audio sharing.`);
|
|
|
|
APP.API.notifyAudioOrVideoSharingToggled(MEDIA_TYPE.AUDIO, 'playing', participantId);
|
|
|
|
} else {
|
|
|
|
logger.debug(`User with id: ${participantId} stop audio sharing.`);
|
|
|
|
APP.API.notifyAudioOrVideoSharingToggled(MEDIA_TYPE.AUDIO, 'stop', participantId);
|
|
|
|
}
|
|
|
|
}
|
2021-06-28 07:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the capture frame rate for screenshare.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @param {number} frameRate - Frame rate to be configured.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-10-21 07:33:10 +00:00
|
|
|
function _setScreenshareCaptureFps(store: IStore, frameRate?: number) {
|
2021-06-28 07:48:16 +00:00
|
|
|
const state = store.getState();
|
|
|
|
const { conference } = state['features/base/conference'];
|
|
|
|
const { captureFrameRate } = state['features/screen-share'];
|
|
|
|
const screenShareFps = frameRate ?? captureFrameRate;
|
|
|
|
|
|
|
|
if (!conference) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (screenShareFps) {
|
|
|
|
logger.debug(`Setting screenshare capture frame rate as ${screenShareFps}`);
|
|
|
|
conference.setDesktopSharingFrameRate(screenShareFps);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|