added logic for updating the settings in the store when the app config changes

This commit is contained in:
Vittorio Palmisano 2021-04-29 15:17:33 +02:00
parent da53b3465e
commit 956aadd1af
9 changed files with 120 additions and 45 deletions

View file

@ -27,6 +27,7 @@
"convict": "^6.0.1",
"convict-format-with-validator": "^6.0.1",
"create-torrent": "^4.4.1",
"deep-object-diff": "^1.1.0",
"dompurify": "^2.0.7",
"domready": "^1.0.8",
"end-of-stream": "1.4.1",

View file

@ -78,17 +78,17 @@ var config =
} ],
// The aspect ratio of the video from the camera
// this is not changeable in settings, only config
videoAspectRatio : 1.777,
defaultResolution : 'medium',
defaultFrameRate : 15,
defaultScreenResolution : 'veryhigh',
defaultScreenSharingFrameRate : 5,
videoAspectRatio : 1.777,
resolution : 'medium',
frameRate : 15,
screenResolution : 'veryhigh',
screenSharingFrameRate : 5,
// Enable or disable simulcast for webcam video
simulcast : true,
simulcast : true,
// Enable or disable simulcast for screen sharing video
simulcastSharing : false,
simulcastSharing : false,
// Define different encodings for various resolutions of the video
simulcastProfiles :
simulcastProfiles :
{
3840 :
[

View file

@ -118,25 +118,25 @@ const configSchema = convict({
format : 'float',
default : 1.777
},
defaultResolution :
resolution :
{
doc : 'The default video camera capture resolution.',
format : [ 'low', 'medium', 'high', 'veryhigh', 'ultra' ],
default : 'medium'
},
defaultFrameRate :
frameRate :
{
doc : 'The default video camera capture framerate.',
format : 'nat',
default : 15
},
defaultScreenResolution :
screenResolution :
{
doc : 'The default screen sharing resolution.',
format : [ 'low', 'medium', 'high', 'veryhigh', 'ultra' ],
default : 'veryhigh'
},
defaultScreenSharingFrameRate :
screenSharingFrameRate :
{
doc : 'The default screen sharing framerate.',
format : 'nat',
@ -234,21 +234,35 @@ const configSchema = convict({
tcp : true
}
},
// defaults for audio setting on new clients / can be customized and overruled from client side
defaultAudio :
autoGainControl :
{
doc : 'Defaults audio settings.',
format : Object,
default :
{
autoGainControl : true, // default : true
echoCancellation : true, // default : true
noiseSuppression : true, // default : true
// Automatically unmute speaking above noisThereshold
voiceActivatedUnmute : false, // default : false
// This is only for voiceActivatedUnmute and audio-indicator
noiseThreshold : -60 // default -60
}
doc : 'Auto gain control enabled.',
format : 'Boolean',
default : true
},
echoCancellation :
{
doc : 'Echo cancellation enabled.',
format : 'Boolean',
default : true
},
noiseSuppression :
{
doc : 'Noise suppression enabled.',
format : 'Boolean',
default : true
},
voiceActivatedUnmute :
{
doc : 'Automatically unmute speaking above noiseThreshold.',
format : 'Boolean',
default : false
},
noiseThreshold :
{
doc : 'This is only for voiceActivatedUnmute and audio-indicator.',
format : 'int',
default : -60
},
// Audio options for now only centrally from config file:
centralAudioOptions :

View file

@ -0,0 +1,22 @@
import { config as defaultConfig } from '../config';
const initialState =
{
...defaultConfig
};
const config = (state = initialState, action) =>
{
switch (action.type)
{
case 'CONFIG_SET':
{
return { ...action.payload };
}
default:
return state;
}
};
export default config;

View file

@ -13,6 +13,7 @@ import files from './files';
import settings from './settings';
import transports from './transports';
import intl from './intl';
import config from './config';
// import { intlReducer } from 'react-intl-redux';
export default combineReducers({
@ -30,5 +31,6 @@ export default combineReducers({
files,
settings,
// intl : intlReducer
intl
intl,
config
});

View file

@ -1,21 +1,23 @@
import { config } from '../config';
const initialState =
{
displayName : '',
selectedWebcam : null,
selectedAudioDevice : null,
advancedMode : false,
autoGainControl : true,
echoCancellation : true,
noiseSuppression : true,
voiceActivatedUnmute : false,
noiseThreshold : -50,
autoGainControl : config.autoGainControl,
echoCancellation : config.echoCancellation,
noiseSuppression : config.noiseSuppression,
voiceActivatedUnmute : config.voiceActivatedUnmute,
noiseThreshold : config.noiseThreshold,
audioMuted : false,
videoMuted : false,
// low, medium, high, veryhigh, ultra
resolution : window.config.defaultResolution || 'medium',
frameRate : window.config.defaultFrameRate || 15,
screenSharingResolution : window.config.defaultScreenResolution || 'veryhigh',
screenSharingFrameRate : window.config.defaultScreenSharingFrameRate || 5,
resolution : config.resolution,
frameRate : config.frameRate,
screenSharingResolution : config.screenResolution,
screenSharingFrameRate : config.screenSharingFrameRate,
lastN : 4,
permanentTopBar : true,
hiddenControls : false,
@ -23,12 +25,11 @@ const initialState =
notificationSounds : true,
mirrorOwnVideo : true,
hideNoVideoParticipants : false,
buttonControlBar : window.config.buttonControlBar || false,
drawerOverlayed : (typeof window.config.drawerOverlayed === 'undefined') ? true : window.config.drawerOverlayed,
aspectRatio : window.config.viewAspectRatio || 1.777, // 16 : 9
buttonControlBar : config.buttonControlBar,
drawerOverlayed : config.drawerOverlayed,
aspectRatio : config.viewAspectRatio || 1.777, // 16 : 9
mediaPerms : { audio: true, video: true },
localPicture : null,
...window.config.defaultAudio
localPicture : null
};
const settings = (state = initialState, action) =>
@ -260,6 +261,11 @@ const settings = (state = initialState, action) =>
return { ...state, localPicture };
}
case 'SETTINGS_UPDATE':
{
return { ...state, ...action.payload };
}
default:
return state;
}

View file

@ -8,8 +8,13 @@ import { createLogger } from 'redux-logger';
import { createMigrate, persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2';
import rootReducer from './reducers/rootReducer';
import { createFilter } from 'redux-persist-transform-filter';
import { diff } from 'deep-object-diff';
import rootReducer from './reducers/rootReducer';
import Logger from './Logger';
import { config } from './config';
const logger = new Logger('store');
const migrations =
{
@ -60,7 +65,7 @@ const persistConfig =
version : 2,
migrate : createMigrate(migrations, { debug: false }),
stateReconciler : autoMergeLevel2,
whitelist : [ 'settings', 'intl' ]
whitelist : [ 'settings', 'intl', 'config' ]
};
const saveSubsetFilter = createFilter(
@ -113,7 +118,27 @@ export const store = createStore(
enhancer
);
export const persistor = persistStore(store);
export const persistor = persistStore(store, null, () =>
{
// Check if the app config differs from the stored version.
const currentConfig = store.getState().config;
const changed = diff(currentConfig, config);
const changedKeys = Object.keys(changed);
if (changedKeys.length)
{
logger.debug('store config changed:', changed);
const changedSettings = {};
changedKeys.forEach((key) =>
{
changedSettings[key] = config[key];
});
store.dispatch({ type: 'SETTINGS_UPDATE', payload: changedSettings });
store.dispatch({ type: 'CONFIG_SET', payload: config });
}
});
/*

View file

@ -4669,6 +4669,11 @@ deep-is@^0.1.3, deep-is@~0.1.3:
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=
deep-object-diff@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/deep-object-diff/-/deep-object-diff-1.1.0.tgz#d6fabf476c2ed1751fc94d5ca693d2ed8c18bc5a"
integrity sha512-b+QLs5vHgS+IoSNcUE4n9HP2NwcHj7aqnJWsjPtuG75Rh5TOaGt0OjAYInh77d5T16V5cRDC+Pw/6ZZZiETBGw==
deepmerge@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955"

View file

@ -2,5 +2,5 @@
var config =
{
developmentPort : 8443,
productionPort : 3443
productionPort : 3443,
};