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.
@@ -749,6 +749,8 @@ var FaceMeshService = class {
749
749
  }
750
750
  this.processLiveness(faceOnCanvas, w, h);
751
751
  } else {
752
+ this.livenessStateRef.current.currentYaw = null;
753
+ this.livenessStateRef.current.currentAbsYaw = null;
752
754
  const vid = this.videoRef.current;
753
755
  if (vid) {
754
756
  const vidW = Math.max(1, vid?.videoWidth || displayW);
@@ -792,6 +794,8 @@ var FaceMeshService = class {
792
794
  const midX = (leftEyeOuter.x + rightEyeOuter.x) / 2;
793
795
  const yaw = (nT.x - midX) / Math.max(1e-6, faceWidth);
794
796
  const absYaw = Math.abs(yaw);
797
+ this.livenessStateRef.current.currentYaw = yaw;
798
+ this.livenessStateRef.current.currentAbsYaw = absYaw;
795
799
  const xs = faceOnCanvas.map((p) => p.x), ys = faceOnCanvas.map((p) => p.y);
796
800
  const minX = Math.min(...xs) * w, maxX = Math.max(...xs) * w;
797
801
  const minY = Math.min(...ys) * h, maxY = Math.max(...ys) * h;
@@ -818,11 +822,13 @@ var FaceMeshService = class {
818
822
  } else if (absYaw < centerThreshold) {
819
823
  state.centerHold += 1;
820
824
  if (state.centerHold >= holdFramesCenter) {
821
- const newStage = "LEFT";
822
- state.stage = newStage;
823
- state.centerHold = 0;
824
- if (this.callbacks.onLivenessUpdate) {
825
- this.callbacks.onLivenessUpdate(newStage, "Turn your face LEFT");
825
+ if (!state.livenessCompleted) {
826
+ const newStage = "LEFT";
827
+ state.stage = newStage;
828
+ state.centerHold = 0;
829
+ if (this.callbacks.onLivenessUpdate) {
830
+ this.callbacks.onLivenessUpdate(newStage, "Turn your face LEFT");
831
+ }
826
832
  }
827
833
  }
828
834
  } else {
@@ -861,16 +867,12 @@ var FaceMeshService = class {
861
867
  state.rightHold += 1;
862
868
  if (state.rightHold >= holdFramesTurn) {
863
869
  state.rightHold = 0;
864
- if (!state.snapTriggered) {
865
- state.snapTriggered = true;
866
- const newStage = "DONE";
867
- state.stage = newStage;
868
- if (this.callbacks.onLivenessUpdate) {
869
- this.callbacks.onLivenessUpdate(newStage, "Capturing...");
870
- }
871
- if (this.callbacks.onCaptureTrigger) {
872
- this.callbacks.onCaptureTrigger();
873
- }
870
+ state.livenessCompleted = true;
871
+ const newStage = "DONE";
872
+ state.stage = newStage;
873
+ state.centerHold = 0;
874
+ if (this.callbacks.onLivenessUpdate) {
875
+ this.callbacks.onLivenessUpdate(newStage, "Great! Now look straight at the camera");
874
876
  }
875
877
  }
876
878
  } else {
@@ -879,6 +881,28 @@ var FaceMeshService = class {
879
881
  this.callbacks.onLivenessUpdate(state.stage, yaw < -0.08 ? "You're facing left. Turn RIGHT" : "Turn a bit more RIGHT");
880
882
  }
881
883
  }
884
+ } else if (state.stage === "DONE") {
885
+ if (absYaw < centerThreshold && insideGuide) {
886
+ state.centerHold += 1;
887
+ if (state.centerHold >= holdFramesCenter && !state.snapTriggered) {
888
+ state.snapTriggered = true;
889
+ if (this.callbacks.onLivenessUpdate) {
890
+ this.callbacks.onLivenessUpdate(state.stage, "Capturing...");
891
+ }
892
+ if (this.callbacks.onCaptureTrigger) {
893
+ this.callbacks.onCaptureTrigger();
894
+ }
895
+ }
896
+ } else {
897
+ state.centerHold = 0;
898
+ if (this.callbacks.onLivenessUpdate) {
899
+ if (!insideGuide) {
900
+ this.callbacks.onLivenessUpdate(state.stage, "Center your face inside the circle");
901
+ } else {
902
+ this.callbacks.onLivenessUpdate(state.stage, "Please look straight at the camera");
903
+ }
904
+ }
905
+ }
882
906
  }
883
907
  }
884
908
  }
@@ -1014,7 +1038,10 @@ function useFaceScan(videoRef, canvasRef, callbacks) {
1014
1038
  snapTriggered: false,
1015
1039
  lastResultsAt: 0,
1016
1040
  stage: "CENTER",
1017
- livenessReady: false
1041
+ livenessReady: false,
1042
+ currentYaw: null,
1043
+ currentAbsYaw: null,
1044
+ livenessCompleted: false
1018
1045
  });
1019
1046
  React.useEffect(() => {
1020
1047
  livenessStateRef.current.centerHold = refs.centerHold.current;
@@ -1035,6 +1062,22 @@ function useFaceScan(videoRef, canvasRef, callbacks) {
1035
1062
  }, []);
1036
1063
  const handleFaceCapture = React.useCallback(async () => {
1037
1064
  if (!videoRef.current) return;
1065
+ const centerThreshold = 0.05;
1066
+ const currentAbsYaw = livenessStateRef.current.currentAbsYaw;
1067
+ if (currentAbsYaw === null || currentAbsYaw === void 0) {
1068
+ setState((prev) => ({
1069
+ ...prev,
1070
+ livenessInstruction: "Please position your face in front of the camera"
1071
+ }));
1072
+ return;
1073
+ }
1074
+ if (currentAbsYaw >= centerThreshold) {
1075
+ setState((prev) => ({
1076
+ ...prev,
1077
+ livenessInstruction: "Please look straight at the camera before capturing"
1078
+ }));
1079
+ return;
1080
+ }
1038
1081
  setState((prev) => ({ ...prev, loading: true }));
1039
1082
  try {
1040
1083
  const video = videoRef.current;
@@ -1257,7 +1300,7 @@ function FaceScanModal({ onComplete }) {
1257
1300
  const errorData = error?.errorData || {};
1258
1301
  if (errorMessage.includes("Face already registered") || errorMessage.includes("already registered") || errorData?.message?.includes("Face already registered") || error?.statusCode === 500 && errorMessage.includes("Face")) {
1259
1302
  setToast({
1260
- message: "Face has already been registered for this session. Proceeding to document upload.",
1303
+ message: "Face already registered",
1261
1304
  type: "warning"
1262
1305
  });
1263
1306
  return;