[mirotalksfu] - fix ls devices

هذا الالتزام موجود في:
Miroslav Pejic
2024-02-03 19:48:29 +01:00
الأصل 67105fd5af
التزام 875366d258
2 ملفات معدلة مع 22 إضافات و20 حذوفات

عرض الملف

@@ -1565,15 +1565,15 @@ function handleSelectsInit() {
initVideoSelect.onchange = async () => { initVideoSelect.onchange = async () => {
await changeCamera(initVideoSelect.value); await changeCamera(initVideoSelect.value);
videoSelect.selectedIndex = initVideoSelect.selectedIndex; videoSelect.selectedIndex = initVideoSelect.selectedIndex;
lS.setLocalStorageDevices(lS.MEDIA_TYPE.video, initVideoSelect.selectedIndex, initVideoSelect.value); await refreshLsDevices();
}; };
initMicrophoneSelect.onchange = () => { initMicrophoneSelect.onchange = async () => {
microphoneSelect.selectedIndex = initMicrophoneSelect.selectedIndex; microphoneSelect.selectedIndex = initMicrophoneSelect.selectedIndex;
lS.setLocalStorageDevices(lS.MEDIA_TYPE.audio, initMicrophoneSelect.selectedIndex, initMicrophoneSelect.value); await refreshLsDevices();
}; };
initSpeakerSelect.onchange = () => { initSpeakerSelect.onchange = async () => {
speakerSelect.selectedIndex = initSpeakerSelect.selectedIndex; speakerSelect.selectedIndex = initSpeakerSelect.selectedIndex;
lS.setLocalStorageDevices(lS.MEDIA_TYPE.speaker, initSpeakerSelect.selectedIndex, initSpeakerSelect.value); await refreshLsDevices();
}; };
} }
@@ -1606,23 +1606,19 @@ async function setSelectsInit() {
console.log('04.1 ----> Audio devices seems changed, use default index 0'); console.log('04.1 ----> Audio devices seems changed, use default index 0');
initMicrophoneSelect.selectedIndex = 0; initMicrophoneSelect.selectedIndex = 0;
microphoneSelect.selectedIndex = 0; microphoneSelect.selectedIndex = 0;
lS.setLocalStorageDevices( await refreshLsDevices();
lS.MEDIA_TYPE.audio,
initMicrophoneSelect.selectedIndex,
initMicrophoneSelect.value,
);
} }
if (lS.DEVICES_COUNT.speaker !== localStorageDevices.speaker.count) { if (lS.DEVICES_COUNT.speaker !== localStorageDevices.speaker.count) {
console.log('04.2 ----> Speaker devices seems changed, use default index 0'); console.log('04.2 ----> Speaker devices seems changed, use default index 0');
initSpeakerSelect.selectedIndex = 0; initSpeakerSelect.selectedIndex = 0;
speakerSelect.selectedIndex = 0; speakerSelect.selectedIndex = 0;
lS.setLocalStorageDevices(lS.MEDIA_TYPE.speaker, initSpeakerSelect.selectedIndex, initSpeakerSelect.value); await refreshLsDevices();
} }
if (lS.DEVICES_COUNT.video !== localStorageDevices.video.count) { if (lS.DEVICES_COUNT.video !== localStorageDevices.video.count) {
console.log('04.3 ----> Video devices seems changed, use default index 0'); console.log('04.3 ----> Video devices seems changed, use default index 0');
initVideoSelect.selectedIndex = 0; initVideoSelect.selectedIndex = 0;
videoSelect.selectedIndex = 0; videoSelect.selectedIndex = 0;
lS.setLocalStorageDevices(lS.MEDIA_TYPE.video, initVideoSelect.selectedIndex, initVideoSelect.value); await refreshLsDevices();
} }
// //
console.log('04.4 ----> Get Local Storage Devices after', lS.getLocalStorageDevices()); console.log('04.4 ----> Get Local Storage Devices after', lS.getLocalStorageDevices());
@@ -1630,6 +1626,12 @@ async function setSelectsInit() {
if (initVideoSelect.value) await changeCamera(initVideoSelect.value); if (initVideoSelect.value) await changeCamera(initVideoSelect.value);
} }
async function refreshLsDevices() {
lS.setLocalStorageDevices(lS.MEDIA_TYPE.video, videoSelect.selectedIndex, videoSelect.value);
lS.setLocalStorageDevices(lS.MEDIA_TYPE.audio, microphoneSelect.selectedIndex, microphoneSelect.value);
lS.setLocalStorageDevices(lS.MEDIA_TYPE.speaker, speakerSelect.selectedIndex, speakerSelect.value);
}
async function changeCamera(deviceId) { async function changeCamera(deviceId) {
if (initStream) { if (initStream) {
await stopTracks(initStream); await stopTracks(initStream);
@@ -1722,10 +1724,10 @@ function handleCameraMirror(video) {
function handleSelects() { function handleSelects() {
// devices options // devices options
videoSelect.onchange = () => { videoSelect.onchange = async () => {
videoQuality.selectedIndex = 0; videoQuality.selectedIndex = 0;
rc.closeThenProduce(RoomClient.mediaType.video, videoSelect.value); rc.closeThenProduce(RoomClient.mediaType.video, videoSelect.value);
lS.setLocalStorageDevices(lS.MEDIA_TYPE.video, videoSelect.selectedIndex, videoSelect.value); await refreshLsDevices();
}; };
videoQuality.onchange = () => { videoQuality.onchange = () => {
rc.closeThenProduce(RoomClient.mediaType.video, videoSelect.value); rc.closeThenProduce(RoomClient.mediaType.video, videoSelect.value);
@@ -1740,13 +1742,13 @@ function handleSelects() {
localStorageSettings.screen_fps = screenFps.selectedIndex; localStorageSettings.screen_fps = screenFps.selectedIndex;
lS.setSettings(localStorageSettings); lS.setSettings(localStorageSettings);
}; };
microphoneSelect.onchange = () => { microphoneSelect.onchange = async () => {
rc.closeThenProduce(RoomClient.mediaType.audio, microphoneSelect.value); rc.closeThenProduce(RoomClient.mediaType.audio, microphoneSelect.value);
lS.setLocalStorageDevices(lS.MEDIA_TYPE.audio, microphoneSelect.selectedIndex, microphoneSelect.value); await refreshLsDevices();
}; };
speakerSelect.onchange = () => { speakerSelect.onchange = async () => {
rc.attachSinkId(rc.myAudioEl, speakerSelect.value); rc.attachSinkId(rc.myAudioEl, speakerSelect.value);
lS.setLocalStorageDevices(lS.MEDIA_TYPE.speaker, speakerSelect.selectedIndex, speakerSelect.value); await refreshLsDevices();
}; };
switchPushToTalk.onchange = (e) => { switchPushToTalk.onchange = (e) => {
const producerExist = rc.producerExist(RoomClient.mediaType.audio); const producerExist = rc.producerExist(RoomClient.mediaType.audio);

عرض الملف

@@ -2383,7 +2383,7 @@ class RoomClient {
.then(() => { .then(() => {
console.log(`Success, audio output device attached: ${sinkId}`); console.log(`Success, audio output device attached: ${sinkId}`);
}) })
.catch((err) => { .catch(async (err) => {
let errorMessage = err; let errorMessage = err;
let speakerSelect = this.getId('speakerSelect'); let speakerSelect = this.getId('speakerSelect');
if (err.name === 'SecurityError') if (err.name === 'SecurityError')
@@ -2391,7 +2391,7 @@ class RoomClient {
console.error('Attach SinkId error: ', errorMessage); console.error('Attach SinkId error: ', errorMessage);
this.userLog('error', errorMessage, 'top-end', 6000); this.userLog('error', errorMessage, 'top-end', 6000);
speakerSelect.selectedIndex = 0; speakerSelect.selectedIndex = 0;
lS.setLocalStorageDevices(lS.MEDIA_TYPE.speaker, 0, speakerSelect.value); await refreshLsDevices();
}); });
} else { } else {
let error = `Browser seems doesn't support output device selection.`; let error = `Browser seems doesn't support output device selection.`;