veryfi-lens-wasm 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/veryfi-lens.js +41 -10
package/package.json
CHANGED
package/veryfi-lens.js
CHANGED
|
@@ -46,6 +46,7 @@ const VeryfiLens = (function () {
|
|
|
46
46
|
let userAgent = null;
|
|
47
47
|
let device_uuid = null;
|
|
48
48
|
let fullSizeImage;
|
|
49
|
+
let torchTrack = null
|
|
49
50
|
// let wasmWrapper = null;
|
|
50
51
|
let finalImage;
|
|
51
52
|
|
|
@@ -237,6 +238,7 @@ const VeryfiLens = (function () {
|
|
|
237
238
|
aspectRatio: isDesktop ? 9 / 16 : 16 / 9,
|
|
238
239
|
width: { ideal: 3840 },
|
|
239
240
|
height: { ideal: 2160 },
|
|
241
|
+
advanced: [{ torch: true }]
|
|
240
242
|
};
|
|
241
243
|
|
|
242
244
|
if (isAndroid) {
|
|
@@ -273,6 +275,7 @@ const VeryfiLens = (function () {
|
|
|
273
275
|
.catch((err) => {
|
|
274
276
|
console.log(`[Event] Error: ${err}`);
|
|
275
277
|
});
|
|
278
|
+
torchTrack = stream.getVideoTracks()[0];
|
|
276
279
|
} catch (error) {
|
|
277
280
|
console.error("Error accessing the camera", error);
|
|
278
281
|
}
|
|
@@ -296,6 +299,7 @@ const VeryfiLens = (function () {
|
|
|
296
299
|
aspectRatio: isDesktop ? 9 / 16 : 16 / 9,
|
|
297
300
|
width: { ideal: 2560 },
|
|
298
301
|
height: { ideal: 1440 },
|
|
302
|
+
advanced: [{ torch: true }]
|
|
299
303
|
};
|
|
300
304
|
|
|
301
305
|
if (isAndroid) {
|
|
@@ -329,10 +333,12 @@ const VeryfiLens = (function () {
|
|
|
329
333
|
const video = videoRef;
|
|
330
334
|
video.srcObject = stream;
|
|
331
335
|
wasmWrapper.setStitcherCallback(logLongDocument);
|
|
336
|
+
torchTrack = stream.getVideoTracks()[0];
|
|
332
337
|
})
|
|
333
338
|
.catch((err) => {
|
|
334
339
|
console.log(`[Event] Error: ${err}`);
|
|
335
340
|
});
|
|
341
|
+
|
|
336
342
|
} catch (error) {
|
|
337
343
|
console.error("Error accessing the camera", error);
|
|
338
344
|
}
|
|
@@ -369,6 +375,7 @@ const VeryfiLens = (function () {
|
|
|
369
375
|
aspectRatio: isDesktop ? 9 / 16 : 16 / 9,
|
|
370
376
|
width: { ideal: 3840 },
|
|
371
377
|
height: { ideal: 2160 },
|
|
378
|
+
advanced: [{ torch: true }]
|
|
372
379
|
};
|
|
373
380
|
|
|
374
381
|
if (useMainCamera) {
|
|
@@ -377,16 +384,13 @@ const VeryfiLens = (function () {
|
|
|
377
384
|
videoConfig.facingMode = "environment";
|
|
378
385
|
}
|
|
379
386
|
|
|
380
|
-
await navigator.mediaDevices
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
.catch((err) => {
|
|
388
|
-
console.log(`[Event] Error: ${err}`);
|
|
389
|
-
});
|
|
387
|
+
const stream = await navigator.mediaDevices.getUserMedia({ video: videoConfig });
|
|
388
|
+
const video = videoRef;
|
|
389
|
+
video.srcObject = stream;
|
|
390
|
+
wasmWrapper.setDocumentCallback(logDocument);
|
|
391
|
+
|
|
392
|
+
// Store the video track for torch control
|
|
393
|
+
torchTrack = stream.getVideoTracks()[0];
|
|
390
394
|
} catch (error) {
|
|
391
395
|
console.error("Error accessing the camera", error);
|
|
392
396
|
}
|
|
@@ -423,6 +427,7 @@ const VeryfiLens = (function () {
|
|
|
423
427
|
aspectRatio: isDesktop ? 9 / 16 : 16 / 9,
|
|
424
428
|
width: { ideal: 3840 },
|
|
425
429
|
height: { ideal: 2160 },
|
|
430
|
+
advanced: [{ torch: true }]
|
|
426
431
|
};
|
|
427
432
|
|
|
428
433
|
if (useMainCamera) {
|
|
@@ -436,6 +441,7 @@ const VeryfiLens = (function () {
|
|
|
436
441
|
const video = videoRef;
|
|
437
442
|
video.srcObject = stream;
|
|
438
443
|
wasmWrapper.setCardDetectorCallback(logCard);
|
|
444
|
+
torchTrack = stream.getVideoTracks()[0];
|
|
439
445
|
})
|
|
440
446
|
.catch((err) => {
|
|
441
447
|
console.log(`[Event] Error: ${err}`);
|
|
@@ -480,6 +486,7 @@ const VeryfiLens = (function () {
|
|
|
480
486
|
let videoConfig = {
|
|
481
487
|
width: { ideal: 3840 },
|
|
482
488
|
height: { ideal: 2160 },
|
|
489
|
+
advanced: [{ torch: true }]
|
|
483
490
|
};
|
|
484
491
|
|
|
485
492
|
if (isDesktop) {
|
|
@@ -514,6 +521,7 @@ const VeryfiLens = (function () {
|
|
|
514
521
|
video.srcObject = newStream;
|
|
515
522
|
});
|
|
516
523
|
}
|
|
524
|
+
torchTrack = stream.getVideoTracks()[0];
|
|
517
525
|
} catch (error) {
|
|
518
526
|
console.error("Error accessing the camera", error);
|
|
519
527
|
}
|
|
@@ -522,6 +530,25 @@ const VeryfiLens = (function () {
|
|
|
522
530
|
}
|
|
523
531
|
};
|
|
524
532
|
|
|
533
|
+
const toggleTorchLight = async () => {
|
|
534
|
+
if (torchTrack) {
|
|
535
|
+
const capabilities = torchTrack.getCapabilities();
|
|
536
|
+
if (capabilities.torch) {
|
|
537
|
+
try {
|
|
538
|
+
await torchTrack.applyConstraints({
|
|
539
|
+
advanced: [{ torch: !torchTrack.getConstraints().advanced?.[0]?.torch }]
|
|
540
|
+
});
|
|
541
|
+
} catch (err) {
|
|
542
|
+
console.error("Error toggling torch:", err);
|
|
543
|
+
}
|
|
544
|
+
} else {
|
|
545
|
+
console.log("Torch not supported on this device");
|
|
546
|
+
}
|
|
547
|
+
} else {
|
|
548
|
+
console.log("Camera not initialized");
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
|
|
525
552
|
const loadImage = (src) => {
|
|
526
553
|
return new Promise((resolve, reject) => {
|
|
527
554
|
const img = new Image();
|
|
@@ -1851,6 +1878,10 @@ const VeryfiLens = (function () {
|
|
|
1851
1878
|
releaseWasm: () => {
|
|
1852
1879
|
wasmWrapper.release();
|
|
1853
1880
|
},
|
|
1881
|
+
|
|
1882
|
+
toggleTorch: () => {
|
|
1883
|
+
toggleTorchLight()
|
|
1884
|
+
}
|
|
1854
1885
|
};
|
|
1855
1886
|
})();
|
|
1856
1887
|
|