Lint code.
This commit is contained in:
parent
ce8e3fe121
commit
decc37e073
46
src/elements/QRScanner.js
Normal file
46
src/elements/QRScanner.js
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
import { makeElement } from "../htmlUtils.js";
|
||||||
|
import { Margin } from "./Margin.js";
|
||||||
|
import QrScanner from 'qr-scanner';
|
||||||
|
|
||||||
|
/* eslint-disable import/no-unresolved */
|
||||||
|
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"
|
||||||
|
})
|
||||||
|
|
||||||
|
let QRInput = makeElement({
|
||||||
|
tag: "div",
|
||||||
|
children: [
|
||||||
|
Margin(webcamVideo),
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
let stream = await navigator.mediaDevices.getUserMedia({
|
||||||
|
video: {
|
||||||
|
facingMode: 'environment',
|
||||||
|
},
|
||||||
|
audio: false,
|
||||||
|
});
|
||||||
|
webcamVideo.srcObject = stream;
|
||||||
|
let lastSeenValue = "";
|
||||||
|
const qrScanner = new QrScanner(webcamVideo, function (value) {
|
||||||
|
if (lastSeenValue == value) return;
|
||||||
|
onScan(value);
|
||||||
|
});
|
||||||
|
qrScanner.start();
|
||||||
|
|
||||||
|
QRInput.deinit = () => {
|
||||||
|
try {
|
||||||
|
stream.getTracks().forEach(function (track) {
|
||||||
|
track.stop();
|
||||||
|
});
|
||||||
|
} catch (_) {
|
||||||
|
()=>{};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
|
@ -2,14 +2,9 @@ import { Page } from "../types/Page.js";
|
||||||
import { submitUnsealKey, getSealStatus } from "../api.js";
|
import { submitUnsealKey, getSealStatus } from "../api.js";
|
||||||
import { setPageContent, setErrorText, changePage } from "../pageUtils.js";
|
import { setPageContent, setErrorText, changePage } from "../pageUtils.js";
|
||||||
import { makeElement } from "../htmlUtils.js";
|
import { makeElement } from "../htmlUtils.js";
|
||||||
import { Margin } from "../elements/Margin.js";
|
|
||||||
import { MarginInline } from "../elements/MarginInline.js";
|
import { MarginInline } from "../elements/MarginInline.js";
|
||||||
|
import { QRScanner } from "../elements/QRScanner.js";
|
||||||
import i18next from 'i18next';
|
import i18next from 'i18next';
|
||||||
import QrScanner from 'qr-scanner';
|
|
||||||
|
|
||||||
/* eslint-disable import/no-unresolved */
|
|
||||||
import qrScannerWorkerSource from '!!raw-loader!qr-scanner/qr-scanner-worker.min.js';
|
|
||||||
QrScanner.WORKER_PATH = URL.createObjectURL(new Blob([qrScannerWorkerSource]));
|
|
||||||
|
|
||||||
const UnsealInputModes = {
|
const UnsealInputModes = {
|
||||||
FORM_INPUT: "FORM_INPUT",
|
FORM_INPUT: "FORM_INPUT",
|
||||||
|
@ -19,7 +14,6 @@ const UnsealInputModes = {
|
||||||
export class UnsealPage extends Page {
|
export class UnsealPage extends Page {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
//this.mode = UnsealInputModes.QR_INPUT;
|
|
||||||
this.mode = UnsealInputModes.FORM_INPUT;
|
this.mode = UnsealInputModes.FORM_INPUT;
|
||||||
}
|
}
|
||||||
cleanup() {
|
cleanup() {
|
||||||
|
@ -29,13 +23,10 @@ export class UnsealPage extends Page {
|
||||||
|
|
||||||
deinitWebcam() {
|
deinitWebcam() {
|
||||||
try {
|
try {
|
||||||
this.stream.getTracks().forEach(function (track) {
|
this.qrScanner.deinit();
|
||||||
track.stop();
|
|
||||||
});
|
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
console.log("");
|
()=>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
makeRefresher() {
|
makeRefresher() {
|
||||||
|
@ -128,34 +119,11 @@ export class UnsealPage extends Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
async makeQRInput() {
|
async makeQRInput() {
|
||||||
let webcamVideo = makeElement({
|
this.qrScanner = await QRScanner(function (code) {
|
||||||
tag: "video"
|
|
||||||
})
|
|
||||||
|
|
||||||
let QRInput = makeElement({
|
|
||||||
tag: "div",
|
|
||||||
children: [
|
|
||||||
Margin(webcamVideo),
|
|
||||||
]
|
|
||||||
})
|
|
||||||
this.unsealInputContent.appendChild(QRInput);
|
|
||||||
|
|
||||||
|
|
||||||
this.stream = await navigator.mediaDevices.getUserMedia({
|
|
||||||
video: {
|
|
||||||
facingMode: 'environment',
|
|
||||||
},
|
|
||||||
audio: false,
|
|
||||||
});
|
|
||||||
webcamVideo.srcObject = this.stream;
|
|
||||||
let lastSeenCode = "";
|
|
||||||
const qrScanner = new QrScanner(webcamVideo, function (code) {
|
|
||||||
if (lastSeenCode == code) return;
|
|
||||||
lastSeenCode = code;
|
|
||||||
this.submitKey(code);
|
this.submitKey(code);
|
||||||
console.log('decoded qr code:', code)
|
console.log('decoded qr code:', code)
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
qrScanner.start();
|
this.unsealInputContent.appendChild(this.qrScanner);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSealProgress(data) {
|
updateSealProgress(data) {
|
||||||
|
|
Loading…
Reference in a new issue