jiti-meet/react/features/virtual-background/middleware.ts

27 lines
1.0 KiB
TypeScript
Raw Normal View History

import { VIDEO_TYPE } from '../base/media/constants';
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
import { getLocalVideoTrack } from '../base/tracks/functions';
import { SET_VIRTUAL_BACKGROUND } from './actionTypes';
import { localTrackStopped } from './functions';
/**
* Middleware which intercepts the desktop video type on
* virtual background. If the user stops the screen share
2021-11-04 21:10:43 +00:00
* then the default virtual background is set to 'none' option.
*
* @param {Store} store - The redux store.
* @returns {Function}
*/
MiddlewareRegistry.register(store => next => action => {
const { dispatch, getState } = store;
const virtualSource = getState()['features/virtual-background'].virtualSource;
const currentLocalTrack = getLocalVideoTrack(getState()['features/base/tracks']);
if (virtualSource?.videoType === VIDEO_TYPE.DESKTOP && action.type === SET_VIRTUAL_BACKGROUND) {
localTrackStopped(dispatch, virtualSource, currentLocalTrack?.jitsiTrack);
}
return next(action);
});