From 9bdb87e9ef7169993fd474e88c295aafa0b3305c Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Fri, 17 May 2024 20:24:33 -0600 Subject: [PATCH] set the correct active camera number when it starts --- src/components/PhotoDialog.vue | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/PhotoDialog.vue b/src/components/PhotoDialog.vue index ec3456a8b..b28f82d03 100644 --- a/src/components/PhotoDialog.vue +++ b/src/components/PhotoDialog.vue @@ -211,6 +211,12 @@ export default class PhotoDialog extends Vue { if (cameraComponent) { this.numDevices = (await cameraComponent.devices(["videoinput"])).length; this.mirror = cameraComponent.facingMode === "user"; + // figure out which device is active + const currentDeviceId = cameraComponent.currentDeviceID(); + const devices = await cameraComponent.devices(["videoinput"]); + this.activeDeviceNumber = devices.findIndex( + (device) => device.deviceId === currentDeviceId, + ); } } @@ -218,7 +224,9 @@ export default class PhotoDialog extends Vue { const cameraComponent = this.$refs.camera as InstanceType; this.activeDeviceNumber = (this.activeDeviceNumber + 1) % this.numDevices; const devices = await cameraComponent?.devices(["videoinput"]); - cameraComponent?.changeCamera(devices[this.activeDeviceNumber].deviceId); + await cameraComponent?.changeCamera( + devices[this.activeDeviceNumber].deviceId, + ); } async takeImage(/* payload: MouseEvent */) {