* When an admin has marked your camera 'red' for you, the Explicit button at the top of the page now will require *two* clicks if the user wants to set their camera back to blue: On first click, they will get a red ChatClient message explaining that their cam was most-recently marked red due to a server action (such as a moderator flagging their cam for them). If they really mean to mark their camera blue, they are instructed to click it a second time to confirm. * This behavior only occurs when the most recent NSFW setting was dictated by the server (e.g. a 'me' event disagreed with the page's local NSFW setting). The flag is cleared any time the user themself toggles the flag, or when the first ChatClient warning after a server event is shown. * The explicit camera settings in the broadcast modal have been rearranged and reworded. * Add an 'advanced' webcam feature to automatically broadcast in the future on page load. The option is only available in the Chat Settings 'Camera' tab after you are already broadcasting (or rather: when a list of video devices have become available to the page, indicating the user has possibly granted permission already).
86 lines
3.0 KiB
JavaScript
86 lines
3.0 KiB
JavaScript
// All the distinct localStorage keys used.
|
|
const keys = {
|
|
'fontSizeClass': String, // Text magnification
|
|
'videoScale': String, // Video magnification (CSS classnames)
|
|
'messageStyle': String, // Message display style (cards, compact, etc.)
|
|
'imageDisplaySetting': String, // Show/hide/expand image preference
|
|
'scrollback': Number, // Scrollback buffer (int)
|
|
'preferredDeviceNames': Object, // Webcam/mic device names (object, keys video,audio)
|
|
'whoSort': String, // user's preferred sort order for the Who List
|
|
'theme': String, // light, dark, or auto theme
|
|
|
|
// Webcam settings (booleans)
|
|
'videoMutual': Boolean,
|
|
'videoMutualOpen': Boolean,
|
|
'videoAutoMute': Boolean,
|
|
'videoVipOnly': Boolean,
|
|
'videoExplicit': Boolean, // whether the user turns explicit on by default
|
|
'videoNonExplicit': Boolean, // user prefers not to see explicit
|
|
'rememberExpresslyClosed': Boolean,
|
|
'autoMuteWebcams': Boolean, // automatically mute other peoples' webcam audio feeds
|
|
'videoAutoShare': Boolean, // automatically share your webcam on page load
|
|
|
|
// Booleans
|
|
'usePolling': Boolean, // use the polling API instead of WebSocket
|
|
'joinMessages': Boolean,
|
|
'exitMessages': Boolean,
|
|
'watchNotif': Boolean,
|
|
'muteSounds': Boolean,
|
|
'closeDMs': Boolean, // close unsolicited DMs
|
|
'debug': Boolean, // Debug views enabled (admin only)
|
|
|
|
// Don't Show Again on NSFW modals.
|
|
'skip-nsfw-modal': Boolean,
|
|
}
|
|
|
|
// UserSettings centralizes browser settings for the chat room.
|
|
class UserSettings {
|
|
constructor() {
|
|
// Recall stored settings. Only set the keys that were
|
|
// found in localStorage on page load.
|
|
for (let key of Object.keys(keys)) {
|
|
if (localStorage[key] != undefined) {
|
|
try {
|
|
this[key] = JSON.parse(localStorage[key]);
|
|
} catch(e) {
|
|
console.error(`LocalStorage: parsing key ${key}: ${e}`);
|
|
delete(this[key]);
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log("LocalStorage: Loaded settings", this);
|
|
}
|
|
|
|
// Return all of the current settings where the user had actually
|
|
// left a preference on them (was in localStorage).
|
|
getSettings() {
|
|
let result = {};
|
|
for (let key of Object.keys(keys)) {
|
|
if (this[key] != undefined) {
|
|
result[key] = this[key];
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Get a value from localStorage, if set.
|
|
get(key) {
|
|
return this[key];
|
|
}
|
|
|
|
// Generic setter.
|
|
set(key, value) {
|
|
if (keys[key] == undefined) {
|
|
throw `${key}: not a supported localStorage setting`;
|
|
}
|
|
|
|
localStorage[key] = JSON.stringify(value);
|
|
this[key] = value;
|
|
}
|
|
}
|
|
|
|
// LocalStorage is a global singleton to access and update user settings.
|
|
const LocalStorage = new UserSettings();
|
|
export default LocalStorage;
|