2022-09-14 07:54:56 +00:00
|
|
|
import { AnyAction } from 'redux';
|
|
|
|
|
|
|
|
import { IStore } from '../../app/types';
|
2020-07-07 20:34:52 +00:00
|
|
|
import { getFeatureFlag } from '../flags/functions';
|
2022-11-22 11:28:30 +00:00
|
|
|
import Platform from '../react/Platform';
|
2022-09-14 07:54:56 +00:00
|
|
|
import MiddlewareRegistry from '../redux/MiddlewareRegistry';
|
|
|
|
import { updateSettings } from '../settings/actions';
|
2018-03-09 14:52:59 +00:00
|
|
|
|
2022-09-27 07:10:28 +00:00
|
|
|
import { OVERWRITE_CONFIG, SET_CONFIG } from './actionTypes';
|
2020-08-14 07:45:15 +00:00
|
|
|
import { updateConfig } from './actions';
|
2022-09-14 07:54:56 +00:00
|
|
|
import { IConfig } from './configType';
|
2018-03-09 14:52:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The middleware of the feature {@code base/config}.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @private
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
switch (action.type) {
|
|
|
|
case SET_CONFIG:
|
|
|
|
return _setConfig(store, next, action);
|
2021-03-17 13:21:19 +00:00
|
|
|
|
|
|
|
case OVERWRITE_CONFIG:
|
|
|
|
return _updateSettings(store, next, action);
|
2018-03-09 14:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies the feature {@code base/config} that the {@link SET_CONFIG} redux
|
|
|
|
* action is being {@code dispatch}ed in a specific redux store.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store in which the specified {@code action}
|
|
|
|
* is being dispatched.
|
|
|
|
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
|
|
|
* specified {@code action} in the specified {@code store}.
|
|
|
|
* @param {Action} action - The redux action which is being {@code dispatch}ed
|
|
|
|
* in the specified {@code store}.
|
|
|
|
* @private
|
|
|
|
* @returns {*} The return value of {@code next(action)}.
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
function _setConfig({ dispatch, getState }: IStore, next: Function, action: AnyAction) {
|
2018-03-09 14:52:59 +00:00
|
|
|
// The reducer is doing some alterations to the config passed in the action,
|
|
|
|
// so make sure it's the final state by waiting for the action to be
|
|
|
|
// reduced.
|
|
|
|
const result = next(action);
|
2019-10-18 14:30:59 +00:00
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
// Update the config with user defined settings.
|
|
|
|
const settings = state['features/base/settings'];
|
2022-09-14 07:54:56 +00:00
|
|
|
const config: IConfig = {};
|
2019-10-18 14:30:59 +00:00
|
|
|
|
2022-11-22 11:28:30 +00:00
|
|
|
if (Platform.OS !== 'android' && typeof settings.disableP2P !== 'undefined') {
|
2019-10-18 14:30:59 +00:00
|
|
|
config.p2p = { enabled: !settings.disableP2P };
|
|
|
|
}
|
|
|
|
|
2020-07-07 20:34:52 +00:00
|
|
|
const resolutionFlag = getFeatureFlag(state, 'resolution');
|
|
|
|
|
|
|
|
if (typeof resolutionFlag !== 'undefined') {
|
|
|
|
config.resolution = resolutionFlag;
|
|
|
|
}
|
|
|
|
|
2021-03-17 13:21:19 +00:00
|
|
|
if (action.config.doNotFlipLocalVideo === true) {
|
|
|
|
dispatch(updateSettings({
|
|
|
|
localFlipX: false
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2022-01-10 10:46:33 +00:00
|
|
|
if (action.config.disableSelfView !== undefined) {
|
|
|
|
dispatch(updateSettings({
|
|
|
|
disableSelfView: action.config.disableSelfView
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2022-09-15 15:12:43 +00:00
|
|
|
if (action.config.filmstrip?.stageFilmstripParticipants !== undefined) {
|
2022-09-15 07:57:48 +00:00
|
|
|
dispatch(updateSettings({
|
|
|
|
maxStageParticipants: action.config.filmstrip.stageFilmstripParticipants
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2020-08-14 07:45:15 +00:00
|
|
|
dispatch(updateConfig(config));
|
2018-03-09 14:52:59 +00:00
|
|
|
|
|
|
|
// FIXME On Web we rely on the global 'config' variable which gets altered
|
|
|
|
// multiple times, before it makes it to the reducer. At some point it may
|
|
|
|
// not be the global variable which is being modified anymore due to
|
|
|
|
// different merge methods being used along the way. The global variable
|
|
|
|
// must be synchronized with the final state resolved by the reducer.
|
|
|
|
if (typeof window.config !== 'undefined') {
|
2019-10-18 14:30:59 +00:00
|
|
|
window.config = state['features/base/config'];
|
2018-03-09 14:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2021-03-17 13:21:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates settings based on some config values.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store in which the specified {@code action}
|
|
|
|
* is being dispatched.
|
|
|
|
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
|
|
|
* specified {@code action} in the specified {@code store}.
|
|
|
|
* @param {Action} action - The redux action which is being {@code dispatch}ed
|
|
|
|
* in the specified {@code store}.
|
|
|
|
* @private
|
|
|
|
* @returns {*} The return value of {@code next(action)}.
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
function _updateSettings({ dispatch }: IStore, next: Function, action: AnyAction) {
|
2021-03-17 13:21:19 +00:00
|
|
|
const { config: { doNotFlipLocalVideo } } = action;
|
|
|
|
|
|
|
|
if (doNotFlipLocalVideo === true) {
|
|
|
|
dispatch(updateSettings({
|
|
|
|
localFlipX: false
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
}
|