veryfi-lens-wasm 1.2.0-beta.2 → 1.2.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfi-lens-wasm",
3
- "version": "1.2.0-beta.2",
3
+ "version": "1.2.1",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",
package/veryfi-lens.js CHANGED
@@ -3,11 +3,6 @@ import { WasmWrapper } from "./wasm/wasm.js";
3
3
  import gatherBrowserData from "./wasm/device-data.js";
4
4
  import UAParser from "./wasm/ua-parser.cjs";
5
5
 
6
- if (typeof document !== 'undefined') {
7
- const script = document.createElement("script");
8
- script.src = "./wasm/opencv.cjs";
9
- }
10
-
11
6
  const VeryfiLens = (function () {
12
7
  const DEFAULT_BOX_COlOR = "rgba(84, 192, 139, 0.6)";
13
8
  const DEFAULT_SCALE = 1.0;
@@ -51,6 +46,7 @@ const VeryfiLens = (function () {
51
46
  let userAgent = null;
52
47
  let device_uuid = null;
53
48
  let fullSizeImage;
49
+ // let wasmWrapper = null;
54
50
  let finalImage;
55
51
 
56
52
  let previewData = null;
@@ -75,6 +71,8 @@ const VeryfiLens = (function () {
75
71
  let CCPhase = "ScanningFront";
76
72
  let timeStamp = 0;
77
73
  let ShouldProcessCC = true;
74
+ // let cv = null;
75
+ let cvReady = false;
78
76
 
79
77
  let cardData = {
80
78
  status: "",
@@ -83,7 +81,6 @@ const VeryfiLens = (function () {
83
81
  date: "",
84
82
  cvv: "",
85
83
  };
86
-
87
84
  const releaseCanvas = (canvas) => {
88
85
  if (canvas) {
89
86
  canvas.width = 1;
@@ -451,31 +448,31 @@ const VeryfiLens = (function () {
451
448
  }
452
449
  };
453
450
 
454
- // const testCCVideo = async () => {
455
- // const video = videoRef;
456
- // video.src = './cardTest.mp4';
457
- // wasmWrapper.setCardDetectorCallback(logCard);
458
- // };
451
+ // const testCCVideo = async () => {
452
+ // const video = videoRef;
453
+ // video.src = './cardTest.mp4';
454
+ // wasmWrapper.setCardDetectorCallback(logCard);
455
+ // };
459
456
 
460
457
  const testCCVideo = async () => {
461
- console.log('TEST VIDEO')
462
- // Create a video element
463
- const video = document.createElement('video');
464
- video.src = './cardTest.mp4';
465
- video.autoplay = true;
466
- video.muted = true; // Mute the video to avoid audio playback
467
- video.loop = true; // Loop the video
468
-
469
- // Attach the video element to the document body
470
- document.body.appendChild(video);
471
-
472
- // Set the video element as the source object of the videoRef
473
- const videoRef = document.getElementById('veryfi-video-ref'); // Assuming you have a video element with this ID
474
- videoRef.srcObject = video.captureStream();
475
-
476
- // Mock the behavior of wasmWrapper.setCardDetectorCallback
477
- wasmWrapper.setCardDetectorCallback(logCard);
478
- };
458
+ console.log("TEST VIDEO");
459
+ // Create a video element
460
+ const video = document.createElement("video");
461
+ video.src = "./cardTest.mp4";
462
+ video.autoplay = true;
463
+ video.muted = true; // Mute the video to avoid audio playback
464
+ video.loop = true; // Loop the video
465
+
466
+ // Attach the video element to the document body
467
+ document.body.appendChild(video);
468
+
469
+ // Set the video element as the source object of the videoRef
470
+ const videoRef = document.getElementById("veryfi-video-ref"); // Assuming you have a video element with this ID
471
+ videoRef.srcObject = video.captureStream();
472
+
473
+ // Mock the behavior of wasmWrapper.setCardDetectorCallback
474
+ wasmWrapper.setCardDetectorCallback(logCard);
475
+ };
479
476
 
480
477
  const loadImage = (src) => {
481
478
  return new Promise((resolve, reject) => {
@@ -713,13 +710,20 @@ const VeryfiLens = (function () {
713
710
  CCPhase = "FlipCard";
714
711
  case "ScanningBack":
715
712
  console.log("ITS CASE 2");
716
- wasmWrapper.resetAutoCapture(false, false, false, true);
713
+ const scanForNumber = !cardData.number;
714
+ const scanForName = !cardData.name;
715
+ const scanForDate = !cardData.date;
716
+ const scanForCvv = !cardData.cvv;
717
+ wasmWrapper.resetAutoCapture(
718
+ scanForNumber,
719
+ scanForName,
720
+ scanForDate,
721
+ scanForCvv
722
+ );
717
723
  if (cardData.status == "AutoCaptureResultDone") {
718
724
  ShouldProcessCC = false;
719
725
  wasmWrapper.resetAutoCapture(true, true, true, true);
720
726
  wasmWrapper.releaseCallback();
721
- // wasmWrapper.release();
722
- // CCPhase = "ScanningFront";
723
727
  }
724
728
  }
725
729
  }
@@ -996,7 +1000,7 @@ const VeryfiLens = (function () {
996
1000
  };
997
1001
 
998
1002
  const startWasm = async (client_id) => {
999
- if(!wasmWrapper.loaded){
1003
+ if (!wasmWrapper.loaded) {
1000
1004
  await wasmWrapper.initialize(client_id);
1001
1005
  }
1002
1006
  if (wasmWrapper) {
@@ -1012,8 +1016,8 @@ const VeryfiLens = (function () {
1012
1016
  };
1013
1017
 
1014
1018
  const startWasmLong = async (client_id) => {
1015
- if(!wasmWrapper.loaded){
1016
- await wasmWrapper.initialize(client_id);
1019
+ if (!wasmWrapper.loaded) {
1020
+ await wasmWrapper.initialize(client_id);
1017
1021
  }
1018
1022
  if (wasmWrapper) {
1019
1023
  getVideoWasmLong();
@@ -1048,7 +1052,7 @@ const VeryfiLens = (function () {
1048
1052
  }
1049
1053
  };
1050
1054
  const startWasmCC = async (client_id) => {
1051
- if (!wasmWrapper.loaded){
1055
+ if (!wasmWrapper.loaded) {
1052
1056
  await wasmWrapper.initialize(client_id);
1053
1057
  }
1054
1058
  if (wasmWrapper.loaded) {
@@ -1068,7 +1072,7 @@ const VeryfiLens = (function () {
1068
1072
  };
1069
1073
  const testWasmCC = async (client_id) => {
1070
1074
  await wasmWrapper.initialize(client_id);
1071
- console.log('first')
1075
+ console.log("first");
1072
1076
  if (wasmWrapper) {
1073
1077
  testCCVideo();
1074
1078
  requestAnimationFrame(displayVideo);
@@ -1079,7 +1083,7 @@ const VeryfiLens = (function () {
1079
1083
  ) {
1080
1084
  clearInterval(intervalRef); // Stop sending frames once condition is met
1081
1085
  } else {
1082
- sendCardWasm();
1086
+ sendCardWasm();
1083
1087
  }
1084
1088
  }, INTERVAL);
1085
1089
  }
@@ -1101,8 +1105,20 @@ const VeryfiLens = (function () {
1101
1105
  }
1102
1106
  };
1103
1107
 
1108
+ function loadOpenCv(url) {
1109
+ return new Promise((resolve, reject) => {
1110
+ const script = document.createElement("script");
1111
+ script.src = url;
1112
+ script.onload = () => resolve(); // Correctly scoped resolve
1113
+ script.onerror = () => reject(new Error(`Script load error for ${url}`));
1114
+ document.body.appendChild(script);
1115
+ cvReady = true;
1116
+ });
1117
+ }
1118
+
1104
1119
  const isBlurry = async (image) => {
1105
1120
  console.log("[EVENT] Checking for blur");
1121
+
1106
1122
  const src = cv.imread(image);
1107
1123
  let refVariance;
1108
1124
  let whiteCanvas = new cv.Mat(490, 866, cv.CV_8UC3, [255, 255, 255, 0]);
@@ -1250,6 +1266,9 @@ const VeryfiLens = (function () {
1250
1266
  device_uuid = new DeviceUUID(userAgent).get();
1251
1267
  console.log("[EVENT] Device ID", getDeviceID(device_uuid));
1252
1268
  if (session) {
1269
+ if (!cvReady) {
1270
+ loadOpenCv("./wasm/opencv.js");
1271
+ }
1253
1272
  lensSessionKey = session;
1254
1273
  createCanvases();
1255
1274
  videoRef = document.getElementById("veryfi-video-ref");
@@ -1382,7 +1401,7 @@ const VeryfiLens = (function () {
1382
1401
  }
1383
1402
  },
1384
1403
  testCC: (client_id) => {
1385
- console.log('testing')
1404
+ console.log("testing");
1386
1405
  isDocumentProcess = true;
1387
1406
  userAgent = navigator.userAgent;
1388
1407
  device_uuid = new DeviceUUID(userAgent).get();
@@ -1391,7 +1410,6 @@ const VeryfiLens = (function () {
1391
1410
  cardData = { status: "", number: "", name: "", date: "", cvv: "" };
1392
1411
  testWasmCC(client_id);
1393
1412
  },
1394
-
1395
1413
 
1396
1414
  startCamera: () => {
1397
1415
  console.log("[EVENT] startCamera");
@@ -1437,7 +1455,7 @@ const VeryfiLens = (function () {
1437
1455
  finalImage = await cropWasm();
1438
1456
  setImage && setImage(finalImage);
1439
1457
  stopWasm();
1440
- wasmWrapper.releaseCallback()
1458
+ wasmWrapper.releaseCallback();
1441
1459
  setIsEditing && setIsEditing(true);
1442
1460
  return finalImage;
1443
1461
  },
@@ -1448,7 +1466,7 @@ const VeryfiLens = (function () {
1448
1466
  setImage && setImage(finalImage);
1449
1467
  stopWasm();
1450
1468
  if (hasCoordinates) setIsDocument(true);
1451
- wasmWrapper.releaseCallback()
1469
+ wasmWrapper.releaseCallback();
1452
1470
  setIsEditing && setIsEditing(true);
1453
1471
  return finalImage;
1454
1472
  },
@@ -1468,7 +1486,7 @@ const VeryfiLens = (function () {
1468
1486
  const imageData = new ImageData(data, width, height);
1469
1487
  ctx.putImageData(imageData, 0, 0);
1470
1488
  setBlurStatus(blurLevel);
1471
- wasmWrapper.releaseCallback()
1489
+ wasmWrapper.releaseCallback();
1472
1490
  stopWasm();
1473
1491
 
1474
1492
  const imgString = cropImgCanvas.toDataURL("image/jpeg");
@@ -1607,9 +1625,7 @@ const VeryfiLens = (function () {
1607
1625
 
1608
1626
  getCardPhase: () => {
1609
1627
  return CCPhase;
1610
- }
1611
-
1612
-
1628
+ },
1613
1629
  };
1614
1630
  })();
1615
1631