From c03e7551e88e6fd9f1ab24411ed4164a0d585027 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Wed, 25 Oct 2023 19:15:13 -0400 Subject: [PATCH 1/2] 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); From 6d9c30856b1cb39290d97e76d0cb20ee4f734c96 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Wed, 25 Oct 2023 19:29:39 -0400 Subject: [PATCH 2/2] update tests slightly to match what is supposed to be happening now that #466 appears fixed --- package.json | 5 +++-- test/integration/integration.spec.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ebf88615..f3a9e828 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ericblade/quagga2", - "version": "1.8.3", + "version": "1.8.4", "description": "An advanced barcode-scanner written in JavaScript", "main": "lib/quagga.js", "types": "type-definitions/quagga.d.ts", @@ -137,7 +137,8 @@ "Ben Khoo ", "Andy Edinborough ", "Claudio Cocciarelli ", - "Hadrien Foucault " + "Hadrien Foucault ", + "ghevge " ], "license": "MIT", "engines": { diff --git a/test/integration/integration.spec.ts b/test/integration/integration.spec.ts index c8e9c0f3..a44a6349 100644 --- a/test/integration/integration.spec.ts +++ b/test/integration/integration.spec.ts @@ -58,8 +58,9 @@ function runNoCodeTest(name: string, config: QuaggaJSConfigObject, testSet: Arra src: `${typeof window !== 'undefined' ? '/' : ''}test/fixtures/${name}/${sample.name}`, }; const result = await Quagga.decodeSingle(thisConfig); - expect(result).to.be.an('Array'); - expect(result).to.be.empty; + expect(result).to.be.an('Object'); + expect(result.barcodes).to.be.an('array'); + expect(result.barcodes).to.be.empty; // // console.warn(`* Expect result ${JSON.stringify(result)} to be an object`); expect(Quagga.canvas).to.be.an('Object'); expect(Quagga.canvas.dom).to.be.an('Object');