2022-07-26 10:20:39 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
|
|
|
// @ts-ignore
|
2020-07-09 07:17:23 +00:00
|
|
|
import { jitsiLocalStorage } from '@jitsi/js-utils';
|
2018-04-12 19:58:20 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
2020-06-04 14:09:13 +00:00
|
|
|
import { APP_WILL_MOUNT } from '../app/actionTypes';
|
2022-07-26 10:20:39 +00:00
|
|
|
import PersistenceRegistry from '../redux/PersistenceRegistry';
|
|
|
|
import ReducerRegistry from '../redux/ReducerRegistry';
|
2022-09-05 11:24:13 +00:00
|
|
|
import { assignIfDefined } from '../util/helpers';
|
2018-04-12 19:58:20 +00:00
|
|
|
|
|
|
|
import { SETTINGS_UPDATED } from './actionTypes';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default/initial redux state of the feature {@code base/settings}.
|
|
|
|
*
|
|
|
|
* @type Object
|
|
|
|
*/
|
2022-07-26 10:20:39 +00:00
|
|
|
const DEFAULT_STATE: ISettingsState = {
|
2018-04-12 19:58:20 +00:00
|
|
|
audioOutputDeviceId: undefined,
|
|
|
|
avatarURL: undefined,
|
|
|
|
cameraDeviceId: undefined,
|
2019-10-18 14:30:59 +00:00
|
|
|
disableCallIntegration: undefined,
|
2020-05-07 21:05:48 +00:00
|
|
|
disableCrashReporting: undefined,
|
2019-10-18 14:30:59 +00:00
|
|
|
disableP2P: undefined,
|
2021-12-07 08:24:00 +00:00
|
|
|
disableSelfView: false,
|
2018-04-12 19:58:20 +00:00
|
|
|
displayName: undefined,
|
|
|
|
email: undefined,
|
|
|
|
localFlipX: true,
|
2022-09-15 07:57:48 +00:00
|
|
|
maxStageParticipants: 1,
|
2018-04-12 19:58:20 +00:00
|
|
|
micDeviceId: undefined,
|
|
|
|
serverURL: undefined,
|
2021-07-07 08:07:30 +00:00
|
|
|
hideShareAudioHelper: false,
|
2021-07-20 11:56:57 +00:00
|
|
|
soundsIncomingMessage: true,
|
|
|
|
soundsParticipantJoined: true,
|
2022-06-15 18:36:26 +00:00
|
|
|
soundsParticipantKnocking: true,
|
2021-07-20 11:56:57 +00:00
|
|
|
soundsParticipantLeft: true,
|
|
|
|
soundsTalkWhileMuted: true,
|
2021-08-23 09:57:56 +00:00
|
|
|
soundsReactions: true,
|
2018-04-12 19:58:20 +00:00
|
|
|
startAudioOnly: false,
|
|
|
|
startWithAudioMuted: false,
|
2019-05-01 14:13:25 +00:00
|
|
|
startWithVideoMuted: false,
|
|
|
|
userSelectedAudioOutputDeviceId: undefined,
|
|
|
|
userSelectedCameraDeviceId: undefined,
|
2019-05-07 08:53:01 +00:00
|
|
|
userSelectedMicDeviceId: undefined,
|
|
|
|
userSelectedAudioOutputDeviceLabel: undefined,
|
|
|
|
userSelectedCameraDeviceLabel: undefined,
|
2021-12-17 12:39:15 +00:00
|
|
|
userSelectedNotifications: {
|
|
|
|
'notify.chatMessages': true
|
|
|
|
},
|
2020-05-07 07:42:55 +00:00
|
|
|
userSelectedMicDeviceLabel: undefined,
|
|
|
|
userSelectedSkipPrejoin: undefined
|
2018-04-12 19:58:20 +00:00
|
|
|
};
|
|
|
|
|
2022-07-26 10:20:39 +00:00
|
|
|
export interface ISettingsState {
|
2022-09-08 09:52:36 +00:00
|
|
|
audioOutputDeviceId?: string | boolean;
|
2022-09-29 11:45:34 +00:00
|
|
|
audioSettingsVisible?: boolean;
|
2022-09-14 07:54:56 +00:00
|
|
|
avatarURL?: string;
|
2022-09-08 09:52:36 +00:00
|
|
|
cameraDeviceId?: string | boolean;
|
2022-07-26 10:20:39 +00:00
|
|
|
disableCallIntegration?: boolean;
|
|
|
|
disableCrashReporting?: boolean;
|
|
|
|
disableP2P?: boolean;
|
|
|
|
disableSelfView?: boolean;
|
2022-09-14 07:54:56 +00:00
|
|
|
displayName?: string;
|
|
|
|
email?: string;
|
2022-07-26 10:20:39 +00:00
|
|
|
hideShareAudioHelper?: boolean;
|
|
|
|
localFlipX?: boolean;
|
2022-09-15 07:57:48 +00:00
|
|
|
maxStageParticipants?: number;
|
2022-09-08 09:52:36 +00:00
|
|
|
micDeviceId?: string | boolean;
|
2022-09-14 07:54:56 +00:00
|
|
|
serverURL?: string;
|
2022-07-26 10:20:39 +00:00
|
|
|
soundsIncomingMessage?: boolean;
|
|
|
|
soundsParticipantJoined?: boolean;
|
|
|
|
soundsParticipantKnocking?: boolean;
|
|
|
|
soundsParticipantLeft?: boolean;
|
|
|
|
soundsReactions?: boolean;
|
|
|
|
soundsTalkWhileMuted?: boolean;
|
|
|
|
startAudioOnly?: boolean;
|
|
|
|
startWithAudioMuted?: boolean;
|
|
|
|
startWithVideoMuted?: boolean;
|
2022-09-14 07:54:56 +00:00
|
|
|
userSelectedAudioOutputDeviceId?: string;
|
|
|
|
userSelectedAudioOutputDeviceLabel?: string;
|
|
|
|
userSelectedCameraDeviceId?: string;
|
|
|
|
userSelectedCameraDeviceLabel?: string;
|
|
|
|
userSelectedMicDeviceId?: string;
|
|
|
|
userSelectedMicDeviceLabel?: string;
|
2022-07-26 10:20:39 +00:00
|
|
|
userSelectedNotifications?: {
|
|
|
|
[key: string]: boolean;
|
2022-09-08 09:52:36 +00:00
|
|
|
} | boolean;
|
2022-07-26 10:20:39 +00:00
|
|
|
userSelectedSkipPrejoin?: boolean;
|
2022-09-29 11:45:34 +00:00
|
|
|
videoSettingsVisible?: boolean;
|
2022-09-05 11:24:13 +00:00
|
|
|
visible?: boolean;
|
2022-07-26 10:20:39 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 19:58:20 +00:00
|
|
|
const STORE_NAME = 'features/base/settings';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up the persistence of the feature {@code base/settings}.
|
|
|
|
*/
|
2022-07-26 10:20:39 +00:00
|
|
|
const filterSubtree: ISettingsState = {};
|
2019-05-01 14:13:25 +00:00
|
|
|
|
|
|
|
// start with the default state
|
|
|
|
Object.keys(DEFAULT_STATE).forEach(key => {
|
2022-07-26 10:20:39 +00:00
|
|
|
const key1 = key as keyof typeof filterSubtree;
|
|
|
|
|
2022-09-14 07:54:56 +00:00
|
|
|
// @ts-ignore
|
2022-07-26 10:20:39 +00:00
|
|
|
filterSubtree[key1] = true;
|
2019-05-01 14:13:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// we want to filter these props, to not be stored as they represent
|
|
|
|
// what is currently opened/used as devices
|
|
|
|
filterSubtree.audioOutputDeviceId = false;
|
|
|
|
filterSubtree.cameraDeviceId = false;
|
|
|
|
filterSubtree.micDeviceId = false;
|
|
|
|
|
2021-08-24 06:51:24 +00:00
|
|
|
PersistenceRegistry.register(STORE_NAME, filterSubtree, DEFAULT_STATE);
|
2018-04-12 19:58:20 +00:00
|
|
|
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<ISettingsState>(STORE_NAME, (state = DEFAULT_STATE, action): ISettingsState => {
|
2018-04-12 19:58:20 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case APP_WILL_MOUNT:
|
|
|
|
return _initSettings(state);
|
|
|
|
|
|
|
|
case SETTINGS_UPDATED:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...action.settings
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inits the settings object based on what information we have available.
|
|
|
|
* Info taken into consideration:
|
2020-12-23 14:02:36 +00:00
|
|
|
* - Old Settings.js style data.
|
2018-04-12 19:58:20 +00:00
|
|
|
*
|
|
|
|
* @private
|
2022-07-26 10:20:39 +00:00
|
|
|
* @param {ISettingsState} featureState - The current state of the feature.
|
2018-04-12 19:58:20 +00:00
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-07-26 10:20:39 +00:00
|
|
|
function _initSettings(featureState: ISettingsState) {
|
2018-04-12 19:58:20 +00:00
|
|
|
let settings = featureState;
|
|
|
|
|
|
|
|
// Old Settings.js values
|
2019-06-05 00:42:48 +00:00
|
|
|
// FIXME: jibri uses old settings.js local storage values to set its display
|
|
|
|
// name and email. Provide another way for jibri to set these values, update
|
|
|
|
// jibri, and remove the old settings.js values.
|
2020-05-01 19:48:08 +00:00
|
|
|
const savedDisplayName = jitsiLocalStorage.getItem('displayname');
|
|
|
|
const savedEmail = jitsiLocalStorage.getItem('email');
|
2018-04-12 19:58:20 +00:00
|
|
|
|
2019-06-05 00:42:48 +00:00
|
|
|
// The helper _.escape will convert null to an empty strings. The empty
|
|
|
|
// string will be saved in settings. On app re-load, because an empty string
|
|
|
|
// is a defined value, it will override any value found in local storage.
|
|
|
|
// The workaround is sidestepping _.escape when the value is not set in
|
|
|
|
// local storage.
|
2020-10-09 12:19:56 +00:00
|
|
|
const displayName = savedDisplayName === null ? undefined : _.escape(savedDisplayName);
|
2019-06-05 00:42:48 +00:00
|
|
|
const email = savedEmail === null ? undefined : _.escape(savedEmail);
|
|
|
|
|
2018-04-12 19:58:20 +00:00
|
|
|
settings = assignIfDefined({
|
|
|
|
displayName,
|
|
|
|
email
|
|
|
|
}, settings);
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
}
|