webrtc: in publish page, prevent same device from appearing multiple times (#3261)

This commit is contained in:
Alessandro Ros 2024-04-17 23:39:17 +02:00 committed by GitHub
parent 851358a379
commit 9e718f9dd9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -577,28 +577,28 @@ const onPublish = () => {
} }
}; };
const selectHasOption = (select, option) => {
for (const opt of select.querySelectorAll('option')) {
if (opt.value === option) {
return true;
}
}
return false;
};
const populateDevices = () => { const populateDevices = () => {
return navigator.mediaDevices.enumerateDevices() return navigator.mediaDevices.enumerateDevices()
.then((devices) => { .then((devices) => {
for (const device of devices) { for (const device of devices) {
switch (device.kind) { if (device.kind === 'videoinput' || device.kind === 'audioinput') {
case 'videoinput': const select = (device.kind === 'videoinput') ? videoForm.device : audioForm.device;
{
const opt = document.createElement('option');
opt.value = device.deviceId;
opt.text = device.label;
videoForm.device.appendChild(opt);
}
break;
case 'audioinput': if (!selectHasOption(select, device.deviceId)) {
{
const opt = document.createElement('option'); const opt = document.createElement('option');
opt.value = device.deviceId; opt.value = device.deviceId;
opt.text = device.label; opt.text = device.label;
audioForm.device.appendChild(opt); select.appendChild(opt);
} }
break;
} }
} }