Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt to fix #466 (data missing in onProcessed, compared to earlier versions of library), submitted from comments by @ghevge #520

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -137,7 +137,8 @@
"Ben Khoo <[email protected]>",
"Andy Edinborough <[email protected]>",
"Claudio Cocciarelli <[email protected]>",
"Hadrien Foucault <[email protected]>"
"Hadrien Foucault <[email protected]>",
"ghevge <[email protected]>"
],
"license": "MIT",
"engines": {
Expand Down
3 changes: 2 additions & 1 deletion src/quagga/quagga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/quagga/qworker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions test/integration/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down