-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwasmWorker.js
30 lines (25 loc) · 869 Bytes
/
wasmWorker.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
importScripts("./node_modules/@maslick/koder/zbar.js");
importScripts("./node_modules/@maslick/koder/browser.js");
(async () => {
// Initialize Koder
const koder = await new Koder().initialize({wasmDirectory: "./node_modules/@maslick/koder"});
// Listen for messages from JS main thread containing raw image data
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 scanResult = koder.decode(data, this.width, this.height);
const t1 = new Date().getTime();
if (scanResult) {
console.log(`Scanned in ${t1 - t0} ms`);
postMessage({
data: scanResult,
ms: t1 - t0
});
}
});
})();