[mirotalksfu] - keep the devices settings in localStorage

هذا الالتزام موجود في:
Miroslav Pejic
2022-08-02 09:55:09 +02:00
الأصل 2b900d05f0
التزام 88a8b6b722
2 ملفات معدلة مع 59 إضافات و7 حذوفات

عرض الملف

@@ -892,12 +892,15 @@ function handleSelects() {
// devices options
microphoneSelect.onchange = () => {
rc.closeThenProduce(RoomClient.mediaType.audio, microphoneSelect.value);
rc.setLocalStorageDevices(RoomClient.mediaType.audio, microphoneSelect.selectedIndex, microphoneSelect.value);
};
speakerSelect.onchange = () => {
rc.attachSinkId(rc.myVideoEl, speakerSelect.value);
rc.setLocalStorageDevices(RoomClient.mediaType.speaker, speakerSelect.selectedIndex, speakerSelect.value);
};
videoSelect.onchange = () => {
rc.closeThenProduce(RoomClient.mediaType.video, videoSelect.value);
rc.setLocalStorageDevices(RoomClient.mediaType.video, videoSelect.selectedIndex, videoSelect.value);
};
// styling
BtnsAspectRatio.onchange = () => {

عرض الملف

@@ -41,6 +41,22 @@ const mediaType = {
video: 'videoType',
camera: 'cameraType',
screen: 'screenType',
speaker: 'speakerType',
};
const LOCAL_STORAGE_DEVICES = {
audio: {
index: null,
select: null,
},
speaker: {
index: null,
select: null,
},
video: {
index: null,
select: null,
},
};
const _EVENTS = {
@@ -558,19 +574,26 @@ class RoomClient {
// ####################################################
startLocalMedia() {
let localStorageDevices = this.getLocalStorageDevices();
console.log('08 ----> Get Local Storage Devices', localStorageDevices);
if (localStorageDevices) {
microphoneSelect.selectedIndex = localStorageDevices.audio.index;
speakerSelect.selectedIndex = localStorageDevices.speaker.index;
videoSelect.selectedIndex = localStorageDevices.video.index;
}
if (this.isAudioAllowed) {
console.log('08 ----> Start audio media');
console.log('09 ----> Start audio media');
this.produce(mediaType.audio, microphoneSelect.value);
} else {
setColor(startAudioButton, 'red');
console.log('08 ----> Audio is off');
console.log('09 ----> Audio is off');
}
if (this.isVideoAllowed) {
console.log('09 ----> Start video media');
console.log('10 ----> Start video media');
this.produce(mediaType.video, videoSelect.value);
} else {
setColor(startVideoButton, 'red');
console.log('09 ----> Video is off');
console.log('10 ----> Video is off');
this.setVideoOff(this.peer_info, false);
this.sendVideoOff();
}
@@ -1284,13 +1307,13 @@ class RoomClient {
}).then((result) => {
if (result.isConfirmed) {
startScreenButton.click();
console.log('10 ----> Screen is on');
console.log('11 ----> Screen is on');
} else {
console.log('10 ----> Screen is on');
console.log('11 ----> Screen is on');
}
});
} else {
console.log('10 ----> Screen is off');
console.log('11 ----> Screen is off');
}
}
@@ -3067,4 +3090,30 @@ class RoomClient {
);
}
}
// ####################################################
// LOCAL STORAGE DEVICES
// ####################################################
setLocalStorageDevices(type, index, select) {
switch (type) {
case RoomClient.mediaType.audio:
LOCAL_STORAGE_DEVICES.audio.index = index;
LOCAL_STORAGE_DEVICES.audio.select = select;
break;
case RoomClient.mediaType.video:
LOCAL_STORAGE_DEVICES.video.index = index;
LOCAL_STORAGE_DEVICES.video.select = select;
break;
case RoomClient.mediaType.speaker:
LOCAL_STORAGE_DEVICES.speaker.index = index;
LOCAL_STORAGE_DEVICES.speaker.select = select;
break;
}
localStorage.setItem('LOCAL_STORAGE_DEVICES', JSON.stringify(LOCAL_STORAGE_DEVICES));
}
getLocalStorageDevices() {
return JSON.parse(localStorage.getItem('LOCAL_STORAGE_DEVICES'));
}
}