From f05d1b6a10380435f89372e274a1d4e0f1124086 Mon Sep 17 00:00:00 2001 From: Neko Ayaka Date: Fri, 4 Oct 2024 01:27:56 +0800 Subject: [PATCH] feat(ui): selected camera Signed-off-by: Neko Ayaka --- app/components/Scan.vue | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/components/Scan.vue b/app/components/Scan.vue index 5307709..0bc2639 100644 --- a/app/components/Scan.vue +++ b/app/components/Scan.vue @@ -48,13 +48,18 @@ const { devices } = useDevicesList({ const cameraSignalStatus = ref(CameraSignalStatus.Waiting) const cameras = computed(() => devices.value.filter(i => i.kind === 'videoinput')) -const selectedCamera = ref(cameras.value[0]?.deviceId) +const selectedCamera = useLocalStorage('qrs-selected-camera', cameras.value[0]?.deviceId) watchEffect(() => { if (!selectedCamera.value) selectedCamera.value = cameras.value[0]?.deviceId }) +watch(cameras, () => { + if (selectedCamera.value && cameras.value.filter(i => i.deviceId === selectedCamera.value).length === 0) + selectedCamera.value = '' +}) + // const results = defineModel>('results', { default: new Set() }) let stream: MediaStream | undefined @@ -97,6 +102,8 @@ function disconnectCamera() { async function connectCamera() { try { + cameraSignalStatus.value = CameraSignalStatus.Waiting + stream = await navigator.mediaDevices.getUserMedia({ audio: false, video: {