[mirotalksfu] - save init audio/video status

هذا الالتزام موجود في:
Miroslav Pejic
2023-07-22 18:32:29 +02:00
الأصل 495ed3ec09
التزام 2f5e27f052
2 ملفات معدلة مع 86 إضافات و28 حذوفات

عرض الملف

@@ -5,9 +5,16 @@ class LocalStorage {
this.MEDIA_TYPE = { this.MEDIA_TYPE = {
audio: 'audio', audio: 'audio',
video: 'video', video: 'video',
audioVideo: 'audioVideo',
speaker: 'speaker', speaker: 'speaker',
}; };
this.INIT_CONFIG = {
audio: true,
video: true,
audioVideo: true,
};
this.DEVICES_COUNT = { this.DEVICES_COUNT = {
audio: 0, audio: 0,
speaker: 0, speaker: 0,
@@ -33,6 +40,33 @@ class LocalStorage {
}; };
} }
// ####################################################
// SET LOCAL STORAGE
// ####################################################
setItemLocalStorage(key, value) {
localStorage.setItem(key, value);
}
setObjectLocalStorage(name, object) {
localStorage.setItem(name, JSON.stringify(object));
}
setInitConfig(type, status) {
switch (type) {
case this.MEDIA_TYPE.audio:
this.INIT_CONFIG.audio = status;
break;
case this.MEDIA_TYPE.video:
this.INIT_CONFIG.video = status;
break;
case this.MEDIA_TYPE.audioVideo:
this.INIT_CONFIG.audioVideo = status;
break;
}
this.setObjectLocalStorage('INIT_CONFIG', this.INIT_CONFIG);
}
setLocalStorageDevices(type, index, select) { setLocalStorageDevices(type, index, select) {
switch (type) { switch (type) {
case this.MEDIA_TYPE.audio: case this.MEDIA_TYPE.audio:
@@ -53,25 +87,25 @@ class LocalStorage {
default: default:
break; break;
} }
localStorage.setItem('LOCAL_STORAGE_DEVICES', JSON.stringify(this.LOCAL_STORAGE_DEVICES)); this.setObjectLocalStorage('LOCAL_STORAGE_DEVICES', this.LOCAL_STORAGE_DEVICES);
}
// ####################################################
// GET LOCAL STORAGE
// ####################################################
getInitConfig() {
return this.getObjectLocalStorage('INIT_CONFIG');
} }
getLocalStorageDevices() { getLocalStorageDevices() {
return JSON.parse(localStorage.getItem('LOCAL_STORAGE_DEVICES')); return this.getObjectLocalStorage('LOCAL_STORAGE_DEVICES');
}
setItemLocalStorage(key, value) {
localStorage.setItem(key, value);
} }
getItemLocalStorage(key) { getItemLocalStorage(key) {
localStorage.getItem(key); localStorage.getItem(key);
} }
setObjectLocalStorage(name, object) {
localStorage.setItem(name, JSON.stringify(object));
}
getObjectLocalStorage(name) { getObjectLocalStorage(name) {
return JSON.parse(localStorage.getItem(name)); return JSON.parse(localStorage.getItem(name));
} }

عرض الملف

@@ -254,18 +254,10 @@ async function initEnumerateDevices() {
if (navigator.getDisplayMedia || navigator.mediaDevices.getDisplayMedia) { if (navigator.getDisplayMedia || navigator.mediaDevices.getDisplayMedia) {
BUTTONS.main.startScreenButton && show(initStartScreenButton); BUTTONS.main.startScreenButton && show(initStartScreenButton);
} }
whoAreYou();
if (!isVideoAllowed) {
hide(initVideo);
hide(initVideoSelect);
}
if (!isAudioAllowed) {
hide(initMicrophoneSelect);
hide(initSpeakerSelect);
}
if (!isAudioAllowed && !isVideoAllowed && !joinRoomWithoutAudioVideo) { if (!isAudioAllowed && !isVideoAllowed && !joinRoomWithoutAudioVideo) {
openURL(`/permission?room_id=${room_id}&message=Not allowed both Audio and Video`); openURL(`/permission?room_id=${room_id}&message=Not allowed both Audio and Video`);
} else { } else {
whoAreYou();
setButtonsInit(); setButtonsInit();
setSelectsInit(); setSelectsInit();
handleSelectsInit(); handleSelectsInit();
@@ -463,6 +455,23 @@ function getRoomPassword() {
} }
} }
// ####################################################
// INIT CONFIG
// ####################################################
function checkInitConfig() {
const initConfig = lS.getInitConfig();
console.log('04.5 ----> Get init config', initConfig);
if (initConfig) {
if (isAudioVideoAllowed && !initConfig.audioVideo) {
handleAudioVideo();
} else {
if (isAudioAllowed && !initConfig.audio) handleAudio();
if (isVideoAllowed && !initConfig.video) handleVideo();
}
}
}
// #################################################### // ####################################################
// SOME PEER INFO // SOME PEER INFO
// #################################################### // ####################################################
@@ -552,36 +561,50 @@ function whoAreYou() {
getPeerInfo(); getPeerInfo();
joinRoom(peer_name, room_id); joinRoom(peer_name, room_id);
}); });
if (!isVideoAllowed) {
hide(initVideo);
hide(initVideoSelect);
}
if (!isAudioAllowed) {
hide(initMicrophoneSelect);
hide(initSpeakerSelect);
}
} }
function handleAudio(e) { function handleAudio() {
isAudioAllowed = isAudioAllowed ? false : true; isAudioAllowed = isAudioAllowed ? false : true;
e.target.className = 'fas fa-microphone' + (isAudioAllowed ? '' : '-slash'); initAudioButton.className = 'fas fa-microphone' + (isAudioAllowed ? '' : '-slash');
setColor(e.target, isAudioAllowed ? 'white' : 'red'); setColor(initAudioButton, isAudioAllowed ? 'white' : 'red');
setColor(startAudioButton, isAudioAllowed ? 'white' : 'red'); setColor(startAudioButton, isAudioAllowed ? 'white' : 'red');
checkInitAudio(isAudioAllowed); checkInitAudio(isAudioAllowed);
lS.setInitConfig(lS.MEDIA_TYPE.audio, isAudioAllowed);
} }
function handleVideo(e) { function handleVideo() {
isVideoAllowed = isVideoAllowed ? false : true; isVideoAllowed = isVideoAllowed ? false : true;
e.target.className = 'fas fa-video' + (isVideoAllowed ? '' : '-slash'); initVideoButton.className = 'fas fa-video' + (isVideoAllowed ? '' : '-slash');
setColor(e.target, isVideoAllowed ? 'white' : 'red'); setColor(initVideoButton, isVideoAllowed ? 'white' : 'red');
setColor(startVideoButton, isVideoAllowed ? 'white' : 'red'); setColor(startVideoButton, isVideoAllowed ? 'white' : 'red');
checkInitVideo(isVideoAllowed); checkInitVideo(isVideoAllowed);
lS.setInitConfig(lS.MEDIA_TYPE.video, isVideoAllowed);
} }
function handleAudioVideo(e) { function handleAudioVideo() {
isAudioVideoAllowed = isAudioVideoAllowed ? false : true; isAudioVideoAllowed = isAudioVideoAllowed ? false : true;
isAudioAllowed = isAudioVideoAllowed; isAudioAllowed = isAudioVideoAllowed;
isVideoAllowed = isAudioVideoAllowed; isVideoAllowed = isAudioVideoAllowed;
lS.setInitConfig(lS.MEDIA_TYPE.audio, isAudioVideoAllowed);
lS.setInitConfig(lS.MEDIA_TYPE.video, isAudioVideoAllowed);
lS.setInitConfig(lS.MEDIA_TYPE.audioVideo, isAudioVideoAllowed);
initAudioButton.className = 'fas fa-microphone' + (isAudioVideoAllowed ? '' : '-slash'); initAudioButton.className = 'fas fa-microphone' + (isAudioVideoAllowed ? '' : '-slash');
initVideoButton.className = 'fas fa-video' + (isAudioVideoAllowed ? '' : '-slash'); initVideoButton.className = 'fas fa-video' + (isAudioVideoAllowed ? '' : '-slash');
initAudioVideoButton.className = 'fas fa-eye' + (isAudioVideoAllowed ? '' : '-slash');
if (!isAudioVideoAllowed) { if (!isAudioVideoAllowed) {
hide(initAudioButton); hide(initAudioButton);
hide(initVideoButton); hide(initVideoButton);
} }
e.target.className = 'fas fa-eye' + (isAudioVideoAllowed ? '' : '-slash'); setColor(initAudioVideoButton, isAudioVideoAllowed ? 'white' : 'red');
setColor(e.target, isAudioVideoAllowed ? 'white' : 'red');
setColor(initAudioButton, isAudioAllowed ? 'white' : 'red'); setColor(initAudioButton, isAudioAllowed ? 'white' : 'red');
setColor(initVideoButton, isVideoAllowed ? 'white' : 'red'); setColor(initVideoButton, isVideoAllowed ? 'white' : 'red');
setColor(startAudioButton, isAudioAllowed ? 'white' : 'red'); setColor(startAudioButton, isAudioAllowed ? 'white' : 'red');
@@ -1247,6 +1270,7 @@ async function changeCamera(deviceId) {
'04.5 ----> Success attached init cam video stream', '04.5 ----> Success attached init cam video stream',
initStream.getVideoTracks()[0].getSettings(), initStream.getVideoTracks()[0].getSettings(),
); );
checkInitConfig();
}) })
.catch((err) => { .catch((err) => {
console.error('[Error] changeCamera', err); console.error('[Error] changeCamera', err);