Skip to content

Commit

Permalink
Merge pull request #520 from ericblade:dev
Browse files Browse the repository at this point in the history
attempt to fix #466 (data missing in onProcessed, compared to earlier versions of library), submitted from comments by @ghevge
  • Loading branch information
ericblade authored Oct 25, 2023
2 parents a384d9e + 6d9c308 commit 673183f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
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 <khoobks@gmail.com>",
"Andy Edinborough <andy@edinborough.org>",
"Claudio Cocciarelli <claudiococciarelli@gmail.com>",
"Hadrien Foucault <hadrien.foucault@gmail.com>"
"Hadrien Foucault <hadrien.foucault@gmail.com>",
"ghevge <ghevge@github.com>"
],
"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

0 comments on commit 673183f

Please sign in to comment.