diff --git a/app/components/Scan.vue b/app/components/Scan.vue index 2f3d919..2a6c5bd 100644 --- a/app/components/Scan.vue +++ b/app/components/Scan.vue @@ -3,8 +3,8 @@ import { toUint8Array } from 'js-base64' import { binaryToBlock, readFileHeaderMetaFromBuffer } from 'luby-transform' import QrScanner from 'qr-scanner' -import { createDecodeWorker } from '~/composables/decode-worker' import { useKiloBytesNumberFormat } from '~/composables/intlNumberFormat' +import { createDecodeWorker } from '~/composables/lt-decode' import { useBytesRate } from '~/composables/timeseries' import { CameraSignalStatus } from '~/types' @@ -59,15 +59,19 @@ watchEffect(() => { 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 qrScanner: QrScanner | undefined +watch(cameras, () => { + if (selectedCamera.value && cameras.value.find(i => i.deviceId === selectedCamera.value)) { + setTimeout(() => { + qrScanner?.setCamera(selectedCamera.value!) + qrScanner?.start() + }, 250) + } +}) + const error = ref() const video = shallowRef() const videoWidth = ref(0) diff --git a/app/composables/decode-worker.ts b/app/composables/lt-decode.ts similarity index 89% rename from app/composables/decode-worker.ts rename to app/composables/lt-decode.ts index 5382d1d..92e1557 100644 --- a/app/composables/decode-worker.ts +++ b/app/composables/lt-decode.ts @@ -1,7 +1,7 @@ import type { EncodedBlock } from 'luby-transform' -import type { DecoderWorkerFunctions } from './workers/decode' +import type { DecoderWorkerFunctions } from './workers/lt-decode.worker' import { createBirpc } from 'birpc' -import DecodeWorkerConstructor from './workers/decode?worker' +import DecodeWorkerConstructor from './workers/lt-decode.worker?worker' export function createDecodeWorker() { const worker = new DecodeWorker() diff --git a/app/composables/workers/decode.ts b/app/composables/workers/lt-decode.worker.ts similarity index 100% rename from app/composables/workers/decode.ts rename to app/composables/workers/lt-decode.worker.ts diff --git a/package.json b/package.json index 989bba3..1913572 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "dependencies": { "birpc": "^0.2.19", "js-base64": "^3.7.7", + "jsqr-es6": "1.4.0-1", "qr-scanner": "^1.4.2", "uqr": "^0.1.2" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e0f6e62..7f9c31d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: js-base64: specifier: ^3.7.7 version: 3.7.7 + jsqr-es6: + specifier: 1.4.0-1 + version: 1.4.0-1 qr-scanner: specifier: ^1.4.2 version: 1.4.2 @@ -4288,6 +4291,9 @@ packages: resolution: {integrity: sha512-p/nXbhSEcu3pZRdkW1OfJhpsVtW1gd4Wa1fnQc9YLiTfAjn0312eMKimbdIQzuZl9aa9xUGaRlP9T/CJE/ditQ==} engines: {node: '>=0.10.0'} + jsqr-es6@1.4.0-1: + resolution: {integrity: sha512-LPWZJLI+3LLOy9k3/s/MeXlkfNOs3bYBX5O+fp4N0XuxbgO8H7Uc/nYZeNwo13nSZXRW9xWFKmZdy9591+PyAg==} + keyv@4.5.4: resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==} @@ -11297,6 +11303,8 @@ snapshots: jsonpointer@5.0.1: {} + jsqr-es6@1.4.0-1: {} + keyv@4.5.4: dependencies: json-buffer: 3.0.1