Skip to content

Commit 9497a7d

Browse files
committed
Apply suggestions from code review.
1 parent 6b621b2 commit 9497a7d

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

components/BarcodeScanner.vue

+4-9
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,13 @@ export default {
159159
const {signal} = abortController;
160160
const barcodes = await detectBarcodes({barcodeDetector, video, signal});
161161
const [result] = barcodes;
162-
if(result?.format && result?.rawValue) {
163-
emit('result', {type: result.format, text: result.rawValue});
164-
}
162+
emit('result', {type: result.format, text: result.rawValue});
165163
}
166164
167165
function startBarcodeDetection() {
168166
// Get video element
169167
const video = document.querySelector(
170-
'#dce-video-container > video'
171-
);
168+
'#dce-video-container > video');
172169
const {BarcodeDetector} = globalThis;
173170
// Check if BarcodeDetector is supported
174171
if(!BarcodeDetector) {
@@ -178,10 +175,8 @@ export default {
178175
const barcodeDetector = new BarcodeDetector({
179176
formats: formatsToSupport
180177
});
181-
// Start the detection loop
182-
video.requestVideoFrameCallback(
183-
() => emitScanResult({barcodeDetector, video})
184-
);
178+
// emit the first scanned result
179+
emitScanResult({barcodeDetector, video});
185180
}
186181
187182
// Update camera zoom

lib/barcodes.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/*!
2+
* Copyright (c) 2025 Digital Bazaar, Inc. All rights reserved.
3+
*/
14
export function detectBarcodes({barcodeDetector, video, signal} = {}) {
25
return new Promise((resolve, reject) => {
36
// schedule barcode detection

0 commit comments

Comments
 (0)