* Try a new strategy to get Apple (iPad/iPhone) webcams to connect. * "Apple compatibility mode" setting: on by default if iPad/iPhone is detected or can be opted into in the chat settings Misc tab. * In Apple compat mode: when you open someone else's webcam, you always attach your local video on the WebRTC offer. This would normally make your video auto-open on the remote side, but the previous commit updates the chat page to ignore offered video if you did not opt-in to auto-open your viewer's camera. * This should satisfy the two-way video call limitation in Safari: the iPad always shares its video and gets video from the person they are watching. * If the person they are watching did not auto-open your video: they ignore the attached video on your offer and don't display it.
84 lines
2.8 KiB
JavaScript
84 lines
2.8 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
|
|
|
|
// 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
|
|
|
|
// Booleans
|
|
'usePolling': Boolean, // use the polling API instead of WebSocket
|
|
'joinMessages': Boolean,
|
|
'exitMessages': Boolean,
|
|
'watchNotif': Boolean,
|
|
'muteSounds': Boolean,
|
|
'closeDMs': Boolean, // close unsolicited DMs
|
|
'appleCompat': Boolean, // Apple browser compatibility mode
|
|
|
|
// 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;
|