From 9e718f9dd9b4d0bfb089bd3750892605b598817c Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Wed, 17 Apr 2024 23:39:17 +0200 Subject: [PATCH] webrtc: in publish page, prevent same device from appearing multiple times (#3261) --- internal/servers/webrtc/publish_index.html | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/servers/webrtc/publish_index.html b/internal/servers/webrtc/publish_index.html index f73459fa..63537ee2 100644 --- a/internal/servers/webrtc/publish_index.html +++ b/internal/servers/webrtc/publish_index.html @@ -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 = () => { return navigator.mediaDevices.enumerateDevices() .then((devices) => { for (const device of devices) { - switch (device.kind) { - case 'videoinput': - { - const opt = document.createElement('option'); - opt.value = device.deviceId; - opt.text = device.label; - videoForm.device.appendChild(opt); - } - break; + if (device.kind === 'videoinput' || device.kind === 'audioinput') { + const select = (device.kind === 'videoinput') ? videoForm.device : audioForm.device; - case 'audioinput': - { + if (!selectHasOption(select, device.deviceId)) { const opt = document.createElement('option'); opt.value = device.deviceId; opt.text = device.label; - audioForm.device.appendChild(opt); + select.appendChild(opt); } - break; } }