From c03e7551e88e6fd9f1ab24411ed4164a0d585027 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Wed, 25 Oct 2023 19:15:13 -0400 Subject: [PATCH] attempt to fix #466 (data missing in onProcessed, compared to earlier versions of library), submitted from comments by @ghevge --- src/quagga/quagga.ts | 3 ++- src/quagga/qworker.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/quagga/quagga.ts b/src/quagga/quagga.ts index bf6973e9..ad37d43a 100644 --- a/src/quagga/quagga.ts +++ b/src/quagga/quagga.ts @@ -190,7 +190,8 @@ export default class Quagga { if (result && this.context.onUIThread) { this.transformResult(result); this.addResult(result, imageData); - resultToPublish = result.barcodes || result; + // @ts-ignore + resultToPublish = result?.barcodes?.length > 0 ? result.barcodes : result; } Events.publish('processed', resultToPublish as never); diff --git a/src/quagga/qworker.ts b/src/quagga/qworker.ts index 45671775..3442b3b8 100644 --- a/src/quagga/qworker.ts +++ b/src/quagga/qworker.ts @@ -142,8 +142,12 @@ export function initWorker(config: QuaggaJSConfigObject, inputStream: any, cb: F } else if (e.data.event === 'processed') { workerThread.imageData = new Uint8Array(e.data.imageData); workerThread.busy = false; - // TODO: how to thread publishResult into here? - // publishResult(e.data.result, workerThread.imageData); + // TODO: how to thread publishResult into here? TypeScript says it's not here. https://github.com/ericblade/quagga2/issues/466#issuecomment-1724248080 says it's necessary? + // @ts-ignore + if (typeof publishResult !== 'undefined') { + // @ts-ignore + publishResult(e.data.result, workerThread.imageData); + } } else if (e.data.event === 'error') { if (ENV.development) { console.log('Worker error: ' + e.data.message);