@sssxyd/face-liveness-detector 0.4.0-alpha.28 → 0.4.0-alpha.29

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/dist/index.esm.js CHANGED
@@ -5077,30 +5077,8 @@ class FaceDetectionEngine extends SimpleEventEmitter {
5077
5077
  }, 'info');
5078
5078
  }
5079
5079
  // Step 3: Prepare finish data (before clearing images)
5080
- // Validate collected images if success is true
5081
- let finalSuccess = success;
5082
- if (success) {
5083
- const hasFrameImage = !!this.detectionState.bestFrameImage;
5084
- const hasFaceImage = !!this.detectionState.bestFaceImage;
5085
- if (!hasFrameImage || !hasFaceImage) {
5086
- finalSuccess = false;
5087
- this.emitDebug('detection', 'Detection marked as success but images are missing', {
5088
- hasFrameImage,
5089
- hasFaceImage,
5090
- collectCount: this.detectionState.collectCount,
5091
- bestQualityScore: this.detectionState.bestQualityScore,
5092
- period: this.detectionState.period
5093
- }, 'warn');
5094
- // Emit error event for missing images
5095
- this.emit('detector-error', {
5096
- code: ErrorCode.INTERNAL_ERROR,
5097
- message: `Detection completed but images are missing: frameImage=${hasFrameImage}, faceImage=${hasFaceImage}`
5098
- });
5099
- }
5100
- }
5101
- // Create a finishData object for emission (with image data)
5102
5080
  const finishData = {
5103
- success: finalSuccess,
5081
+ success: success,
5104
5082
  silentPassedCount: this.detectionState.collectCount,
5105
5083
  actionPassedCount: this.detectionState.completedActions.size,
5106
5084
  totalTime: performance.now() - this.detectionState.startTime,
@@ -5115,10 +5093,6 @@ class FaceDetectionEngine extends SimpleEventEmitter {
5115
5093
  catch (error) {
5116
5094
  this.emitDebug('detection', 'Error emitting detector-finish event', { error: error.message }, 'error');
5117
5095
  }
5118
- // Clear image references from the original finishData object immediately after emit
5119
- // to prevent external listeners from accessing stale data if they store the reference
5120
- finishData.bestFrameImage = undefined;
5121
- finishData.bestFaceImage = undefined;
5122
5096
  // Step 5: Stop video playback
5123
5097
  if (this.videoElement) {
5124
5098
  try {
@@ -5620,19 +5594,19 @@ class FaceDetectionEngine extends SimpleEventEmitter {
5620
5594
  return true;
5621
5595
  }
5622
5596
  if (screenResult) {
5623
- this.emitDebug('screen-detection', 'Screen capture not detected', {
5624
- screenConfidence: screenResult.confidenceScore,
5625
- riskLevel: screenResult.riskLevel,
5626
- processingTimeMs: screenResult.processingTimeMs,
5627
- executedMethodsCount: screenResult.executedMethods?.length || 0,
5628
- methodsSummary: screenResult.executedMethods?.map((m) => `${m.method}:${m.confidence?.toFixed(2)}`).join(', ') || 'none',
5629
- stageCount: screenResult.debug?.stages?.length || 0
5630
- // 移除了 executedMethods stageDetails 的完整数据,避免超大输出
5631
- }, 'info');
5632
- }
5633
- // 只有ready状态的检测器的success结果才可信
5634
- if (this.detectionState.screenDetector?.isReady()) {
5635
- this.detectionState.realness = !screenResult?.isScreenCapture;
5597
+ // 只有ready状态的检测器的success结果才可信
5598
+ if (this.detectionState.screenDetector?.isReady() && !screenResult.isScreenCapture) {
5599
+ this.detectionState.realness = true;
5600
+ this.emitDebug('screen-detection', 'Screen capture not detected', {
5601
+ screenConfidence: screenResult.confidenceScore,
5602
+ riskLevel: screenResult.riskLevel,
5603
+ processingTimeMs: screenResult.processingTimeMs,
5604
+ executedMethodsCount: screenResult.executedMethods?.length || 0,
5605
+ methodsSummary: screenResult.executedMethods?.map((m) => `${m.method}:${m.confidence?.toFixed(2)}`).join(', ') || 'none',
5606
+ stageCount: screenResult.debug?.stages?.length || 0
5607
+ // 移除了 executedMethods 和 stageDetails 的完整数据,避免超大输出
5608
+ }, 'warn');
5609
+ }
5636
5610
  }
5637
5611
  return false;
5638
5612
  }
@@ -5681,6 +5655,14 @@ class FaceDetectionEngine extends SimpleEventEmitter {
5681
5655
  this.partialResetDetectionState();
5682
5656
  return;
5683
5657
  }
5658
+ this.emitDebug('motion-detection', 'Motion liveness check passed', {
5659
+ motionScore: motionResult.motionScore,
5660
+ keypointVariance: motionResult.keypointVariance,
5661
+ opticalFlowMagnitude: motionResult.opticalFlowMagnitude,
5662
+ eyeMotionScore: motionResult.eyeMotionScore,
5663
+ mouthMotionScore: motionResult.mouthMotionScore,
5664
+ motionType: motionResult.motionType
5665
+ }, 'warn');
5684
5666
  this.detectionState.liveness = true;
5685
5667
  }
5686
5668
  // 计算面部大小比例,不达标则跳过当前帧