"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-7305/react/features/base/settings/reducer.ts" (26 May 2023, 5249 Bytes) of package /linux/misc/jitsi-meet-7305.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "reducer.ts": 7259_vs_7266.

    1 // @ts-expect-error
    2 import { jitsiLocalStorage } from '@jitsi/js-utils';
    3 import _ from 'lodash';
    4 
    5 import { APP_WILL_MOUNT } from '../app/actionTypes';
    6 import PersistenceRegistry from '../redux/PersistenceRegistry';
    7 import ReducerRegistry from '../redux/ReducerRegistry';
    8 import { assignIfDefined } from '../util/helpers';
    9 
   10 import { SETTINGS_UPDATED } from './actionTypes';
   11 
   12 /**
   13  * The default/initial redux state of the feature {@code base/settings}.
   14  *
   15  * @type Object
   16  */
   17 const DEFAULT_STATE: ISettingsState = {
   18     audioOutputDeviceId: undefined,
   19     avatarURL: undefined,
   20     cameraDeviceId: undefined,
   21     disableCallIntegration: undefined,
   22     disableCrashReporting: undefined,
   23     disableP2P: undefined,
   24     disableSelfView: false,
   25     displayName: undefined,
   26     email: undefined,
   27     localFlipX: true,
   28     maxStageParticipants: 1,
   29     micDeviceId: undefined,
   30     serverURL: undefined,
   31     hideShareAudioHelper: false,
   32     soundsIncomingMessage: true,
   33     soundsParticipantJoined: true,
   34     soundsParticipantKnocking: true,
   35     soundsParticipantLeft: true,
   36     soundsTalkWhileMuted: true,
   37     soundsReactions: true,
   38     startAudioOnly: false,
   39     startCarMode: false,
   40     startWithAudioMuted: false,
   41     startWithVideoMuted: false,
   42     userSelectedAudioOutputDeviceId: undefined,
   43     userSelectedCameraDeviceId: undefined,
   44     userSelectedMicDeviceId: undefined,
   45     userSelectedAudioOutputDeviceLabel: undefined,
   46     userSelectedCameraDeviceLabel: undefined,
   47     userSelectedNotifications: {
   48         'notify.chatMessages': true
   49     },
   50     userSelectedMicDeviceLabel: undefined,
   51     userSelectedSkipPrejoin: undefined
   52 };
   53 
   54 export interface ISettingsState {
   55     audioOutputDeviceId?: string;
   56     audioSettingsVisible?: boolean;
   57     avatarURL?: string;
   58     cameraDeviceId?: string | boolean;
   59     disableCallIntegration?: boolean;
   60     disableCrashReporting?: boolean;
   61     disableP2P?: boolean;
   62     disableSelfView?: boolean;
   63     displayName?: string;
   64     email?: string;
   65     hideShareAudioHelper?: boolean;
   66     localFlipX?: boolean;
   67     maxStageParticipants?: number;
   68     micDeviceId?: string | boolean;
   69     serverURL?: string;
   70     soundsIncomingMessage?: boolean;
   71     soundsParticipantJoined?: boolean;
   72     soundsParticipantKnocking?: boolean;
   73     soundsParticipantLeft?: boolean;
   74     soundsReactions?: boolean;
   75     soundsTalkWhileMuted?: boolean;
   76     startAudioOnly?: boolean;
   77     startCarMode?: boolean;
   78     startWithAudioMuted?: boolean;
   79     startWithVideoMuted?: boolean;
   80     userSelectedAudioOutputDeviceId?: string;
   81     userSelectedAudioOutputDeviceLabel?: string;
   82     userSelectedCameraDeviceId?: string;
   83     userSelectedCameraDeviceLabel?: string;
   84     userSelectedMicDeviceId?: string;
   85     userSelectedMicDeviceLabel?: string;
   86     userSelectedNotifications?: {
   87         [key: string]: boolean;
   88     };
   89     userSelectedSkipPrejoin?: boolean;
   90     videoSettingsVisible?: boolean;
   91     visible?: boolean;
   92 }
   93 
   94 const STORE_NAME = 'features/base/settings';
   95 
   96 /**
   97  * Sets up the persistence of the feature {@code base/settings}.
   98  */
   99 const filterSubtree: ISettingsState = {};
  100 
  101 // start with the default state
  102 Object.keys(DEFAULT_STATE).forEach(key => {
  103     const key1 = key as keyof typeof filterSubtree;
  104 
  105     // @ts-ignore
  106     filterSubtree[key1] = true;
  107 });
  108 
  109 // we want to filter these props, to not be stored as they represent
  110 // what is currently opened/used as devices
  111 // @ts-ignore
  112 filterSubtree.audioOutputDeviceId = false;
  113 filterSubtree.cameraDeviceId = false;
  114 filterSubtree.micDeviceId = false;
  115 
  116 PersistenceRegistry.register(STORE_NAME, filterSubtree, DEFAULT_STATE);
  117 
  118 ReducerRegistry.register<ISettingsState>(STORE_NAME, (state = DEFAULT_STATE, action): ISettingsState => {
  119     switch (action.type) {
  120     case APP_WILL_MOUNT:
  121         return _initSettings(state);
  122 
  123     case SETTINGS_UPDATED:
  124         return {
  125             ...state,
  126             ...action.settings
  127         };
  128     }
  129 
  130     return state;
  131 });
  132 
  133 /**
  134  * Inits the settings object based on what information we have available.
  135  * Info taken into consideration:
  136  *   - Old Settings.js style data.
  137  *
  138  * @private
  139  * @param {ISettingsState} featureState - The current state of the feature.
  140  * @returns {Object}
  141  */
  142 function _initSettings(featureState: ISettingsState) {
  143     let settings = featureState;
  144 
  145     // Old Settings.js values
  146     // FIXME: jibri uses old settings.js local storage values to set its display
  147     // name and email. Provide another way for jibri to set these values, update
  148     // jibri, and remove the old settings.js values.
  149     const savedDisplayName = jitsiLocalStorage.getItem('displayname');
  150     const savedEmail = jitsiLocalStorage.getItem('email');
  151 
  152     // The helper _.escape will convert null to an empty strings. The empty
  153     // string will be saved in settings. On app re-load, because an empty string
  154     // is a defined value, it will override any value found in local storage.
  155     // The workaround is sidestepping _.escape when the value is not set in
  156     // local storage.
  157     const displayName = savedDisplayName === null ? undefined : _.escape(savedDisplayName);
  158     const email = savedEmail === null ? undefined : _.escape(savedEmail);
  159 
  160     settings = assignIfDefined({
  161         displayName,
  162         email
  163     }, settings);
  164 
  165     return settings;
  166 }