astra-sdk-web 1.1.7 → 1.1.8

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.
@@ -954,6 +954,8 @@ var FaceMeshService = class {
954
954
  }
955
955
  this.processLiveness(faceOnCanvas, w, h);
956
956
  } else {
957
+ this.livenessStateRef.current.currentYaw = null;
958
+ this.livenessStateRef.current.currentAbsYaw = null;
957
959
  const vid = this.videoRef.current;
958
960
  if (vid) {
959
961
  const vidW = Math.max(1, vid?.videoWidth || displayW);
@@ -997,6 +999,8 @@ var FaceMeshService = class {
997
999
  const midX = (leftEyeOuter.x + rightEyeOuter.x) / 2;
998
1000
  const yaw = (nT.x - midX) / Math.max(1e-6, faceWidth);
999
1001
  const absYaw = Math.abs(yaw);
1002
+ this.livenessStateRef.current.currentYaw = yaw;
1003
+ this.livenessStateRef.current.currentAbsYaw = absYaw;
1000
1004
  const xs = faceOnCanvas.map((p) => p.x), ys = faceOnCanvas.map((p) => p.y);
1001
1005
  const minX = Math.min(...xs) * w, maxX = Math.max(...xs) * w;
1002
1006
  const minY = Math.min(...ys) * h, maxY = Math.max(...ys) * h;
@@ -1023,11 +1027,13 @@ var FaceMeshService = class {
1023
1027
  } else if (absYaw < centerThreshold) {
1024
1028
  state.centerHold += 1;
1025
1029
  if (state.centerHold >= holdFramesCenter) {
1026
- const newStage = "LEFT";
1027
- state.stage = newStage;
1028
- state.centerHold = 0;
1029
- if (this.callbacks.onLivenessUpdate) {
1030
- this.callbacks.onLivenessUpdate(newStage, "Turn your face LEFT");
1030
+ if (!state.livenessCompleted) {
1031
+ const newStage = "LEFT";
1032
+ state.stage = newStage;
1033
+ state.centerHold = 0;
1034
+ if (this.callbacks.onLivenessUpdate) {
1035
+ this.callbacks.onLivenessUpdate(newStage, "Turn your face LEFT");
1036
+ }
1031
1037
  }
1032
1038
  }
1033
1039
  } else {
@@ -1066,16 +1072,12 @@ var FaceMeshService = class {
1066
1072
  state.rightHold += 1;
1067
1073
  if (state.rightHold >= holdFramesTurn) {
1068
1074
  state.rightHold = 0;
1069
- if (!state.snapTriggered) {
1070
- state.snapTriggered = true;
1071
- const newStage = "DONE";
1072
- state.stage = newStage;
1073
- if (this.callbacks.onLivenessUpdate) {
1074
- this.callbacks.onLivenessUpdate(newStage, "Capturing...");
1075
- }
1076
- if (this.callbacks.onCaptureTrigger) {
1077
- this.callbacks.onCaptureTrigger();
1078
- }
1075
+ state.livenessCompleted = true;
1076
+ const newStage = "DONE";
1077
+ state.stage = newStage;
1078
+ state.centerHold = 0;
1079
+ if (this.callbacks.onLivenessUpdate) {
1080
+ this.callbacks.onLivenessUpdate(newStage, "Great! Now look straight at the camera");
1079
1081
  }
1080
1082
  }
1081
1083
  } else {
@@ -1084,6 +1086,28 @@ var FaceMeshService = class {
1084
1086
  this.callbacks.onLivenessUpdate(state.stage, yaw < -0.08 ? "You're facing left. Turn RIGHT" : "Turn a bit more RIGHT");
1085
1087
  }
1086
1088
  }
1089
+ } else if (state.stage === "DONE") {
1090
+ if (absYaw < centerThreshold && insideGuide) {
1091
+ state.centerHold += 1;
1092
+ if (state.centerHold >= holdFramesCenter && !state.snapTriggered) {
1093
+ state.snapTriggered = true;
1094
+ if (this.callbacks.onLivenessUpdate) {
1095
+ this.callbacks.onLivenessUpdate(state.stage, "Capturing...");
1096
+ }
1097
+ if (this.callbacks.onCaptureTrigger) {
1098
+ this.callbacks.onCaptureTrigger();
1099
+ }
1100
+ }
1101
+ } else {
1102
+ state.centerHold = 0;
1103
+ if (this.callbacks.onLivenessUpdate) {
1104
+ if (!insideGuide) {
1105
+ this.callbacks.onLivenessUpdate(state.stage, "Center your face inside the circle");
1106
+ } else {
1107
+ this.callbacks.onLivenessUpdate(state.stage, "Please look straight at the camera");
1108
+ }
1109
+ }
1110
+ }
1087
1111
  }
1088
1112
  }
1089
1113
  }
@@ -1219,7 +1243,10 @@ function useFaceScan(videoRef, canvasRef, callbacks) {
1219
1243
  snapTriggered: false,
1220
1244
  lastResultsAt: 0,
1221
1245
  stage: "CENTER",
1222
- livenessReady: false
1246
+ livenessReady: false,
1247
+ currentYaw: null,
1248
+ currentAbsYaw: null,
1249
+ livenessCompleted: false
1223
1250
  });
1224
1251
  React.useEffect(() => {
1225
1252
  livenessStateRef.current.centerHold = refs.centerHold.current;
@@ -1240,6 +1267,22 @@ function useFaceScan(videoRef, canvasRef, callbacks) {
1240
1267
  }, []);
1241
1268
  const handleFaceCapture = React.useCallback(async () => {
1242
1269
  if (!videoRef.current) return;
1270
+ const centerThreshold = 0.05;
1271
+ const currentAbsYaw = livenessStateRef.current.currentAbsYaw;
1272
+ if (currentAbsYaw === null || currentAbsYaw === void 0) {
1273
+ setState((prev) => ({
1274
+ ...prev,
1275
+ livenessInstruction: "Please position your face in front of the camera"
1276
+ }));
1277
+ return;
1278
+ }
1279
+ if (currentAbsYaw >= centerThreshold) {
1280
+ setState((prev) => ({
1281
+ ...prev,
1282
+ livenessInstruction: "Please look straight at the camera before capturing"
1283
+ }));
1284
+ return;
1285
+ }
1243
1286
  setState((prev) => ({ ...prev, loading: true }));
1244
1287
  try {
1245
1288
  const video = videoRef.current;
@@ -1462,7 +1505,7 @@ function FaceScanModal({ onComplete }) {
1462
1505
  const errorData = error?.errorData || {};
1463
1506
  if (errorMessage.includes("Face already registered") || errorMessage.includes("already registered") || errorData?.message?.includes("Face already registered") || error?.statusCode === 500 && errorMessage.includes("Face")) {
1464
1507
  setToast({
1465
- message: "Face has already been registered for this session. Proceeding to document upload.",
1508
+ message: "Face already registered",
1466
1509
  type: "warning"
1467
1510
  });
1468
1511
  return;