diff --git a/src/components/QrcodeStream.vue b/src/components/QrcodeStream.vue index c8138354..7fbfb4a0 100644 --- a/src/components/QrcodeStream.vue +++ b/src/components/QrcodeStream.vue @@ -29,7 +29,7 @@ import { keepScanning } from "../misc/scanner.js"; import { thinSquare } from "../misc/track-func.js"; import Camera from "../misc/camera.js"; import CommonAPI from "../mixins/CommonAPI.vue"; -import Worker from "../worker/jsqr.js"; +import spawnWorker from "../worker/jsqr.js"; export default { name: "qrcode-stream", @@ -58,7 +58,7 @@ export default { worker: { type: Function, - default: Worker + default: spawnWorker } }, diff --git a/src/misc/scanner.js b/src/misc/scanner.js index d613c29e..c1716598 100644 --- a/src/misc/scanner.js +++ b/src/misc/scanner.js @@ -1,7 +1,7 @@ import { eventOn } from "callforth"; -export async function scan(Worker, imageData) { - const worker = new Worker(); +export const scan = async (spawnWorker, imageData) => { + const worker = spawnWorker(); worker.postMessage(imageData, [imageData.data.buffer]); @@ -16,14 +16,14 @@ export async function scan(Worker, imageData) { * Continuously extracts frames from camera stream and tries to read * potentially pictured QR codes. */ -export function keepScanning(Worker, camera, options) { +export const keepScanning = (spawnWorker, camera, options) => { const { detectHandler, locateHandler, minDelay } = options; let contentBefore = null; let locationBefore = null; let lastScanned = performance.now(); - const worker = new Worker(); + const worker = spawnWorker(); // If worker can't process frames fast enough, memory will quickly full up. // Make sure to process only one frame at a time.