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"]
}
],
"@typescript-eslint/ban-ts-comment": [
"off"
],
"sort-imports-es6-autofix/sort-imports-es6": [
2
],

View file

@ -2,30 +2,35 @@ import { Margin } from "./Margin";
import { makeElement } from "../htmlUtils";
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';
QrScanner.WORKER_PATH = URL.createObjectURL(new Blob([qrScannerWorkerSource]));
export async function QRScanner(onScan) {
let webcamVideo = makeElement({
tag: "video"
})
interface QRScannerType extends HTMLElement {
deinit(): void;
}
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",
children: [
Margin(webcamVideo),
]
});
}) as QRScannerType;
let stream = await navigator.mediaDevices.getUserMedia({
const stream = await navigator.mediaDevices.getUserMedia({
video: {
facingMode: 'environment',
},
audio: false,
});
webcamVideo.srcObject = stream;
let lastSeenValue = "";
const lastSeenValue = "";
const qrScanner = new QrScanner(webcamVideo, function (value) {
if (lastSeenValue == value) return;
onScan(value);

View file

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