-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathqrcode-scanner.js
45 lines (37 loc) · 1.09 KB
/
qrcode-scanner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { html, css, LitElement } from "https://unpkg.com/lit?module";
import { Html5QrcodeScanner } from "https://unpkg.com/html5-qrcode?module";
export class QRCodeScanner extends LitElement {
static styles = css`
:host {
display: block;
}
`;
render() {
return html`
<div id="reader"></div>
<div>${this.decodedText}</div>
<div>${this.errorMessage}</div>
`;
}
firstUpdated() {
const onScanSuccess = (decodedText, decodedResult) => {
// handle the scanned code as you like
this.decodedText = decodedText;
};
const onScanFailure = (errorMessage, error) => {
// handle scan failure, usually better to ignore and keep scanning
this.errorMessage = errorMessage;
};
const config = {
fps: 10,
qrbox: {
width: 350,
height: 250,
},
};
const reader = this.shadowRoot.querySelector("#reader");
const html5QrcodeScanner = new Html5QrcodeScanner(reader, config);
html5QrcodeScanner.render(onScanSuccess, onScanFailure);
}
}
customElements.define("qrcode-scanner", QRCodeScanner);