mirror of
https://github.com/eliasstepanik/vdo.ninja.git
synced 2026-01-26 21:08:43 +00:00
Merge pull request #711 from steveseguin/fix_devices
Fix /devices multiple video inputs bug
This commit is contained in:
commit
0f7b09526d
@ -9,6 +9,7 @@ h1 {
|
|||||||
padding:10px;
|
padding:10px;
|
||||||
background-color:#457b9d;
|
background-color:#457b9d;
|
||||||
color:white;
|
color:white;
|
||||||
|
border-bottom: 2px solid #3b6a87;
|
||||||
}
|
}
|
||||||
|
|
||||||
.device {
|
.device {
|
||||||
@ -18,6 +19,9 @@ h1 {
|
|||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
user-select: none;
|
||||||
|
background: #d0d0d0;
|
||||||
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.device.selected {
|
.device.selected {
|
||||||
@ -55,12 +59,13 @@ h1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.notice {
|
.notice {
|
||||||
background-color: orange;
|
background-color: #fff18c;
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
padding: 20px 20px;
|
padding: 20px 20px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
line-height: 1.4em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.notice a {
|
.notice a {
|
||||||
@ -89,7 +94,7 @@ h1 {
|
|||||||
left: 10%;
|
left: 10%;
|
||||||
color: white;
|
color: white;
|
||||||
overflow-wrap: anywhere;
|
overflow-wrap: anywhere;
|
||||||
background: #141926;
|
background: #2c3754;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
box-shadow: 0px 0px 10px 5px #00000047;
|
box-shadow: 0px 0px 10px 5px #00000047;
|
||||||
border: 1px solid #333c52;
|
border: 1px solid #333c52;
|
||||||
|
|||||||
43
devices.html
43
devices.html
@ -22,7 +22,8 @@
|
|||||||
<div class="notice">
|
<div class="notice">
|
||||||
Device IDs are bound to a combination of domain and browser. <br />If
|
Device IDs are bound to a combination of domain and browser. <br />If
|
||||||
you want to use electron-capture, open this URL on the electron-capture
|
you want to use electron-capture, open this URL on the electron-capture
|
||||||
app.
|
app. <br/>
|
||||||
|
Click device names to preset them. Select multiple audio inputs by clicking multiple devices.
|
||||||
</div>
|
</div>
|
||||||
<div class="notice">
|
<div class="notice">
|
||||||
Check for browser and camera capabilities <a href="/supports">here</a>.
|
Check for browser and camera capabilities <a href="/supports">here</a>.
|
||||||
@ -41,7 +42,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="sharedDevices" style="display: none">
|
<div id="sharedDevices" style="display: none">
|
||||||
<span>Click to copy. Send this to your host:</span>
|
<span>Click to copy. Use this URL to preset audio/video devices.</span>
|
||||||
<span id="close" onclick="this.parentNode.style.display='none'">×</span>
|
<span id="close" onclick="this.parentNode.style.display='none'">×</span>
|
||||||
<input id="devicesUrl" value="" />
|
<input id="devicesUrl" value="" />
|
||||||
</div>
|
</div>
|
||||||
@ -63,15 +64,19 @@
|
|||||||
return value.kind === "videoinput";
|
return value.kind === "videoinput";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sanitizeDeviceName(deviceName) {
|
||||||
|
return String(deviceName).toLowerCase().replace(/[\W]+/g, "_");
|
||||||
|
}
|
||||||
|
|
||||||
function addDevice(element) {
|
function addDevice(element) {
|
||||||
const info = element.getElementsByClassName("device-id")[0];
|
const type = element.dataset.deviceType;
|
||||||
const type = info.dataset.deviceType;
|
const device = sanitizeDeviceName(element.querySelector('span').innerText);
|
||||||
|
|
||||||
if (type === "audioinput") {
|
if (type === "audioinput") {
|
||||||
setAudioSearchParams(info);
|
setAudioSearchParams(element);
|
||||||
}
|
}
|
||||||
if (type === "videoinput") {
|
if (type === "videoinput") {
|
||||||
setVideoSearchParams(info);
|
setVideoSearchParams(element);
|
||||||
}
|
}
|
||||||
if (type === "audiooutput") {
|
if (type === "audiooutput") {
|
||||||
return;
|
return;
|
||||||
@ -84,9 +89,9 @@
|
|||||||
|
|
||||||
function setAudioSearchParams(info) {
|
function setAudioSearchParams(info) {
|
||||||
// Device was already selected
|
// Device was already selected
|
||||||
if (info.parentNode.className === "device selected") {
|
if (info.className === "device selected") {
|
||||||
// Remove device from list of selected devices
|
// Remove device from list of selected devices
|
||||||
const index = audioInputDevices.indexOf(info.innerText);
|
const index = audioInputDevices.indexOf(device);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
audioInputDevices.splice(index, 1);
|
audioInputDevices.splice(index, 1);
|
||||||
}
|
}
|
||||||
@ -101,7 +106,8 @@
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Device is unselected
|
// Device is unselected
|
||||||
audioInputDevices.push(info.innerText);
|
|
||||||
|
audioInputDevices.push(device);
|
||||||
url.searchParams.set("ad", audioInputDevices.join(","));
|
url.searchParams.set("ad", audioInputDevices.join(","));
|
||||||
element.className = "device selected";
|
element.className = "device selected";
|
||||||
}
|
}
|
||||||
@ -112,11 +118,12 @@
|
|||||||
*/
|
*/
|
||||||
function setVideoSearchParams(info) {
|
function setVideoSearchParams(info) {
|
||||||
// Device was already selected
|
// Device was already selected
|
||||||
if (info.parentNode.className === "device selected") {
|
if (info.className === "device selected") {
|
||||||
info.parentNode.className = "device";
|
element.className = "device";
|
||||||
|
|
||||||
|
|
||||||
// Set the url param to the devices that are left
|
// Set the url param to the devices that are left
|
||||||
url.searchParams.set("vd", info.innerText);
|
url.searchParams.set("vd", device);
|
||||||
element.className = "device";
|
element.className = "device";
|
||||||
|
|
||||||
// If no devices remained, just remove the param completely
|
// If no devices remained, just remove the param completely
|
||||||
@ -125,7 +132,13 @@
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Device is unselected
|
// Device is unselected
|
||||||
url.searchParams.set("vd", info.innerText);
|
try {
|
||||||
|
element.parentElement.querySelector('.device.selected').className = "device";
|
||||||
|
} catch (error) {
|
||||||
|
console.log("There was no video device already selected.");
|
||||||
|
}
|
||||||
|
|
||||||
|
url.searchParams.set("vd", device);
|
||||||
element.className = "device selected";
|
element.className = "device selected";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,9 +160,9 @@
|
|||||||
.sort()
|
.sort()
|
||||||
.forEach(([key, value]) => {
|
.forEach(([key, value]) => {
|
||||||
output += `
|
output += `
|
||||||
<div class='device' onclick='addDevice(this)'>
|
<div class='device' onclick='addDevice(this)' data-device-type='${value.kind}'>
|
||||||
<span class='device-name'>${value.label}</span>
|
<span class='device-name'>${value.label}</span>
|
||||||
<span class='device-id' data-device-type='${value.kind}'>
|
<span class='device-id'>
|
||||||
${value.deviceId}
|
${value.deviceId}
|
||||||
</span>
|
</span>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user