@@ -164,28 +164,9 @@ export default {
164
164
return ;
165
165
} else {
166
166
const barcodeDetector = new BarcodeDetector ({formats: [' pdf417' ]});
167
- const detectBarcode = async video => {
168
- try {
169
- // Detect barcodes in the current video frame
170
- const barcodes = await barcodeDetector .detect (video);
171
- if (barcodes .length > 0 ) {
172
- barcodes .forEach (barcode => {
173
- const {format , rawValue } = barcode;
174
- if (format && rawValue) {
175
- console .log (' Barcode Detection API:' , barcode);
176
- emit (' result' , {type: format, text: rawValue});
177
- }
178
- });
179
- }
180
- } catch (error) {
181
- console .error (' Barcode detection failed:' , error);
182
- }
183
- // Schedule the next frame check
184
- video .requestVideoFrameCallback (() => detectBarcode (video));
185
- };
186
167
// Start the detection loop
187
168
videoElement .requestVideoFrameCallback (() =>
188
- detectBarcode (videoElement)
169
+ detectBarcode (barcodeDetector, videoElement, emit )
189
170
);
190
171
}
191
172
}
@@ -271,6 +252,28 @@ export default {
271
252
}
272
253
};
273
254
255
+ async function detectBarcode (barcodeDetector , video , emit ) {
256
+ try {
257
+ // Detect barcodes in the current video frame
258
+ const barcodes = await barcodeDetector .detect (video);
259
+ if (barcodes .length > 0 ) {
260
+ barcodes .forEach (barcode => {
261
+ const {format , rawValue } = barcode;
262
+ if (format && rawValue) {
263
+ console .log (' Barcode Detection API:' , barcode);
264
+ emit (' result' , {type: format, text: rawValue});
265
+ }
266
+ });
267
+ }
268
+ } catch (error) {
269
+ console .error (' Barcode detection failed:' , error);
270
+ }
271
+ // Schedule the next frame check
272
+ video .requestVideoFrameCallback (() =>
273
+ detectBarcode (barcodeDetector, video, emit)
274
+ );
275
+ }
276
+
274
277
// see: `BarcodeFormat`
275
278
// https://wicg.github.io/shape-detection-api/#enumdef-barcodeformat
276
279
const FORMAT_MAP = new Map ([
0 commit comments