-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor persistent storage to use UserChoices
instead of DeviceSettings
- Loading branch information
Showing
5 changed files
with
47 additions
and
45 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { setDeviceSettings, getDeviceSettings, type DeviceSettings } from './device-settings'; | ||
export { saveUserChoices, loadUserChoices, type UserChoices } from './user-choices'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { cssPrefix } from '../constants'; | ||
import { getLocalStorageObject, setLocalStorageObject } from './local-storage-helpers'; | ||
|
||
const USER_CHOICES_KEY = `${cssPrefix}-device-settings` as const; | ||
|
||
export type UserChoices = { | ||
videoInputEnabled: boolean; | ||
audioInputEnabled: boolean; | ||
videoInputDeviceId: string; | ||
audioInputDeviceId: string; | ||
username: string; | ||
}; | ||
|
||
const defaultUserChoices: UserChoices = { | ||
videoInputEnabled: true, | ||
audioInputEnabled: true, | ||
videoInputDeviceId: '', | ||
audioInputDeviceId: '', | ||
username: '', | ||
}; | ||
|
||
/** | ||
* Sets the user choices in local storage. | ||
* @param deviceSettings - The device settings to be stored. | ||
* @alpha | ||
*/ | ||
export function saveUserChoices(deviceSettings: UserChoices): void { | ||
setLocalStorageObject(USER_CHOICES_KEY, deviceSettings); | ||
} | ||
|
||
/** | ||
* Reads the user choices from local storage, or returns the default settings if none are found. | ||
* @param defaults - The default device settings to use if none are found in local storage. | ||
* @alpha | ||
*/ | ||
export function loadUserChoices(defaults?: UserChoices): UserChoices { | ||
return getLocalStorageObject(USER_CHOICES_KEY) ?? defaults ?? defaultUserChoices; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters