2026-03-07 18:03:32 +11:00
|
|
|
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);
|
2026-05-14 11:07:10 -04:00
|
|
|
// Never restore camera state — always start with camera off for privacy.
|
|
|
|
|
// Users can toggle it in the prescreen before joining.
|
|
|
|
|
return { ...v, video: false };
|
2026-03-07 18:03:32 +11:00
|
|
|
},
|
|
|
|
|
(key, value) => {
|
2026-05-14 11:07:10 -04:00
|
|
|
// Don't persist video state — always resets to off on next load.
|
|
|
|
|
setLocalStorageItem(key, { ...value, video: false });
|
2026-03-07 18:03:32 +11:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return callPreferencesAtom;
|
|
|
|
|
};
|