Files
cinny/src/app/state/callPreferences.ts
T
Lotus Bot 61a1f008d0 chore: upgrade i18next 26, prettier 3, fontsource-variable, domhandler 6, lint-staged 17
- i18next 23->26 + react-i18next 15->17
- prettier 2->3, reformat all files
- replace @fontsource/inter with @fontsource-variable/inter 5, update import path
- domhandler 5->6 (aligns with transitive deps)
- lint-staged 16->17
2026-05-21 23:30:50 -04:00

43 lines
1.2 KiB
TypeScript

import { WritableAtom } from 'jotai';
import {
atomWithLocalStorage,
getLocalStorageItem,
setLocalStorageItem,
} from './utils/atomWithLocalStorage';
export type CallPreferences = {
microphone: boolean;
video: boolean;
sound: boolean;
};
const CALL_PREFERENCES = 'callPreferences';
const DEFAULT_PREFERENCES: CallPreferences = {
microphone: true,
video: false,
sound: true,
};
export type CallPreferencesAtom = WritableAtom<CallPreferences, [CallPreferences], undefined>;
export const makeCallPreferencesAtom = (userId: string): CallPreferencesAtom => {
const storeKey = `${CALL_PREFERENCES}${userId}`;
const callPreferencesAtom = atomWithLocalStorage<CallPreferences>(
storeKey,
(key) => {
const v = getLocalStorageItem<CallPreferences>(key, DEFAULT_PREFERENCES);
// Never restore camera state — always start with camera off for privacy.
// Users can toggle it in the prescreen before joining.
return { ...v, video: false };
},
(key, value) => {
// Don't persist video state — always resets to off on next load.
setLocalStorageItem(key, { ...value, video: false });
},
);
return callPreferencesAtom;
};