forked from External/mediamtx
webrtc: in publish page, prevent same device from appearing multiple times (#3261)
This commit is contained in:
parent
851358a379
commit
9e718f9dd9
1 changed files with 13 additions and 13 deletions
|
|
@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue