jiti-meet/react/features/prejoin/middleware.js

96 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-04-16 10:47:10 +00:00
// @flow
import { CONFERENCE_FAILED, CONFERENCE_JOINED } from '../base/conference';
import { SET_AUDIO_MUTED, SET_VIDEO_MUTED } from '../base/media';
2020-05-20 10:57:03 +00:00
import { MiddlewareRegistry } from '../base/redux';
import { updateSettings } from '../base/settings';
import {
TRACK_ADDED,
TRACK_NO_DATA_FROM_SOURCE
} from '../base/tracks';
2020-05-20 10:57:03 +00:00
import {
setDeviceStatusOk,
setDeviceStatusWarning,
setJoiningInProgress,
setPrejoinPageVisibility
} from './actions';
import { PREJOIN_SCREEN_STATES } from './constants';
import { isPrejoinPageVisible } from './functions';
2020-04-16 10:47:10 +00:00
declare var APP: Object;
/**
* The redux middleware for {@link PrejoinPage}.
*
* @param {Store} store - The redux store.
* @returns {Function}
*/
MiddlewareRegistry.register(store => next => async action => {
switch (action.type) {
case SET_AUDIO_MUTED: {
if (isPrejoinPageVisible(store.getState())) {
store.dispatch(updateSettings({
startWithAudioMuted: Boolean(action.muted)
}));
}
break;
}
case SET_VIDEO_MUTED: {
if (isPrejoinPageVisible(store.getState())) {
store.dispatch(updateSettings({
startWithVideoMuted: Boolean(action.muted)
}));
}
break;
2020-04-16 10:47:10 +00:00
}
case TRACK_ADDED:
case TRACK_NO_DATA_FROM_SOURCE: {
const state = store.getState();
if (isPrejoinPageVisible(state)) {
const { track: { jitsiTrack: track } } = action;
const { deviceStatusType, deviceStatusText } = state['features/prejoin'];
if (!track.isAudioTrack()) {
break;
}
if (track.isReceivingData()) {
if (deviceStatusType === 'warning'
&& deviceStatusText === 'prejoin.audioDeviceProblem') {
store.dispatch(setDeviceStatusOk('prejoin.lookGood'));
}
} else if (deviceStatusType === 'ok') {
store.dispatch(setDeviceStatusWarning('prejoin.audioDeviceProblem'));
}
}
break;
}
case CONFERENCE_FAILED:
store.dispatch(setJoiningInProgress(false));
break;
case CONFERENCE_JOINED:
return _conferenceJoined(store, next, action);
}
2020-04-16 10:47:10 +00:00
return next(action);
});
/**
* Handles cleanup of prejoin state when a conference is joined.
*
* @param {Object} store - The Redux store.
* @param {Function} next - The Redux next function.
* @param {Object} action - The Redux action.
* @returns {Object}
*/
function _conferenceJoined({ dispatch }, next, action) {
dispatch(setPrejoinPageVisibility(PREJOIN_SCREEN_STATES.HIDDEN));
dispatch(setJoiningInProgress(false));
return next(action);
}