[mirotalk] - save init audio/video status

This commit is contained in:
Miroslav Pejic
2023-07-22 19:11:38 +02:00
parent 5e9830ef06
commit 5b2713472a
2 changed files with 58 additions and 4 deletions
+17
View File
@@ -1346,6 +1346,20 @@ async function loadLocalStorage() {
}
}
/**
* Check int config from local storage
*/
async function checkInitConfig() {
const initConfig = lS.getInitConfig();
console.log('Get init config', initConfig);
if (initConfig) {
initAudioBtn = getId('initAudioBtn');
initVideoBtn = getId('initVideoBtn');
if (useAudio && !initConfig.audio) initAudioBtn.click();
if (useVideo && !initConfig.video) initVideoBtn.click();
}
}
/**
* Change init camera by device id
* @param {string} deviceId
@@ -1365,6 +1379,7 @@ async function changeInitCamera(deviceId) {
initVideo.srcObject = camStream;
initStream = camStream;
console.log('Success attached init video stream', initStream.getVideoTracks()[0].getSettings());
checkInitConfig();
})
.catch((err) => {
console.error('[Error] changeInitCamera', err);
@@ -4504,6 +4519,7 @@ function handleAudio(e, init, force = null) {
setTippy(initAudioBtn, myAudioStatus ? 'Stop the audio' : 'Start the audio', 'top');
getId('initMicrophoneSelect').disabled = !myAudioStatus;
getId('initSpeakerSelect').disabled = !myAudioStatus;
lS.setInitConfig(lS.MEDIA_TYPE.audio, myAudioStatus);
}
setMyAudioStatus(myAudioStatus);
}
@@ -4533,6 +4549,7 @@ function handleVideo(e, init, force = null) {
setTippy(initVideoBtn, myVideoStatus ? 'Stop the video' : 'Start the video', 'top');
initVideo.style.display = myVideoStatus ? 'block' : 'none';
initVideoSelect.disabled = !myVideoStatus;
lS.setInitConfig(lS.MEDIA_TYPE.video, myVideoStatus);
}
setMyVideoStatus(myVideoStatus);
}
+41 -4
View File
@@ -8,6 +8,11 @@ class LocalStorage {
speaker: 'speaker',
};
this.P2P_INIT_CONFIG = {
audio: true,
video: true,
};
this.DEVICES_COUNT = {
audio: 0,
speaker: 0,
@@ -33,6 +38,30 @@ 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.P2P_INIT_CONFIG.audio = status;
break;
case this.MEDIA_TYPE.video:
this.P2P_INIT_CONFIG.video = status;
break;
}
this.setObjectLocalStorage('P2P_INIT_CONFIG', this.P2P_INIT_CONFIG);
}
setLocalStorageDevices(type, index, select) {
switch (type) {
case this.MEDIA_TYPE.audio:
@@ -53,15 +82,23 @@ class LocalStorage {
default:
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('P2P_INIT_CONFIG');
}
getLocalStorageDevices() {
return JSON.parse(localStorage.getItem('LOCAL_STORAGE_DEVICES'));
return this.getObjectLocalStorage('LOCAL_STORAGE_DEVICES');
}
setObjectLocalStorage(name, object) {
localStorage.setItem(name, JSON.stringify(object));
getItemLocalStorage(key) {
localStorage.getItem(key);
}
getObjectLocalStorage(name) {