veryfi-lens-wasm 1.2.1 → 1.2.3

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.1",
3
+ "version": "1.2.3",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",
package/veryfi-lens.js CHANGED
@@ -448,32 +448,6 @@ const VeryfiLens = (function () {
448
448
  }
449
449
  };
450
450
 
451
- // const testCCVideo = async () => {
452
- // const video = videoRef;
453
- // video.src = './cardTest.mp4';
454
- // wasmWrapper.setCardDetectorCallback(logCard);
455
- // };
456
-
457
- const testCCVideo = async () => {
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
- };
476
-
477
451
  const loadImage = (src) => {
478
452
  return new Promise((resolve, reject) => {
479
453
  const img = new Image();
@@ -723,7 +697,7 @@ const VeryfiLens = (function () {
723
697
  if (cardData.status == "AutoCaptureResultDone") {
724
698
  ShouldProcessCC = false;
725
699
  wasmWrapper.resetAutoCapture(true, true, true, true);
726
- wasmWrapper.releaseCallback();
700
+ // wasmWrapper.releaseCallback();
727
701
  }
728
702
  }
729
703
  }
@@ -1046,11 +1020,14 @@ const VeryfiLens = (function () {
1046
1020
  };
1047
1021
 
1048
1022
  const startUploadWasm = async (client_id) => {
1049
- await wasmWrapper.initialize(client_id);
1023
+ if (!wasmWrapper.loaded) {
1024
+ await wasmWrapper.initialize(client_id);
1025
+ }
1050
1026
  if (wasmWrapper) {
1051
- wasmWrapper.setDocumentCallback(logDocument);
1027
+ await wasmWrapper.setDocumentCallback(logDocument);
1052
1028
  }
1053
1029
  };
1030
+
1054
1031
  const startWasmCC = async (client_id) => {
1055
1032
  if (!wasmWrapper.loaded) {
1056
1033
  await wasmWrapper.initialize(client_id);
@@ -1070,24 +1047,6 @@ const VeryfiLens = (function () {
1070
1047
  }, INTERVAL);
1071
1048
  }
1072
1049
  };
1073
- const testWasmCC = async (client_id) => {
1074
- await wasmWrapper.initialize(client_id);
1075
- console.log("first");
1076
- if (wasmWrapper) {
1077
- testCCVideo();
1078
- requestAnimationFrame(displayVideo);
1079
- intervalRef = setInterval(() => {
1080
- if (
1081
- cardData.status === "AutoCaptureResultDone" &&
1082
- CCPhase === "ScanningBack"
1083
- ) {
1084
- clearInterval(intervalRef); // Stop sending frames once condition is met
1085
- } else {
1086
- sendCardWasm();
1087
- }
1088
- }, INTERVAL);
1089
- }
1090
- };
1091
1050
 
1092
1051
  const setBlurStatus = (variance) => {
1093
1052
  if (variance >= 9) {
@@ -1260,6 +1219,23 @@ const VeryfiLens = (function () {
1260
1219
  });
1261
1220
  };
1262
1221
 
1222
+ async function convertToRGBA(imageSrc) {
1223
+ const img = new Image();
1224
+ img.src = URL.createObjectURL(imageSrc);
1225
+ await new Promise((resolve) => {
1226
+ img.onload = resolve;
1227
+ });
1228
+
1229
+ const canvas = document.createElement("canvas");
1230
+ const ctx = canvas.getContext("2d");
1231
+ canvas.width = img.width;
1232
+ canvas.height = img.height;
1233
+ ctx.drawImage(img, 0, 0);
1234
+
1235
+ const rgbaImageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
1236
+ return rgbaImageData;
1237
+ }
1238
+
1263
1239
  return {
1264
1240
  init: async (session, client_id) => {
1265
1241
  userAgent = navigator.userAgent;
@@ -1400,16 +1376,6 @@ const VeryfiLens = (function () {
1400
1376
  return;
1401
1377
  }
1402
1378
  },
1403
- testCC: (client_id) => {
1404
- console.log("testing");
1405
- isDocumentProcess = true;
1406
- userAgent = navigator.userAgent;
1407
- device_uuid = new DeviceUUID(userAgent).get();
1408
- ShouldProcessCC = true;
1409
- CCPhase = "ScanningFront";
1410
- cardData = { status: "", number: "", name: "", date: "", cvv: "" };
1411
- testWasmCC(client_id);
1412
- },
1413
1379
 
1414
1380
  startCamera: () => {
1415
1381
  console.log("[EVENT] startCamera");
@@ -1455,7 +1421,7 @@ const VeryfiLens = (function () {
1455
1421
  finalImage = await cropWasm();
1456
1422
  setImage && setImage(finalImage);
1457
1423
  stopWasm();
1458
- wasmWrapper.releaseCallback();
1424
+ // wasmWrapper.releaseCallback();
1459
1425
  setIsEditing && setIsEditing(true);
1460
1426
  return finalImage;
1461
1427
  },
@@ -1466,48 +1432,51 @@ const VeryfiLens = (function () {
1466
1432
  setImage && setImage(finalImage);
1467
1433
  stopWasm();
1468
1434
  if (hasCoordinates) setIsDocument(true);
1469
- wasmWrapper.releaseCallback();
1435
+ // wasmWrapper.releaseCallback();
1470
1436
  setIsEditing && setIsEditing(true);
1471
1437
  return finalImage;
1472
1438
  },
1473
1439
 
1474
1440
  captureUploaded: async (imageData) => {
1475
- return await createImageBitmap(imageData).then((bitmap) => {
1476
- const wasmOutput = wasmWrapper.cropDocument(bitmap);
1477
- const { data, blurLevel, outputHeight, outputWidth } = wasmOutput;
1478
- // If a document is detected and cropped
1479
- if (outputWidth > 0 && outputHeight > 0) {
1480
- const width = outputWidth;
1481
- const height = outputHeight;
1482
- const cropImgCanvas = document.createElement("canvas");
1483
- cropImgCanvas.height = height;
1484
- cropImgCanvas.width = width;
1485
- const ctx = cropImgCanvas.getContext("2d");
1486
- const imageData = new ImageData(data, width, height);
1487
- ctx.putImageData(imageData, 0, 0);
1488
- setBlurStatus(blurLevel);
1489
- wasmWrapper.releaseCallback();
1490
- stopWasm();
1491
-
1492
- const imgString = cropImgCanvas.toDataURL("image/jpeg");
1493
- image = cropImgCanvas;
1494
- releaseCanvas(boxRef);
1495
- setIsDocument(true);
1496
- coordinates = [];
1497
- return imgString.split("data:image/jpeg;base64,")[1];
1441
+ const RGBAImage = await convertToRGBA(imageData);
1442
+ return await createImageBitmap(RGBAImage).then(async (bitmap) => {
1443
+ if (wasmWrapper.documentDetectorLoaded) {
1444
+ const wasmOutput = await wasmWrapper.cropDocument(bitmap);
1445
+ // console.log(wasmOutput, "output");
1446
+ const { data, blurLevel, outputHeight, outputWidth } = wasmOutput;
1447
+
1448
+ if (outputWidth > 0 && outputHeight > 0) {
1449
+ const width = outputWidth;
1450
+ const height = outputHeight;
1451
+ const cropImgCanvas = document.createElement("canvas");
1452
+ cropImgCanvas.height = height;
1453
+ cropImgCanvas.width = width;
1454
+ const ctx = cropImgCanvas.getContext("2d");
1455
+ const imageData = new ImageData(data, width, height);
1456
+ ctx.putImageData(imageData, 0, 0);
1457
+ setBlurStatus(blurLevel);
1458
+ const imgString = cropImgCanvas.toDataURL("image/jpeg");
1459
+ image = cropImgCanvas;
1460
+ setIsDocument(true);
1461
+ coordinates = [];
1462
+ return imgString.split("data:image/jpeg;base64,")[1];
1463
+ } else {
1464
+ // Return the original, uncropped image
1465
+ return new Promise((resolve, reject) => {
1466
+ setIsDocument(false);
1467
+ const reader = new FileReader();
1468
+ reader.readAsDataURL(imageData);
1469
+ reader.onload = function () {
1470
+ const base64Image = reader.result.split(",")[1];
1471
+ resolve(base64Image);
1472
+ };
1473
+ reader.onerror = function (error) {
1474
+ reject(error);
1475
+ };
1476
+ });
1477
+ }
1498
1478
  } else {
1499
- // Return the original, uncropped image
1500
- return new Promise((resolve, reject) => {
1501
- const reader = new FileReader();
1502
- reader.readAsDataURL(imageData);
1503
- reader.onload = function () {
1504
- const base64Image = reader.result.split(",")[1];
1505
- resolve(base64Image);
1506
- };
1507
- reader.onerror = function (error) {
1508
- reject(error);
1509
- };
1510
- });
1479
+ console.log("Wasm not loaded");
1511
1480
  }
1512
1481
  });
1513
1482
  },
@@ -1626,6 +1595,9 @@ const VeryfiLens = (function () {
1626
1595
  getCardPhase: () => {
1627
1596
  return CCPhase;
1628
1597
  },
1598
+ releaseWasm: () => {
1599
+ wasmWrapper.release();
1600
+ },
1629
1601
  };
1630
1602
  })();
1631
1603