2022-10-04 10:52:09 +00:00
|
|
|
import { VIDEO_TYPE } from '../base/media/constants';
|
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
|
|
|
import { getLocalVideoTrack } from '../base/tracks/functions';
|
2021-05-14 14:53:11 +00:00
|
|
|
|
2021-07-13 13:47:23 +00:00
|
|
|
import { SET_VIRTUAL_BACKGROUND } from './actionTypes';
|
2021-05-19 09:57:11 +00:00
|
|
|
import { localTrackStopped } from './functions';
|
2021-05-14 14:53:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2021-05-14 14:53:11 +00:00
|
|
|
*
|
|
|
|
* @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']);
|
|
|
|
|
2021-07-13 13:47:23 +00:00
|
|
|
if (virtualSource?.videoType === VIDEO_TYPE.DESKTOP && action.type === SET_VIRTUAL_BACKGROUND) {
|
2021-05-26 16:01:00 +00:00
|
|
|
localTrackStopped(dispatch, virtualSource, currentLocalTrack?.jitsiTrack);
|
2021-05-14 14:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|