[mirotalksfu] - #112 keep settings on local storage

هذا الالتزام موجود في:
Miroslav Pejic
2023-07-28 20:18:28 +02:00
الأصل 7af2f26790
التزام cbfc279edd
4 ملفات معدلة مع 67 إضافات و25 حذوفات

عرض الملف

@@ -15,6 +15,14 @@ class LocalStorage {
audioVideo: true, audioVideo: true,
}; };
this.SFU_SETTINGS = {
video_obj_fit: 'cover',
video_controls: 'off',
theme: 'dark',
buttons_bar: 'vertical',
pin_grid: 'vertical',
};
this.DEVICES_COUNT = { this.DEVICES_COUNT = {
audio: 0, audio: 0,
speaker: 0, speaker: 0,
@@ -52,6 +60,11 @@ class LocalStorage {
localStorage.setItem(name, JSON.stringify(object)); localStorage.setItem(name, JSON.stringify(object));
} }
setSettings(settings) {
this.SFU_SETTINGS = settings;
this.setObjectLocalStorage('SFU_SETTINGS', this.SFU_SETTINGS);
}
setInitConfig(type, status) { setInitConfig(type, status) {
switch (type) { switch (type) {
case this.MEDIA_TYPE.audio: case this.MEDIA_TYPE.audio:
@@ -94,6 +107,10 @@ class LocalStorage {
// GET LOCAL STORAGE // GET LOCAL STORAGE
// #################################################### // ####################################################
getSettings() {
return this.getObjectLocalStorage('SFU_SETTINGS');
}
getInitConfig() { getInitConfig() {
return this.getObjectLocalStorage('INIT_CONFIG'); return this.getObjectLocalStorage('INIT_CONFIG');
} }

عرض الملف

@@ -55,12 +55,16 @@ const wbHeight = 600;
const swalImageUrl = '../images/pricing-illustration.svg'; const swalImageUrl = '../images/pricing-illustration.svg';
const lS = new LocalStorage(); const lS = new LocalStorage();
const localStorageSettings = lS.getObjectLocalStorage('MIROTALK_SFU_SETTINGS'); // Get Settings from localStorage
const localStorageSettings = lS.getObjectLocalStorage('SFU_SETTINGS');
const lsSettings = localStorageSettings const lsSettings = localStorageSettings
? localStorageSettings ? localStorageSettings
: { : {
theme: 'dark', video_obj_fit: 2, // cover
//... video_controls: BtnVideoControls.selectedIndex,
theme: selectTheme.selectedIndex,
buttons_bar: BtnsBarPosition.selectedIndex,
pin_grid: pinVideoPosition.selectedIndex,
}; };
// #################################################### // ####################################################
@@ -131,7 +135,7 @@ let initStream = null;
// #################################################### // ####################################################
function initClient() { function initClient() {
setTheme(lsSettings.theme); setTheme();
if (!DetectRTC.isMobileDevice) { if (!DetectRTC.isMobileDevice) {
setTippy('shareButton', 'Share room', 'right'); setTippy('shareButton', 'Share room', 'right');
setTippy('hideMeButton', 'Toggle hide me', 'right'); setTippy('hideMeButton', 'Toggle hide me', 'right');
@@ -837,6 +841,7 @@ function roomIsReady() {
BUTTONS.settings.lobbyButton && show(lobbyButton); BUTTONS.settings.lobbyButton && show(lobbyButton);
BUTTONS.main.aboutButton && show(aboutButton); BUTTONS.main.aboutButton && show(aboutButton);
if (!DetectRTC.isMobileDevice) show(pinUnpinGridDiv); if (!DetectRTC.isMobileDevice) show(pinUnpinGridDiv);
loadSettings();
handleButtons(); handleButtons();
handleSelects(); handleSelects();
handleInputs(); handleInputs();
@@ -920,6 +925,21 @@ function stopRecordingTimer() {
clearInterval(recTimer); clearInterval(recTimer);
} }
// ####################################################
// LOAD SETTINGS
// ####################################################
function loadSettings() {
BtnVideoObjectFit.selectedIndex = lsSettings.video_obj_fit;
BtnVideoControls.selectedIndex = lsSettings.video_controls;
BtnsBarPosition.selectedIndex = lsSettings.buttons_bar;
pinVideoPosition.selectedIndex = lsSettings.pin_grid;
rc.handleVideoObjectFit(BtnVideoObjectFit.value);
rc.handleVideoControls(BtnVideoControls.value);
rc.changeBtnsBarPosition(BtnsBarPosition.value);
rc.togglePin(pinVideoPosition.value);
}
// #################################################### // ####################################################
// HTML BUTTONS // HTML BUTTONS
// #################################################### // ####################################################
@@ -1347,25 +1367,33 @@ function handleSelects() {
rc.lobbyToggle(); rc.lobbyToggle();
}; };
// styling // styling
BtnsAspectRatio.onchange = () => { BtnAspectRatio.onchange = () => {
setAspectRatio(BtnsAspectRatio.value); setAspectRatio(BtnAspectRatio.value);
}; };
BtnVideoObjectFit.onchange = () => { BtnVideoObjectFit.onchange = () => {
rc.handleVideoObjectFit(BtnVideoObjectFit.value); rc.handleVideoObjectFit(BtnVideoObjectFit.value);
lsSettings.video_obj_fit = BtnVideoObjectFit.selectedIndex;
lS.setSettings(lsSettings);
}; // cover }; // cover
BtnVideoObjectFit.selectedIndex = 2;
BtnVideoControls.onchange = () => { BtnVideoControls.onchange = () => {
rc.handleVideoControls(BtnVideoControls.value); rc.handleVideoControls(BtnVideoControls.value);
lsSettings.video_controls = BtnVideoControls.selectedIndex;
lS.setSettings(lsSettings);
}; };
selectTheme.onchange = () => { selectTheme.onchange = () => {
setTheme(selectTheme.value); lsSettings.theme = selectTheme.selectedIndex;
lS.setSettings(lsSettings);
setTheme();
}; };
BtnsBarPosition.onchange = () => { BtnsBarPosition.onchange = () => {
rc.changeBtnsBarPosition(BtnsBarPosition.value); rc.changeBtnsBarPosition(BtnsBarPosition.value);
lsSettings.buttons_bar = BtnsBarPosition.selectedIndex;
lS.setSettings(lsSettings);
}; };
pinVideoPosition.onchange = () => { pinVideoPosition.onchange = () => {
rc.togglePin(pinVideoPosition.value); rc.togglePin(pinVideoPosition.value);
lsSettings.pin_grid = pinVideoPosition.selectedIndex;
lS.setSettings(lsSettings);
}; };
// chat // chat
showChatOnMsg.onchange = (e) => { showChatOnMsg.onchange = (e) => {
@@ -1387,8 +1415,7 @@ function handleSelects() {
}; };
whiteboardGhostButton.onclick = (e) => { whiteboardGhostButton.onclick = (e) => {
wbIsBgTransparent = !wbIsBgTransparent; wbIsBgTransparent = !wbIsBgTransparent;
//setWhiteboardBgColor(wbIsBgTransparent ? 'rgba(0, 0, 0, 0.100)' : wbBackgroundColorEl.value); wbIsBgTransparent ? wbCanvasBackgroundColor('rgba(0, 0, 0, 0.100)') : setTheme();
wbIsBgTransparent ? wbCanvasBackgroundColor('rgba(0, 0, 0, 0.100)') : setTheme(lsSettings.theme);
}; };
} }
@@ -2346,7 +2373,9 @@ function getParticipantAvatar(peerName) {
// SET THEME // SET THEME
// #################################################### // ####################################################
function setTheme(theme) { function setTheme() {
selectTheme.selectedIndex = lsSettings.theme;
const theme = selectTheme.value;
switch (theme) { switch (theme) {
case 'dark': case 'dark':
swalBackground = 'radial-gradient(#393939, #000000)'; swalBackground = 'radial-gradient(#393939, #000000)';
@@ -2420,8 +2449,6 @@ function setTheme(theme) {
break; break;
//... //...
} }
lsSettings.theme = theme;
lS.setObjectLocalStorage('MIROTALK_SFU_SETTINGS', lsSettings);
wbIsBgTransparent = false; wbIsBgTransparent = false;
if (rc) rc.isChatBgTransparent = false; if (rc) rc.isChatBgTransparent = false;
} }
@@ -2492,8 +2519,8 @@ function adaptAspectRatio(participantsCount) {
desktop = 1; // (4:3) desktop = 1; // (4:3)
mobile = 3; // (1:1) mobile = 3; // (1:1)
} }
BtnsAspectRatio.selectedIndex = DetectRTC.isMobileDevice ? mobile : desktop; BtnAspectRatio.selectedIndex = DetectRTC.isMobileDevice ? mobile : desktop;
setAspectRatio(BtnsAspectRatio.selectedIndex); setAspectRatio(BtnAspectRatio.selectedIndex);
} }
// #################################################### // ####################################################

عرض الملف

@@ -2504,7 +2504,7 @@ class RoomClient {
} }
handleVideoControls(value) { handleVideoControls(value) {
isVideoControlsOn = value == 'On' ? true : false; isVideoControlsOn = value == 'on' ? true : false;
let cameras = this.getEcN('Camera'); let cameras = this.getEcN('Camera');
for (let i = 0; i < cameras.length; i++) { for (let i = 0; i < cameras.length; i++) {
let cameraId = cameras[i].id.replace('__video', ''); let cameraId = cameras[i].id.replace('__video', '');
@@ -3153,11 +3153,9 @@ class RoomClient {
chatToggleBg() { chatToggleBg() {
this.isChatBgTransparent = !this.isChatBgTransparent; this.isChatBgTransparent = !this.isChatBgTransparent;
if (this.isChatBgTransparent) { this.isChatBgTransparent
document.documentElement.style.setProperty('--msger-bg', 'rgba(0, 0, 0, 0.100)'); ? document.documentElement.style.setProperty('--msger-bg', 'rgba(0, 0, 0, 0.100)')
} else { : setTheme();
setTheme(lsSettings.theme);
}
} }
chatClean() { chatClean() {

عرض الملف

@@ -298,7 +298,7 @@ access to use this app.
<br /> <br />
<p>Aspect ratio:</p> <p>Aspect ratio:</p>
<br /> <br />
<select id="BtnsAspectRatio" class="form-select text-light bg-dark"> <select id="BtnAspectRatio" class="form-select text-light bg-dark">
<option value="0">default</option> <option value="0">default</option>
<option value="1">4:3</option> <option value="1">4:3</option>
<option value="2">16:9</option> <option value="2">16:9</option>
@@ -319,8 +319,8 @@ access to use this app.
<p>Video Controls:</p> <p>Video Controls:</p>
<br /> <br />
<select id="BtnVideoControls" class="form-select text-light bg-dark"> <select id="BtnVideoControls" class="form-select text-light bg-dark">
<option value="Off">Off</option> <option value="off">off</option>
<option value="On">On</option> <option value="on">on</option>
</select> </select>
<br /> <br />
</div> </div>