1
0
Fork 0

Add typing to QRScanner.ts.

This commit is contained in:
Kitteh 2021-05-08 00:54:50 +01:00
parent e712af95de
commit 5a4df25547
3 changed files with 18 additions and 10 deletions

View file

@ -35,6 +35,9 @@
"allow": ["arrowFunctions"] "allow": ["arrowFunctions"]
} }
], ],
"@typescript-eslint/ban-ts-comment": [
"off"
],
"sort-imports-es6-autofix/sort-imports-es6": [ "sort-imports-es6-autofix/sort-imports-es6": [
2 2
], ],

View file

@ -3,29 +3,34 @@ import { makeElement } from "../htmlUtils";
import QrScanner from 'qr-scanner'; import QrScanner from 'qr-scanner';
/* eslint-disable import/no-unresolved */ /* eslint-disable import/no-unresolved */
// @ts-ignore
import qrScannerWorkerSource from '!!raw-loader!qr-scanner/qr-scanner-worker.min.js'; import qrScannerWorkerSource from '!!raw-loader!qr-scanner/qr-scanner-worker.min.js';
QrScanner.WORKER_PATH = URL.createObjectURL(new Blob([qrScannerWorkerSource])); QrScanner.WORKER_PATH = URL.createObjectURL(new Blob([qrScannerWorkerSource]));
export async function QRScanner(onScan) { interface QRScannerType extends HTMLElement {
let webcamVideo = makeElement({ deinit(): void;
tag: "video" }
})
let QRInput = makeElement({ export async function QRScanner(onScan: (code: string) => void): Promise<QRScannerType> {
const webcamVideo = makeElement({
tag: "video"
}) as HTMLVideoElement;
const QRInput = makeElement({
tag: "div", tag: "div",
children: [ children: [
Margin(webcamVideo), Margin(webcamVideo),
] ]
}); }) as QRScannerType;
let stream = await navigator.mediaDevices.getUserMedia({ const stream = await navigator.mediaDevices.getUserMedia({
video: { video: {
facingMode: 'environment', facingMode: 'environment',
}, },
audio: false, audio: false,
}); });
webcamVideo.srcObject = stream; webcamVideo.srcObject = stream;
let lastSeenValue = ""; const lastSeenValue = "";
const qrScanner = new QrScanner(webcamVideo, function (value) { const qrScanner = new QrScanner(webcamVideo, function (value) {
if (lastSeenValue == value) return; if (lastSeenValue == value) return;
onScan(value); onScan(value);

View file

@ -1,6 +1,6 @@
import { MarginInline } from "../elements/MarginInline"; import { MarginInline } from "../elements/MarginInline";
import { Page } from "../types/Page"; import { Page } from "../types/Page";
import { QRScanner } from "../elements/QRScanner.js"; import { QRScanner } from "../elements/QRScanner";
import { changePage, setErrorText, setPageContent } from "../pageUtils"; import { changePage, setErrorText, setPageContent } from "../pageUtils";
import { getSealStatus } from "../api/getSealStatus"; import { getSealStatus } from "../api/getSealStatus";
import { makeElement } from "../htmlUtils"; import { makeElement } from "../htmlUtils";