-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathjsQrWorker.js
More file actions
24 lines (20 loc) · 629 Bytes
/
jsQrWorker.js
File metadata and controls
24 lines (20 loc) · 629 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
importScripts("https://cdn.jsdelivr.net/npm/[email protected]/dist/jsQR.min.js");
let width = 0, height = 0;
self.addEventListener('message', event => {
if ('width' in event.data && 'height' in event.data) {
this.width = event.data.width;
this.height = event.data.height;
}
const {data} = event.data;
if (!data) return;
const t0 = new Date().getTime();
const code = jsQR(data, this.width, this.height, { inversionAttempts: "dontInvert" });
const t1 = new Date().getTime();
if (code != null) {
console.log(`Scanned in ${t1-t0} ms`);
postMessage({
data: code.data,
ms: t1-t0
});
}
});