diff --git a/web/index.html b/web/index.html
index 37f9a6f..8145b63 100644
--- a/web/index.html
+++ b/web/index.html
@@ -275,7 +275,22 @@
Settings
-
+
+
+ -
+
+ Select New Capture Device
+
+
+
+
+
+
+
+
+
diff --git a/web/index.js b/web/index.js
index 597d710..4862a8c 100644
--- a/web/index.js
+++ b/web/index.js
@@ -23,6 +23,8 @@ const displayMediaOptions = {
},
audio: false
}
+
+
let dialogWindow, autoModeTimer, croppedVideoTimer, currentText;
let audioSources, audioDeviceIndex;
@@ -73,6 +75,7 @@ const croppedVideoCanvas = document.getElementById("croppedVideoCanvas");
const croppedVideoCtx = croppedVideoCanvas.getContext("2d");
const settingsDialog = document.getElementById("settingsDialog");
const dialogCloseButton = document.getElementById("dialogCloseButton");
+const captureSelect = document.getElementById("captureSource");
init();
@@ -80,6 +83,7 @@ function init() {
(async() => {
loadProfiles();
loadAnki();
+ getCaptureDevices();
})();
}
@@ -87,6 +91,30 @@ function selectApplication() {
startCapture();
}
+async function getCaptureDevices() {
+ if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
+ console.log("enumerateDevices() not supported.");
+ return;
+ }
+
+ captureSelect.options.length = 0;
+ navigator.mediaDevices.enumerateDevices().then(function(devices) {
+ devices.forEach(function(device) {
+ if (device.kind == "videoinput") {
+ const option = document.createElement('option');
+ option.value = device.deviceId;
+ option.text = device.label || `source ${captureSelect.length +1}`;
+ captureSelect.appendChild(option)
+ }
+ })
+ });
+
+}
+
+function selectCaptureDevice() {
+ startDeviceCapture();
+}
+
async function startCapture(){
try {
videoElement.srcObject = await navigator.mediaDevices.getDisplayMedia(displayMediaOptions);
@@ -98,6 +126,23 @@ async function startCapture(){
}
}
+async function startDeviceCapture(){
+ const videoSource = captureSelect.value;
+ const userMediaOptions = {
+ video: {width: 1920, height: 1080, deviceId: videoSource ? {exact: videoSource} : undefined},
+ audio: false
+ }
+ try {
+ videoElement.srcObject = await navigator.mediaDevices.getUserMedia(userMediaOptions);
+ getCaptureDevices();
+ if (settingsDialog.open) {
+ closeSettings();
+ }
+ }catch(err) {
+ console.error("Error" + err)
+ }
+}
+
function videoOnLoad(element) {
videoLoaded = true;
resizeCanvas(element);