Skip to content

Commit

Permalink
optimize qr-scanner?
Browse files Browse the repository at this point in the history
  • Loading branch information
california authored and california committed Feb 13, 2025
1 parent 59b6cf4 commit 139fa73
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/pages/dashboard/activities/PairActivity.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { onCleanup, onMount, type JSX, type VoidComponent } from 'solid-js'
import { useLocation, useNavigate } from '@solidjs/router'
import { createMachine } from '@solid-primitives/state-machine'
import QrScanner from 'qr-scanner'
import type { default as QrScannerType } from 'qr-scanner'

import { pairDevice } from '~/api/devices'
import Button from '~/components/material/Button'
Expand Down Expand Up @@ -38,9 +38,12 @@ const PairActivity: VoidComponent = () => {
states: {
scanning(_input, to) {
let videoRef!: HTMLVideoElement
let qrScanner: QrScanner
let qrScanner: QrScannerType

onMount(async () => {
const { default: QrScanner } = await import('qr-scanner')
await import('qr-scanner/qr-scanner-worker.min.js')

onMount(() => {
qrScanner = new QrScanner(
videoRef,
(result) => {
Expand Down
17 changes: 17 additions & 0 deletions src/qr-scanner-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
declare module 'qr-scanner' {
export interface QrScannerResult {
data: string
}

export default class QrScanner {
constructor(
video: HTMLVideoElement,
onResult: (result: QrScannerResult) => void,
options?: { highlightScanRegion?: boolean }
)
start(): Promise<void>
destroy(): void
}
}

declare module 'qr-scanner/qr-scanner-worker.min.js'

0 comments on commit 139fa73

Please sign in to comment.