@idmission/websdk-core 0.1.0-rc.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/README.md +66 -0
- package/dist/attestation/attestationState.d.ts +24 -0
- package/dist/attestation/attestationState.d.ts.map +1 -0
- package/dist/attestation/attestationState.js +57 -0
- package/dist/attestation/clientAttestation.d.ts +40 -0
- package/dist/attestation/clientAttestation.d.ts.map +1 -0
- package/dist/attestation/clientAttestation.js +19 -0
- package/dist/attestation/collectClientAttestation.d.ts +10 -0
- package/dist/attestation/collectClientAttestation.d.ts.map +1 -0
- package/dist/attestation/collectClientAttestation.js +18 -0
- package/dist/attestation/index.d.ts +5 -0
- package/dist/attestation/index.d.ts.map +1 -0
- package/dist/attestation/index.js +4 -0
- package/dist/attestation/nativeAttestationBridge.d.ts +3 -0
- package/dist/attestation/nativeAttestationBridge.d.ts.map +1 -0
- package/dist/attestation/nativeAttestationBridge.js +38 -0
- package/dist/barcode/AAMVAParser.d.ts +77 -0
- package/dist/barcode/AAMVAParser.d.ts.map +1 -0
- package/dist/barcode/AAMVAParser.js +422 -0
- package/dist/barcode/NativeBarcodeDecoder.d.ts +157 -0
- package/dist/barcode/NativeBarcodeDecoder.d.ts.map +1 -0
- package/dist/barcode/NativeBarcodeDecoder.js +832 -0
- package/dist/barcode/Parse.d.ts +6 -0
- package/dist/barcode/Parse.d.ts.map +1 -0
- package/dist/barcode/Parse.js +148 -0
- package/dist/barcode/decodeSummary.d.ts +45 -0
- package/dist/barcode/decodeSummary.d.ts.map +1 -0
- package/dist/barcode/decodeSummary.js +23 -0
- package/dist/barcode/index.d.ts +5 -0
- package/dist/barcode/index.d.ts.map +1 -0
- package/dist/barcode/index.js +4 -0
- package/dist/camera/Camera.d.ts +37 -0
- package/dist/camera/Camera.d.ts.map +1 -0
- package/dist/camera/Camera.js +453 -0
- package/dist/camera/acquireCamera.d.ts +29 -0
- package/dist/camera/acquireCamera.d.ts.map +1 -0
- package/dist/camera/acquireCamera.js +224 -0
- package/dist/camera/cameraSignals.d.ts +23 -0
- package/dist/camera/cameraSignals.d.ts.map +1 -0
- package/dist/camera/cameraSignals.js +32 -0
- package/dist/camera/getUserMediaIntegrity.d.ts +72 -0
- package/dist/camera/getUserMediaIntegrity.d.ts.map +1 -0
- package/dist/camera/getUserMediaIntegrity.js +256 -0
- package/dist/camera/index.d.ts +6 -0
- package/dist/camera/index.d.ts.map +1 -0
- package/dist/camera/index.js +5 -0
- package/dist/camera/isVirtualCamera.d.ts +10 -0
- package/dist/camera/isVirtualCamera.d.ts.map +1 -0
- package/dist/camera/isVirtualCamera.js +11 -0
- package/dist/client/IdmissionClient.d.ts +151 -0
- package/dist/client/IdmissionClient.d.ts.map +1 -0
- package/dist/client/IdmissionClient.js +638 -0
- package/dist/client/additionalDocument.d.ts +14 -0
- package/dist/client/additionalDocument.d.ts.map +1 -0
- package/dist/client/additionalDocument.js +24 -0
- package/dist/client/artifacts.d.ts +146 -0
- package/dist/client/artifacts.d.ts.map +1 -0
- package/dist/client/artifacts.js +1 -0
- package/dist/client/blobToB64.d.ts +2 -0
- package/dist/client/blobToB64.d.ts.map +1 -0
- package/dist/client/blobToB64.js +17 -0
- package/dist/client/endpoints.d.ts +7 -0
- package/dist/client/endpoints.d.ts.map +1 -0
- package/dist/client/endpoints.js +59 -0
- package/dist/client/errors.d.ts +20 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/errors.js +45 -0
- package/dist/client/index.d.ts +23 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +38 -0
- package/dist/client/payload.d.ts +36 -0
- package/dist/client/payload.d.ts.map +1 -0
- package/dist/client/payload.js +397 -0
- package/dist/client/sessionMachine.d.ts +26 -0
- package/dist/client/sessionMachine.d.ts.map +1 -0
- package/dist/client/sessionMachine.js +23 -0
- package/dist/client/submissionMetadata.d.ts +31 -0
- package/dist/client/submissionMetadata.d.ts.map +1 -0
- package/dist/client/submissionMetadata.js +90 -0
- package/dist/client/timings.d.ts +49 -0
- package/dist/client/timings.d.ts.map +1 -0
- package/dist/client/timings.js +32 -0
- package/dist/client/types.d.ts +305 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +18 -0
- package/dist/client/upload.d.ts +60 -0
- package/dist/client/upload.d.ts.map +1 -0
- package/dist/client/upload.js +313 -0
- package/dist/client/uploadedDocument.d.ts +7 -0
- package/dist/client/uploadedDocument.d.ts.map +1 -0
- package/dist/client/uploadedDocument.js +4 -0
- package/dist/client/urls.d.ts +30 -0
- package/dist/client/urls.d.ts.map +1 -0
- package/dist/client/urls.js +73 -0
- package/dist/client/validateSession.d.ts +7 -0
- package/dist/client/validateSession.d.ts.map +1 -0
- package/dist/client/validateSession.js +63 -0
- package/dist/config/cdn.d.ts +2 -0
- package/dist/config/cdn.d.ts.map +1 -0
- package/dist/config/cdn.js +1 -0
- package/dist/diagnostics/buffer.d.ts +8 -0
- package/dist/diagnostics/buffer.d.ts.map +1 -0
- package/dist/diagnostics/buffer.js +25 -0
- package/dist/diagnostics/envCapability.d.ts +3 -0
- package/dist/diagnostics/envCapability.d.ts.map +1 -0
- package/dist/diagnostics/envCapability.js +40 -0
- package/dist/diagnostics/floodControl.d.ts +6 -0
- package/dist/diagnostics/floodControl.d.ts.map +1 -0
- package/dist/diagnostics/floodControl.js +29 -0
- package/dist/diagnostics/index.d.ts +8 -0
- package/dist/diagnostics/index.d.ts.map +1 -0
- package/dist/diagnostics/index.js +17 -0
- package/dist/diagnostics/install.d.ts +20 -0
- package/dist/diagnostics/install.d.ts.map +1 -0
- package/dist/diagnostics/install.js +159 -0
- package/dist/diagnostics/redaction.d.ts +7 -0
- package/dist/diagnostics/redaction.d.ts.map +1 -0
- package/dist/diagnostics/redaction.js +73 -0
- package/dist/diagnostics/transport.d.ts +15 -0
- package/dist/diagnostics/transport.d.ts.map +1 -0
- package/dist/diagnostics/transport.js +35 -0
- package/dist/diagnostics/types.d.ts +59 -0
- package/dist/diagnostics/types.d.ts.map +1 -0
- package/dist/diagnostics/types.js +1 -0
- package/dist/documentCapture/controller.d.ts +35 -0
- package/dist/documentCapture/controller.d.ts.map +1 -0
- package/dist/documentCapture/controller.js +254 -0
- package/dist/documentCapture/index.d.ts +4 -0
- package/dist/documentCapture/index.d.ts.map +1 -0
- package/dist/documentCapture/index.js +8 -0
- package/dist/documentCapture/reducer.d.ts +31 -0
- package/dist/documentCapture/reducer.d.ts.map +1 -0
- package/dist/documentCapture/reducer.js +87 -0
- package/dist/documentCapture/state.d.ts +49 -0
- package/dist/documentCapture/state.d.ts.map +1 -0
- package/dist/documentCapture/state.js +36 -0
- package/dist/idCapture/controller.d.ts +228 -0
- package/dist/idCapture/controller.d.ts.map +1 -0
- package/dist/idCapture/controller.js +1453 -0
- package/dist/idCapture/errors.d.ts +36 -0
- package/dist/idCapture/errors.d.ts.map +1 -0
- package/dist/idCapture/errors.js +18 -0
- package/dist/idCapture/guidance.d.ts +80 -0
- package/dist/idCapture/guidance.d.ts.map +1 -0
- package/dist/idCapture/guidance.js +143 -0
- package/dist/idCapture/index.d.ts +22 -0
- package/dist/idCapture/index.d.ts.map +1 -0
- package/dist/idCapture/index.js +46 -0
- package/dist/idCapture/phase.d.ts +10 -0
- package/dist/idCapture/phase.d.ts.map +1 -0
- package/dist/idCapture/phase.js +28 -0
- package/dist/idCapture/pipeline.d.ts +176 -0
- package/dist/idCapture/pipeline.d.ts.map +1 -0
- package/dist/idCapture/pipeline.js +1028 -0
- package/dist/idCapture/reducer.d.ts +3 -0
- package/dist/idCapture/reducer.d.ts.map +1 -0
- package/dist/idCapture/reducer.js +661 -0
- package/dist/idCapture/requirements.d.ts +10 -0
- package/dist/idCapture/requirements.d.ts.map +1 -0
- package/dist/idCapture/requirements.js +43 -0
- package/dist/idCapture/stabilizer.d.ts +2 -0
- package/dist/idCapture/stabilizer.d.ts.map +1 -0
- package/dist/idCapture/stabilizer.js +4 -0
- package/dist/idCapture/state.d.ts +426 -0
- package/dist/idCapture/state.d.ts.map +1 -0
- package/dist/idCapture/state.js +91 -0
- package/dist/idCapture/submit.d.ts +33 -0
- package/dist/idCapture/submit.d.ts.map +1 -0
- package/dist/idCapture/submit.js +105 -0
- package/dist/idCapture/types.d.ts +20 -0
- package/dist/idCapture/types.d.ts.map +1 -0
- package/dist/idCapture/types.js +12 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/liveness/challengeGeometry.d.ts +66 -0
- package/dist/liveness/challengeGeometry.d.ts.map +1 -0
- package/dist/liveness/challengeGeometry.js +226 -0
- package/dist/liveness/challengeSequence.d.ts +49 -0
- package/dist/liveness/challengeSequence.d.ts.map +1 -0
- package/dist/liveness/challengeSequence.js +71 -0
- package/dist/liveness/index.d.ts +4 -0
- package/dist/liveness/index.d.ts.map +1 -0
- package/dist/liveness/index.js +3 -0
- package/dist/liveness/livenessResult.d.ts +11 -0
- package/dist/liveness/livenessResult.d.ts.map +1 -0
- package/dist/liveness/livenessResult.js +16 -0
- package/dist/models/BarcodeReadability.d.ts +36 -0
- package/dist/models/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/BarcodeReadability.js +71 -0
- package/dist/models/CapabilityProbing.d.ts +25 -0
- package/dist/models/CapabilityProbing.d.ts.map +1 -0
- package/dist/models/CapabilityProbing.js +172 -0
- package/dist/models/DocumentDetection.d.ts +96 -0
- package/dist/models/DocumentDetection.d.ts.map +1 -0
- package/dist/models/DocumentDetection.js +257 -0
- package/dist/models/FaceDetection.d.ts +21 -0
- package/dist/models/FaceDetection.d.ts.map +1 -0
- package/dist/models/FaceDetection.js +4 -0
- package/dist/models/Focus.d.ts +36 -0
- package/dist/models/Focus.d.ts.map +1 -0
- package/dist/models/Focus.js +69 -0
- package/dist/models/FrameLoop.d.ts +13 -0
- package/dist/models/FrameLoop.d.ts.map +1 -0
- package/dist/models/FrameLoop.js +56 -0
- package/dist/models/VisionRuntime.d.ts +18 -0
- package/dist/models/VisionRuntime.d.ts.map +1 -0
- package/dist/models/VisionRuntime.js +158 -0
- package/dist/models/defaults/BarcodeReadability.d.ts +3 -0
- package/dist/models/defaults/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/defaults/BarcodeReadability.js +3 -0
- package/dist/models/defaults/BarcodeReadabilityLiteRT.d.ts +3 -0
- package/dist/models/defaults/BarcodeReadabilityLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/BarcodeReadabilityLiteRT.js +3 -0
- package/dist/models/defaults/DocumentDetector.d.ts +3 -0
- package/dist/models/defaults/DocumentDetector.d.ts.map +1 -0
- package/dist/models/defaults/DocumentDetector.js +3 -0
- package/dist/models/defaults/DocumentDetectorLiteRT.d.ts +3 -0
- package/dist/models/defaults/DocumentDetectorLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/DocumentDetectorLiteRT.js +3 -0
- package/dist/models/defaults/FaceDetector.d.ts +3 -0
- package/dist/models/defaults/FaceDetector.d.ts.map +1 -0
- package/dist/models/defaults/FaceDetector.js +3 -0
- package/dist/models/defaults/FaceLandmarker.d.ts +3 -0
- package/dist/models/defaults/FaceLandmarker.d.ts.map +1 -0
- package/dist/models/defaults/FaceLandmarker.js +8 -0
- package/dist/models/defaults/FaceLandmarkerLiteRT.d.ts +3 -0
- package/dist/models/defaults/FaceLandmarkerLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/FaceLandmarkerLiteRT.js +3 -0
- package/dist/models/defaults/Focus.d.ts +3 -0
- package/dist/models/defaults/Focus.d.ts.map +1 -0
- package/dist/models/defaults/Focus.js +3 -0
- package/dist/models/defaults/FocusLiteRT.d.ts +3 -0
- package/dist/models/defaults/FocusLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/FocusLiteRT.js +3 -0
- package/dist/models/defaults/index.d.ts +31 -0
- package/dist/models/defaults/index.d.ts.map +1 -0
- package/dist/models/defaults/index.js +38 -0
- package/dist/models/helpers.d.ts +25 -0
- package/dist/models/helpers.d.ts.map +1 -0
- package/dist/models/helpers.js +98 -0
- package/dist/models/index.d.ts +15 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +14 -0
- package/dist/models/modelLifecycle.d.ts +26 -0
- package/dist/models/modelLifecycle.d.ts.map +1 -0
- package/dist/models/modelLifecycle.js +137 -0
- package/dist/models/occlusion.d.ts +20 -0
- package/dist/models/occlusion.d.ts.map +1 -0
- package/dist/models/occlusion.js +109 -0
- package/dist/models/passportBooklet.d.ts +34 -0
- package/dist/models/passportBooklet.d.ts.map +1 -0
- package/dist/models/passportBooklet.js +152 -0
- package/dist/models/preloadModels.d.ts +42 -0
- package/dist/models/preloadModels.d.ts.map +1 -0
- package/dist/models/preloadModels.js +204 -0
- package/dist/models/providers/litert/BarcodeReadability.d.ts +11 -0
- package/dist/models/providers/litert/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/providers/litert/BarcodeReadability.js +135 -0
- package/dist/models/providers/litert/CapabilityProbe.d.ts +3 -0
- package/dist/models/providers/litert/CapabilityProbe.d.ts.map +1 -0
- package/dist/models/providers/litert/CapabilityProbe.js +44 -0
- package/dist/models/providers/litert/DocumentDetection.d.ts +18 -0
- package/dist/models/providers/litert/DocumentDetection.d.ts.map +1 -0
- package/dist/models/providers/litert/DocumentDetection.js +194 -0
- package/dist/models/providers/litert/FaceDetection.d.ts +11 -0
- package/dist/models/providers/litert/FaceDetection.d.ts.map +1 -0
- package/dist/models/providers/litert/FaceDetection.js +204 -0
- package/dist/models/providers/litert/FaceLandmarker.d.ts +11 -0
- package/dist/models/providers/litert/FaceLandmarker.d.ts.map +1 -0
- package/dist/models/providers/litert/FaceLandmarker.js +199 -0
- package/dist/models/providers/litert/Focus.d.ts +11 -0
- package/dist/models/providers/litert/Focus.d.ts.map +1 -0
- package/dist/models/providers/litert/Focus.js +141 -0
- package/dist/models/providers/litert/barcodeReadabilityPrePost.d.ts +6 -0
- package/dist/models/providers/litert/barcodeReadabilityPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/barcodeReadabilityPrePost.js +68 -0
- package/dist/models/providers/litert/blazeFacePrePost.d.ts +30 -0
- package/dist/models/providers/litert/blazeFacePrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/blazeFacePrePost.js +206 -0
- package/dist/models/providers/litert/docDetectPrePost.d.ts +25 -0
- package/dist/models/providers/litert/docDetectPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/docDetectPrePost.js +197 -0
- package/dist/models/providers/litert/faceMeshPrePost.d.ts +23 -0
- package/dist/models/providers/litert/faceMeshPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/faceMeshPrePost.js +86 -0
- package/dist/models/providers/litert/focusPrePost.d.ts +6 -0
- package/dist/models/providers/litert/focusPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/focusPrePost.js +67 -0
- package/dist/models/providers/litert/runtime.d.ts +14 -0
- package/dist/models/providers/litert/runtime.d.ts.map +1 -0
- package/dist/models/providers/litert/runtime.js +83 -0
- package/dist/models/providers/mediapipe/BarcodeReadability.d.ts +11 -0
- package/dist/models/providers/mediapipe/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/BarcodeReadability.js +68 -0
- package/dist/models/providers/mediapipe/CapabilityProbe.d.ts +2 -0
- package/dist/models/providers/mediapipe/CapabilityProbe.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/CapabilityProbe.js +14 -0
- package/dist/models/providers/mediapipe/DocumentDetection.d.ts +12 -0
- package/dist/models/providers/mediapipe/DocumentDetection.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/DocumentDetection.js +90 -0
- package/dist/models/providers/mediapipe/FaceDetection.d.ts +11 -0
- package/dist/models/providers/mediapipe/FaceDetection.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/FaceDetection.js +93 -0
- package/dist/models/providers/mediapipe/FaceLandmarker.d.ts +46 -0
- package/dist/models/providers/mediapipe/FaceLandmarker.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/FaceLandmarker.js +166 -0
- package/dist/models/providers/mediapipe/Focus.d.ts +11 -0
- package/dist/models/providers/mediapipe/Focus.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/Focus.js +51 -0
- package/dist/models/runtimeSelection.d.ts +5 -0
- package/dist/models/runtimeSelection.d.ts.map +1 -0
- package/dist/models/runtimeSelection.js +21 -0
- package/dist/selfieCapture/challengeRunner.d.ts +38 -0
- package/dist/selfieCapture/challengeRunner.d.ts.map +1 -0
- package/dist/selfieCapture/challengeRunner.js +181 -0
- package/dist/selfieCapture/controller.d.ts +166 -0
- package/dist/selfieCapture/controller.d.ts.map +1 -0
- package/dist/selfieCapture/controller.js +1253 -0
- package/dist/selfieCapture/faceTracking.d.ts +67 -0
- package/dist/selfieCapture/faceTracking.d.ts.map +1 -0
- package/dist/selfieCapture/faceTracking.js +158 -0
- package/dist/selfieCapture/guidance.d.ts +24 -0
- package/dist/selfieCapture/guidance.d.ts.map +1 -0
- package/dist/selfieCapture/guidance.js +41 -0
- package/dist/selfieCapture/index.d.ts +18 -0
- package/dist/selfieCapture/index.d.ts.map +1 -0
- package/dist/selfieCapture/index.js +11 -0
- package/dist/selfieCapture/lighting.d.ts +36 -0
- package/dist/selfieCapture/lighting.d.ts.map +1 -0
- package/dist/selfieCapture/lighting.js +95 -0
- package/dist/selfieCapture/livenessMachine.d.ts +66 -0
- package/dist/selfieCapture/livenessMachine.d.ts.map +1 -0
- package/dist/selfieCapture/livenessMachine.js +137 -0
- package/dist/selfieCapture/pipeline.d.ts +42 -0
- package/dist/selfieCapture/pipeline.d.ts.map +1 -0
- package/dist/selfieCapture/pipeline.js +282 -0
- package/dist/selfieCapture/reducer.d.ts +35 -0
- package/dist/selfieCapture/reducer.d.ts.map +1 -0
- package/dist/selfieCapture/reducer.js +143 -0
- package/dist/selfieCapture/state.d.ts +40 -0
- package/dist/selfieCapture/state.d.ts.map +1 -0
- package/dist/selfieCapture/state.js +36 -0
- package/dist/selfieCapture/testing/challengeFixtures.d.ts +43 -0
- package/dist/selfieCapture/testing/challengeFixtures.d.ts.map +1 -0
- package/dist/selfieCapture/testing/challengeFixtures.js +43 -0
- package/dist/signature/frameDecode.d.ts +48 -0
- package/dist/signature/frameDecode.d.ts.map +1 -0
- package/dist/signature/frameDecode.js +491 -0
- package/dist/signature/index.d.ts +5 -0
- package/dist/signature/index.d.ts.map +1 -0
- package/dist/signature/index.js +4 -0
- package/dist/signature/metadata.d.ts +63 -0
- package/dist/signature/metadata.d.ts.map +1 -0
- package/dist/signature/metadata.js +1 -0
- package/dist/signature/quality.d.ts +169 -0
- package/dist/signature/quality.d.ts.map +1 -0
- package/dist/signature/quality.js +186 -0
- package/dist/signature/signatureValidity.d.ts +149 -0
- package/dist/signature/signatureValidity.d.ts.map +1 -0
- package/dist/signature/signatureValidity.js +305 -0
- package/dist/signatureCapture/controller.d.ts +67 -0
- package/dist/signatureCapture/controller.d.ts.map +1 -0
- package/dist/signatureCapture/controller.js +534 -0
- package/dist/signatureCapture/guidance.d.ts +9 -0
- package/dist/signatureCapture/guidance.d.ts.map +1 -0
- package/dist/signatureCapture/guidance.js +7 -0
- package/dist/signatureCapture/index.d.ts +6 -0
- package/dist/signatureCapture/index.d.ts.map +1 -0
- package/dist/signatureCapture/index.js +5 -0
- package/dist/signatureCapture/pipeline.d.ts +111 -0
- package/dist/signatureCapture/pipeline.d.ts.map +1 -0
- package/dist/signatureCapture/pipeline.js +680 -0
- package/dist/signatureCapture/reducer.d.ts +42 -0
- package/dist/signatureCapture/reducer.d.ts.map +1 -0
- package/dist/signatureCapture/reducer.js +159 -0
- package/dist/signatureCapture/state.d.ts +92 -0
- package/dist/signatureCapture/state.d.ts.map +1 -0
- package/dist/signatureCapture/state.js +24 -0
- package/dist/utils/canvas.d.ts +4 -0
- package/dist/utils/canvas.d.ts.map +1 -0
- package/dist/utils/canvas.js +21 -0
- package/dist/utils/cropping.d.ts +8 -0
- package/dist/utils/cropping.d.ts.map +1 -0
- package/dist/utils/cropping.js +85 -0
- package/dist/utils/dataUrlToBase64.d.ts +7 -0
- package/dist/utils/dataUrlToBase64.d.ts.map +1 -0
- package/dist/utils/dataUrlToBase64.js +67 -0
- package/dist/utils/getFrameDimensions.d.ts +3 -0
- package/dist/utils/getFrameDimensions.d.ts.map +1 -0
- package/dist/utils/getFrameDimensions.js +12 -0
- package/dist/utils/isMobile.d.ts +3 -0
- package/dist/utils/isMobile.d.ts.map +1 -0
- package/dist/utils/isMobile.js +36 -0
- package/dist/utils/logger.d.ts +19 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +25 -0
- package/dist/utils/platform.d.ts +4 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +11 -0
- package/dist/utils/stabilizer.d.ts +26 -0
- package/dist/utils/stabilizer.d.ts.map +1 -0
- package/dist/utils/stabilizer.js +65 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +1 -0
- package/dist/videoIdCapture/controller.d.ts +108 -0
- package/dist/videoIdCapture/controller.d.ts.map +1 -0
- package/dist/videoIdCapture/controller.js +833 -0
- package/dist/videoIdCapture/index.d.ts +5 -0
- package/dist/videoIdCapture/index.d.ts.map +1 -0
- package/dist/videoIdCapture/index.js +2 -0
- package/dist/videoIdCapture/state.d.ts +88 -0
- package/dist/videoIdCapture/state.d.ts.map +1 -0
- package/dist/videoIdCapture/state.js +67 -0
- package/package.json +111 -0
|
@@ -0,0 +1,833 @@
|
|
|
1
|
+
import { acquireCamera, } from '../camera/acquireCamera';
|
|
2
|
+
import { CaptureAttachError } from '../idCapture/errors';
|
|
3
|
+
import { createDetectionPipeline, } from '../idCapture/pipeline';
|
|
4
|
+
import { defaultDocumentDetectionBoundaries } from '../models/DocumentDetection';
|
|
5
|
+
import { waitForEncoderDrain } from '../signatureCapture/pipeline';
|
|
6
|
+
import { buildVideoIdCaptureArtifacts, createInitialVideoIdCaptureState, VideoIdCaptureGuidanceCode, } from './state';
|
|
7
|
+
export const DEFAULT_VIDEO_ID_PREDICTION_THROTTLE_MS = 16;
|
|
8
|
+
const RECENT_DETECTION_WINDOW_MS = 2000;
|
|
9
|
+
export const defaultVideoIdCaptureThresholds = {
|
|
10
|
+
detection: {
|
|
11
|
+
idCardFront: 0.4,
|
|
12
|
+
idCardBack: 0.2,
|
|
13
|
+
passport: 0.25,
|
|
14
|
+
singlePage: 0.3,
|
|
15
|
+
},
|
|
16
|
+
focus: {
|
|
17
|
+
idCardFront: { desktop: 0, mobile: 0 },
|
|
18
|
+
idCardBack: { desktop: 0, mobile: 0 },
|
|
19
|
+
passport: { desktop: 0, mobile: 0 },
|
|
20
|
+
singlePage: { desktop: 0, mobile: 0 },
|
|
21
|
+
},
|
|
22
|
+
goodFrames: {
|
|
23
|
+
idCardFront: 1,
|
|
24
|
+
idCardBack: 1,
|
|
25
|
+
passport: 1,
|
|
26
|
+
singlePage: 1,
|
|
27
|
+
},
|
|
28
|
+
flipShortcutThreshold: 0.7,
|
|
29
|
+
};
|
|
30
|
+
function preferredMimeType() {
|
|
31
|
+
if (typeof MediaRecorder === 'undefined' ||
|
|
32
|
+
typeof MediaRecorder.isTypeSupported !== 'function')
|
|
33
|
+
return '';
|
|
34
|
+
const candidates = [
|
|
35
|
+
'video/webm;codecs=vp9',
|
|
36
|
+
'video/webm;codecs=vp8',
|
|
37
|
+
'video/webm',
|
|
38
|
+
'video/mp4',
|
|
39
|
+
];
|
|
40
|
+
return candidates.find((type) => MediaRecorder.isTypeSupported(type)) ?? '';
|
|
41
|
+
}
|
|
42
|
+
function mapError(cause) {
|
|
43
|
+
if (cause instanceof CaptureAttachError) {
|
|
44
|
+
const code = cause.captureError.code;
|
|
45
|
+
if (code === 'CAMERA_PERMISSION_DENIED' || code === 'CAMERA_UNAVAILABLE') {
|
|
46
|
+
return { code, message: cause.message, recoverable: cause.captureError.recoverable };
|
|
47
|
+
}
|
|
48
|
+
if (code === 'MODEL_LOAD_FAILED') {
|
|
49
|
+
return { code, message: cause.message, recoverable: true };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
code: 'CAPTURE_FAILED',
|
|
54
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
55
|
+
recoverable: true,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function createVideoIdCaptureController(config = {}) {
|
|
59
|
+
const documentType = config.documentType ?? 'idCard';
|
|
60
|
+
const thresholds = config.thresholds ?? defaultVideoIdCaptureThresholds;
|
|
61
|
+
const io = {
|
|
62
|
+
now: config.io?.now ?? (() => new Date()),
|
|
63
|
+
monotonicNow: config.io?.monotonicNow ?? (() => performance.now()),
|
|
64
|
+
setTimeout: config.io?.setTimeout ?? setTimeout.bind(globalThis),
|
|
65
|
+
clearTimeout: config.io?.clearTimeout ?? clearTimeout.bind(globalThis),
|
|
66
|
+
setInterval: config.io?.setInterval ?? setInterval.bind(globalThis),
|
|
67
|
+
clearInterval: config.io?.clearInterval ?? clearInterval.bind(globalThis),
|
|
68
|
+
acquireCamera: config.io?.acquireCamera ?? acquireCamera,
|
|
69
|
+
createPipeline: config.io?.createPipeline ?? createDetectionPipeline,
|
|
70
|
+
createCanvas: config.io?.createCanvas ?? (() => document.createElement('canvas')),
|
|
71
|
+
createMediaRecorder: config.io?.createMediaRecorder ??
|
|
72
|
+
((stream, options) => new MediaRecorder(stream, options)),
|
|
73
|
+
acquireMicrophone: config.io?.acquireMicrophone ??
|
|
74
|
+
(() => navigator.mediaDevices.getUserMedia({ audio: true })),
|
|
75
|
+
createStream: config.io?.createStream ??
|
|
76
|
+
((tracks) => new MediaStream(tracks)),
|
|
77
|
+
};
|
|
78
|
+
const listeners = new Set();
|
|
79
|
+
let state = createInitialVideoIdCaptureState(documentType);
|
|
80
|
+
let video = null;
|
|
81
|
+
let camera = null;
|
|
82
|
+
let pipeline = null;
|
|
83
|
+
let pipelineLoadPromise = null;
|
|
84
|
+
let activeCameraRequest = null;
|
|
85
|
+
let recorder = null;
|
|
86
|
+
// The read-aloud stage's own recorder and stream, kept separate from the
|
|
87
|
+
// video's: sdk2 records audio on a second MediaRecorder unless
|
|
88
|
+
// `mergeAVStreams` puts the track on the video instead.
|
|
89
|
+
let audioRecorder = null;
|
|
90
|
+
let audioStream = null;
|
|
91
|
+
let audioChunks = [];
|
|
92
|
+
let audioStartsAtMs = null;
|
|
93
|
+
let recordingStartedAtMs = 0;
|
|
94
|
+
let readingMinTimer = null;
|
|
95
|
+
let readingTimeoutTimer = null;
|
|
96
|
+
let readingDetectionTimer = null;
|
|
97
|
+
let chunks = [];
|
|
98
|
+
let lastChunkAt = 0;
|
|
99
|
+
let requestDataTimer = null;
|
|
100
|
+
let flipTimer = null;
|
|
101
|
+
let countdownTimer = null;
|
|
102
|
+
let generation = 0;
|
|
103
|
+
let firstGoodFrameAt = null;
|
|
104
|
+
let recentDetectionSamples = [];
|
|
105
|
+
let lastFrameWasSinglePage = false;
|
|
106
|
+
let captureInFlight = false;
|
|
107
|
+
let frontImage = null;
|
|
108
|
+
let backImage = null;
|
|
109
|
+
function update(patch) {
|
|
110
|
+
state = { ...state, ...patch };
|
|
111
|
+
for (const listener of listeners) {
|
|
112
|
+
try {
|
|
113
|
+
listener(state);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// A consumer listener cannot interrupt recording or sibling listeners.
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function stageGuidance(stage) {
|
|
121
|
+
if (stage === 'front')
|
|
122
|
+
return VideoIdCaptureGuidanceCode.SHOW_ID_FRONT;
|
|
123
|
+
if (stage === 'back')
|
|
124
|
+
return VideoIdCaptureGuidanceCode.SHOW_ID_BACK;
|
|
125
|
+
if (stage === 'passport')
|
|
126
|
+
return VideoIdCaptureGuidanceCode.SHOW_PASSPORT;
|
|
127
|
+
return VideoIdCaptureGuidanceCode.FLIP_ID;
|
|
128
|
+
}
|
|
129
|
+
function thresholdFor(stage) {
|
|
130
|
+
if (stage === 'front')
|
|
131
|
+
return thresholds.goodFrames.idCardFront;
|
|
132
|
+
if (stage === 'back')
|
|
133
|
+
return thresholds.goodFrames.idCardBack;
|
|
134
|
+
if (stage === 'passport')
|
|
135
|
+
return thresholds.goodFrames.passport;
|
|
136
|
+
return thresholds.goodFrames.idCardBack;
|
|
137
|
+
}
|
|
138
|
+
function setStage(stage) {
|
|
139
|
+
firstGoodFrameAt = null;
|
|
140
|
+
recentDetectionSamples = [];
|
|
141
|
+
lastFrameWasSinglePage = false;
|
|
142
|
+
update({
|
|
143
|
+
stage,
|
|
144
|
+
guidance: stageGuidance(stage),
|
|
145
|
+
goodFramesCount: 0,
|
|
146
|
+
goodFramesThreshold: thresholdFor(stage),
|
|
147
|
+
progress: 0,
|
|
148
|
+
recentPeakDetectionScore: 0,
|
|
149
|
+
countdownRemaining: null,
|
|
150
|
+
});
|
|
151
|
+
pipeline?.resetBestFrame();
|
|
152
|
+
pipeline?.setRequiredDocumentType(stage === 'passport'
|
|
153
|
+
? 'passport'
|
|
154
|
+
: stage === 'back'
|
|
155
|
+
? 'idCardBack'
|
|
156
|
+
: 'idCardFront');
|
|
157
|
+
}
|
|
158
|
+
function clearTimers() {
|
|
159
|
+
if (flipTimer !== null)
|
|
160
|
+
io.clearTimeout(flipTimer);
|
|
161
|
+
if (countdownTimer !== null)
|
|
162
|
+
io.clearTimeout(countdownTimer);
|
|
163
|
+
if (requestDataTimer !== null)
|
|
164
|
+
io.clearInterval(requestDataTimer);
|
|
165
|
+
if (readingMinTimer !== null)
|
|
166
|
+
io.clearTimeout(readingMinTimer);
|
|
167
|
+
if (readingTimeoutTimer !== null)
|
|
168
|
+
io.clearTimeout(readingTimeoutTimer);
|
|
169
|
+
if (readingDetectionTimer !== null)
|
|
170
|
+
io.clearTimeout(readingDetectionTimer);
|
|
171
|
+
flipTimer = null;
|
|
172
|
+
countdownTimer = null;
|
|
173
|
+
requestDataTimer = null;
|
|
174
|
+
readingMinTimer = null;
|
|
175
|
+
readingTimeoutTimer = null;
|
|
176
|
+
readingDetectionTimer = null;
|
|
177
|
+
}
|
|
178
|
+
function resetCaptureData() {
|
|
179
|
+
clearTimers();
|
|
180
|
+
finishInFlight = false;
|
|
181
|
+
audioChunks = [];
|
|
182
|
+
audioRecorder = null;
|
|
183
|
+
audioStartsAtMs = null;
|
|
184
|
+
chunks = [];
|
|
185
|
+
lastChunkAt = 0;
|
|
186
|
+
recorder = null;
|
|
187
|
+
captureInFlight = false;
|
|
188
|
+
frontImage = null;
|
|
189
|
+
backImage = null;
|
|
190
|
+
setStage(documentType === 'passport' ? 'passport' : 'front');
|
|
191
|
+
}
|
|
192
|
+
function createPipelineInstance() {
|
|
193
|
+
const created = io.createPipeline({
|
|
194
|
+
video: () => video,
|
|
195
|
+
runtime: config.runtime,
|
|
196
|
+
documentDetectorRuntime: config.documentDetectorRuntime,
|
|
197
|
+
focusRuntime: config.focusRuntime,
|
|
198
|
+
allowSinglePageIdCapture: config.allowSinglePageIdCapture,
|
|
199
|
+
enableBarcodeReadabilityModel: false,
|
|
200
|
+
throttleMs: config.throttleMs ?? DEFAULT_VIDEO_ID_PREDICTION_THROTTLE_MS,
|
|
201
|
+
modelAssetPaths: {
|
|
202
|
+
documentDetector: config.assets?.documentDetectionModelUrl,
|
|
203
|
+
focus: config.assets?.focusModelUrl,
|
|
204
|
+
},
|
|
205
|
+
modelLoadTimeoutMs: config.modelLoadTimeoutMs,
|
|
206
|
+
onModelStateChange: (models) => update({
|
|
207
|
+
models: {
|
|
208
|
+
ready: models.ready,
|
|
209
|
+
loadState: models.modelLoadState,
|
|
210
|
+
downloadProgress: models.modelDownloadProgress,
|
|
211
|
+
},
|
|
212
|
+
}),
|
|
213
|
+
});
|
|
214
|
+
created.setThresholds(thresholds);
|
|
215
|
+
created.setBoundaries({
|
|
216
|
+
...defaultDocumentDetectionBoundaries,
|
|
217
|
+
top: 20,
|
|
218
|
+
left: 20,
|
|
219
|
+
right: 20,
|
|
220
|
+
bottom: 0,
|
|
221
|
+
});
|
|
222
|
+
created.onPredictionMade(handlePrediction);
|
|
223
|
+
return created;
|
|
224
|
+
}
|
|
225
|
+
async function requestCamera() {
|
|
226
|
+
if (camera)
|
|
227
|
+
return;
|
|
228
|
+
if (activeCameraRequest)
|
|
229
|
+
return activeCameraRequest;
|
|
230
|
+
if (!video)
|
|
231
|
+
throw new Error('Video element is not attached');
|
|
232
|
+
const run = generation;
|
|
233
|
+
const attachedVideo = video;
|
|
234
|
+
update({ camera: { ...state.camera, accessRequested: true } });
|
|
235
|
+
const cameraPromise = Promise.resolve().then(() => io.acquireCamera(attachedVideo, config.camera));
|
|
236
|
+
const request = (async () => {
|
|
237
|
+
try {
|
|
238
|
+
const [acquired] = await Promise.all([
|
|
239
|
+
cameraPromise,
|
|
240
|
+
pipelineLoadPromise ?? Promise.resolve(),
|
|
241
|
+
]);
|
|
242
|
+
if (run !== generation) {
|
|
243
|
+
acquired.release();
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
camera = acquired;
|
|
247
|
+
update({
|
|
248
|
+
phase: 'ready',
|
|
249
|
+
camera: {
|
|
250
|
+
ready: true,
|
|
251
|
+
accessRequested: true,
|
|
252
|
+
isRearFacing: acquired.isRearFacing,
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
setStage(documentType === 'passport' ? 'passport' : 'front');
|
|
256
|
+
}
|
|
257
|
+
catch (cause) {
|
|
258
|
+
void cameraPromise.then((acquired) => acquired.release(), () => { });
|
|
259
|
+
if (run !== generation)
|
|
260
|
+
return;
|
|
261
|
+
update({ phase: 'error', error: mapError(cause) });
|
|
262
|
+
throw cause;
|
|
263
|
+
}
|
|
264
|
+
})();
|
|
265
|
+
activeCameraRequest = request;
|
|
266
|
+
try {
|
|
267
|
+
await request;
|
|
268
|
+
}
|
|
269
|
+
finally {
|
|
270
|
+
if (activeCameraRequest === request)
|
|
271
|
+
activeCameraRequest = null;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
async function attach(attachedVideo) {
|
|
275
|
+
const run = ++generation;
|
|
276
|
+
activeCameraRequest = null;
|
|
277
|
+
pipelineLoadPromise = null;
|
|
278
|
+
video = attachedVideo;
|
|
279
|
+
update({ phase: 'loading', error: null });
|
|
280
|
+
pipeline?.close();
|
|
281
|
+
pipeline = createPipelineInstance();
|
|
282
|
+
try {
|
|
283
|
+
pipelineLoadPromise = pipeline.load();
|
|
284
|
+
if (config.deferCameraAcquisition) {
|
|
285
|
+
await pipelineLoadPromise;
|
|
286
|
+
if (run !== generation)
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
await requestCamera();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
catch (cause) {
|
|
294
|
+
if (run !== generation)
|
|
295
|
+
return;
|
|
296
|
+
update({ phase: 'error', error: mapError(cause) });
|
|
297
|
+
throw cause;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Acquires the microphone for the read-aloud stage. sdk2 asks for it up
|
|
302
|
+
* front, before recording starts, because `mergeAVStreams` needs the track
|
|
303
|
+
* in hand when the video recorder is created.
|
|
304
|
+
*
|
|
305
|
+
* A denial is NOT fatal to the whole capture: it lands as its own error code
|
|
306
|
+
* so a host can report it (sdk2's `onMicrophoneAccessDenied`), and the flow
|
|
307
|
+
* continues without audio rather than stranding the user mid-recording.
|
|
308
|
+
*/
|
|
309
|
+
async function acquireMicrophone() {
|
|
310
|
+
if (!config.readText || audioStream)
|
|
311
|
+
return;
|
|
312
|
+
try {
|
|
313
|
+
audioStream = await io.acquireMicrophone();
|
|
314
|
+
update({ reading: { ...state.reading, microphoneReady: true } });
|
|
315
|
+
}
|
|
316
|
+
catch {
|
|
317
|
+
audioStream = null;
|
|
318
|
+
update({
|
|
319
|
+
reading: { ...state.reading, microphoneReady: false },
|
|
320
|
+
error: {
|
|
321
|
+
code: 'MICROPHONE_PERMISSION_DENIED',
|
|
322
|
+
message: 'Microphone access was denied.',
|
|
323
|
+
recoverable: true,
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function beginRecording() {
|
|
329
|
+
if (!camera)
|
|
330
|
+
throw new Error('Camera is not ready');
|
|
331
|
+
const mimeType = preferredMimeType();
|
|
332
|
+
const options = {
|
|
333
|
+
videoBitsPerSecond: 270000,
|
|
334
|
+
...(mimeType ? { mimeType } : {}),
|
|
335
|
+
};
|
|
336
|
+
// sdk2 `useVideoRecorder.ts:74-79`: with mergeAVStreams the audio rides on
|
|
337
|
+
// the video stream, so nothing is recorded separately.
|
|
338
|
+
const recordedStream = config.mergeAVStreams && audioStream
|
|
339
|
+
? io.createStream([
|
|
340
|
+
...camera.camera.stream.getTracks(),
|
|
341
|
+
...audioStream.getTracks(),
|
|
342
|
+
])
|
|
343
|
+
: camera.camera.stream;
|
|
344
|
+
const active = io.createMediaRecorder(recordedStream, options);
|
|
345
|
+
chunks = [];
|
|
346
|
+
lastChunkAt = 0;
|
|
347
|
+
active.ondataavailable = (event) => {
|
|
348
|
+
if (event.data.size <= 0)
|
|
349
|
+
return;
|
|
350
|
+
chunks.push(event.data);
|
|
351
|
+
lastChunkAt = io.monotonicNow();
|
|
352
|
+
if (!state.recording.firstChunkReceived) {
|
|
353
|
+
update({ recording: { active: true, firstChunkReceived: true } });
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
active.onerror = () => {
|
|
357
|
+
if (active !== recorder)
|
|
358
|
+
return;
|
|
359
|
+
update({
|
|
360
|
+
phase: 'error',
|
|
361
|
+
recording: { ...state.recording, active: false },
|
|
362
|
+
error: {
|
|
363
|
+
code: 'CAPTURE_FAILED',
|
|
364
|
+
message: 'Video ID recording failed.',
|
|
365
|
+
recoverable: true,
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
recorder = active;
|
|
370
|
+
recordingStartedAtMs = io.monotonicNow();
|
|
371
|
+
update({ recording: { active: true, firstChunkReceived: false } });
|
|
372
|
+
active.start(100);
|
|
373
|
+
requestDataTimer = io.setInterval(() => {
|
|
374
|
+
try {
|
|
375
|
+
if (recorder?.state === 'recording')
|
|
376
|
+
recorder.requestData();
|
|
377
|
+
}
|
|
378
|
+
catch {
|
|
379
|
+
// Recorder may have become inactive between the check and request.
|
|
380
|
+
}
|
|
381
|
+
}, 250);
|
|
382
|
+
}
|
|
383
|
+
async function start() {
|
|
384
|
+
if (state.phase !== 'ready')
|
|
385
|
+
return;
|
|
386
|
+
try {
|
|
387
|
+
// Before the recorder is created: mergeAVStreams needs the track now.
|
|
388
|
+
await acquireMicrophone();
|
|
389
|
+
beginRecording();
|
|
390
|
+
update({ phase: 'capturing' });
|
|
391
|
+
pipeline?.start();
|
|
392
|
+
}
|
|
393
|
+
catch (cause) {
|
|
394
|
+
update({
|
|
395
|
+
phase: 'error',
|
|
396
|
+
error: {
|
|
397
|
+
code: 'RECORDING_UNAVAILABLE',
|
|
398
|
+
message: cause instanceof Error ? cause.message : String(cause),
|
|
399
|
+
recoverable: true,
|
|
400
|
+
},
|
|
401
|
+
});
|
|
402
|
+
throw cause;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
function handlePrediction(prediction) {
|
|
406
|
+
if (state.phase !== 'capturing')
|
|
407
|
+
return;
|
|
408
|
+
const stageDetectionScore = state.stage === 'back' || state.stage === 'flip'
|
|
409
|
+
? prediction.idCardBackDetectionScore
|
|
410
|
+
: state.stage === 'passport'
|
|
411
|
+
? prediction.passportDetectionScore
|
|
412
|
+
: Math.max(prediction.idCardFrontDetectionScore, prediction.singlePageDetectionScore);
|
|
413
|
+
const predictionAt = io.monotonicNow();
|
|
414
|
+
recentDetectionSamples = [
|
|
415
|
+
...recentDetectionSamples.filter((sample) => predictionAt - sample.at <= RECENT_DETECTION_WINDOW_MS),
|
|
416
|
+
{ at: predictionAt, score: stageDetectionScore },
|
|
417
|
+
];
|
|
418
|
+
if (state.stage === 'front' &&
|
|
419
|
+
prediction.singlePageDetectionThresholdMet) {
|
|
420
|
+
lastFrameWasSinglePage = true;
|
|
421
|
+
}
|
|
422
|
+
update({
|
|
423
|
+
detectedObjects: prediction.detectedObjects,
|
|
424
|
+
frameWidth: prediction.frameWidth,
|
|
425
|
+
frameHeight: prediction.frameHeight,
|
|
426
|
+
detectedDocumentType: prediction.detectedDocumentType,
|
|
427
|
+
detectionScore: prediction.detectionScore,
|
|
428
|
+
idCardFrontDetectionScore: prediction.idCardFrontDetectionScore,
|
|
429
|
+
idCardBackDetectionScore: prediction.idCardBackDetectionScore,
|
|
430
|
+
recentPeakDetectionScore: Math.max(0, ...recentDetectionSamples.map((sample) => sample.score)),
|
|
431
|
+
focusScore: prediction.focusScore,
|
|
432
|
+
focusThresholdMet: prediction.focusThresholdMet,
|
|
433
|
+
documentInBounds: prediction.documentInBounds,
|
|
434
|
+
documentTooClose: prediction.documentTooClose,
|
|
435
|
+
documentIsStable: prediction.documentIsStable,
|
|
436
|
+
});
|
|
437
|
+
if (state.stage === 'flip') {
|
|
438
|
+
if (prediction.focusThresholdMet &&
|
|
439
|
+
prediction.idCardBackDetectionScore >= thresholds.flipShortcutThreshold) {
|
|
440
|
+
if (flipTimer !== null)
|
|
441
|
+
io.clearTimeout(flipTimer);
|
|
442
|
+
flipTimer = null;
|
|
443
|
+
setStage('back');
|
|
444
|
+
}
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
const good = prediction.focusThresholdMet &&
|
|
448
|
+
(state.stage === 'front'
|
|
449
|
+
? prediction.idCardFrontDetectionThresholdMet ||
|
|
450
|
+
prediction.singlePageDetectionThresholdMet
|
|
451
|
+
: state.stage === 'back'
|
|
452
|
+
? prediction.idCardBackDetectionThresholdMet
|
|
453
|
+
: prediction.passportDetectionThresholdMet);
|
|
454
|
+
const count = good ? state.goodFramesCount + 1 : 0;
|
|
455
|
+
if (good && firstGoodFrameAt === null) {
|
|
456
|
+
firstGoodFrameAt = io.now().getTime();
|
|
457
|
+
}
|
|
458
|
+
const required = thresholdFor(state.stage);
|
|
459
|
+
const progress = required > 0 ? Math.min(count / required, 1) : 1;
|
|
460
|
+
update({
|
|
461
|
+
goodFramesCount: count,
|
|
462
|
+
goodFramesThreshold: required,
|
|
463
|
+
progress,
|
|
464
|
+
guidance: good
|
|
465
|
+
? VideoIdCaptureGuidanceCode.HOLD_STEADY
|
|
466
|
+
: stageGuidance(state.stage),
|
|
467
|
+
});
|
|
468
|
+
const frontDelaySatisfied = state.stage === 'back' ||
|
|
469
|
+
(firstGoodFrameAt !== null &&
|
|
470
|
+
io.now().getTime() - firstGoodFrameAt >=
|
|
471
|
+
(config.idCardFrontDelayMs ?? 1000));
|
|
472
|
+
if (count >= required && frontDelaySatisfied && countdownTimer === null) {
|
|
473
|
+
startCountdown();
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
function startCountdown() {
|
|
477
|
+
let remaining = config.captureCountdownSeconds ?? 3;
|
|
478
|
+
update({ countdownRemaining: remaining });
|
|
479
|
+
const tick = () => {
|
|
480
|
+
remaining -= 1;
|
|
481
|
+
if (remaining <= 0) {
|
|
482
|
+
countdownTimer = null;
|
|
483
|
+
update({ countdownRemaining: null });
|
|
484
|
+
void capture().catch(() => {
|
|
485
|
+
// capture() already publishes the typed controller error state.
|
|
486
|
+
});
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
update({ countdownRemaining: remaining });
|
|
490
|
+
countdownTimer = io.setTimeout(tick, 1000);
|
|
491
|
+
};
|
|
492
|
+
countdownTimer = io.setTimeout(tick, remaining > 0 ? 1000 : 0);
|
|
493
|
+
}
|
|
494
|
+
function captureImage() {
|
|
495
|
+
if (!video)
|
|
496
|
+
throw new Error('Video element is not attached');
|
|
497
|
+
const canvas = io.createCanvas();
|
|
498
|
+
canvas.width = video.videoWidth || video.clientWidth || 1;
|
|
499
|
+
canvas.height = video.videoHeight || video.clientHeight || 1;
|
|
500
|
+
const context = canvas.getContext('2d');
|
|
501
|
+
if (!context)
|
|
502
|
+
throw new Error('Unable to create video frame');
|
|
503
|
+
context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
504
|
+
return { data: canvas.toDataURL('image/jpeg', 0.95), at: io.now() };
|
|
505
|
+
}
|
|
506
|
+
async function shouldSkipBack() {
|
|
507
|
+
if (config.skipBack === true)
|
|
508
|
+
return true;
|
|
509
|
+
if (typeof config.skipBack === 'function')
|
|
510
|
+
return config.skipBack();
|
|
511
|
+
return false;
|
|
512
|
+
}
|
|
513
|
+
async function capture() {
|
|
514
|
+
if (captureInFlight || state.phase !== 'capturing' || state.stage === 'flip')
|
|
515
|
+
return;
|
|
516
|
+
const run = generation;
|
|
517
|
+
captureInFlight = true;
|
|
518
|
+
try {
|
|
519
|
+
const image = captureImage();
|
|
520
|
+
if (state.stage === 'front') {
|
|
521
|
+
frontImage = image;
|
|
522
|
+
const skipBack = lastFrameWasSinglePage || (await shouldSkipBack());
|
|
523
|
+
if (run !== generation)
|
|
524
|
+
return;
|
|
525
|
+
if (skipBack) {
|
|
526
|
+
await finishCapture();
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
setStage('flip');
|
|
530
|
+
flipTimer = io.setTimeout(() => {
|
|
531
|
+
flipTimer = null;
|
|
532
|
+
if (state.phase === 'capturing' && state.stage === 'flip') {
|
|
533
|
+
setStage('back');
|
|
534
|
+
}
|
|
535
|
+
}, config.flipDurationMs ?? 6000);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
else if (state.stage === 'back') {
|
|
539
|
+
backImage = image;
|
|
540
|
+
await finishCapture();
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
frontImage = image;
|
|
544
|
+
await finishCapture();
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
catch (cause) {
|
|
548
|
+
if (run !== generation)
|
|
549
|
+
return;
|
|
550
|
+
update({ phase: 'error', error: mapError(cause) });
|
|
551
|
+
throw cause;
|
|
552
|
+
}
|
|
553
|
+
finally {
|
|
554
|
+
if (run === generation)
|
|
555
|
+
captureInFlight = false;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
function waitForStop(active) {
|
|
559
|
+
return new Promise((resolve, reject) => {
|
|
560
|
+
let settled = false;
|
|
561
|
+
const finish = (fn) => {
|
|
562
|
+
if (settled)
|
|
563
|
+
return;
|
|
564
|
+
settled = true;
|
|
565
|
+
active.onstop = null;
|
|
566
|
+
active.onerror = null;
|
|
567
|
+
fn();
|
|
568
|
+
};
|
|
569
|
+
active.onstop = () => finish(resolve);
|
|
570
|
+
active.onerror = () => finish(() => reject(new Error('Video ID recorder failed to stop')));
|
|
571
|
+
try {
|
|
572
|
+
active.stop();
|
|
573
|
+
}
|
|
574
|
+
catch (cause) {
|
|
575
|
+
finish(() => reject(cause));
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
async function stopRecording() {
|
|
580
|
+
const active = recorder;
|
|
581
|
+
if (!active)
|
|
582
|
+
throw new Error('Video ID recorder is not active');
|
|
583
|
+
if (requestDataTimer !== null)
|
|
584
|
+
io.clearInterval(requestDataTimer);
|
|
585
|
+
requestDataTimer = null;
|
|
586
|
+
await waitForEncoderDrain({
|
|
587
|
+
recorder: active,
|
|
588
|
+
initialLastValueAt: lastChunkAt || io.monotonicNow(),
|
|
589
|
+
getLastValueAt: () => lastChunkAt,
|
|
590
|
+
now: io.monotonicNow,
|
|
591
|
+
sleep: (ms) => new Promise((resolve) => io.setTimeout(resolve, ms)),
|
|
592
|
+
setInterval: io.setInterval,
|
|
593
|
+
clearInterval: io.clearInterval,
|
|
594
|
+
...config.recorderDrain,
|
|
595
|
+
});
|
|
596
|
+
await waitForStop(active);
|
|
597
|
+
const type = active.mimeType || chunks[0]?.type || 'video/webm';
|
|
598
|
+
const blob = new Blob(chunks, { type });
|
|
599
|
+
recorder = null;
|
|
600
|
+
return blob;
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* sdk2 IdVideoCapture.tsx:410-419: with a read prompt configured, capturing
|
|
604
|
+
* the last ID image does not end the recording — it moves the user to the
|
|
605
|
+
* reading stage, with the video still rolling.
|
|
606
|
+
*/
|
|
607
|
+
function beginReading() {
|
|
608
|
+
audioStartsAtMs = io.monotonicNow() - recordingStartedAtMs;
|
|
609
|
+
if (audioStream && !config.mergeAVStreams) {
|
|
610
|
+
audioChunks = [];
|
|
611
|
+
const active = io.createMediaRecorder(audioStream, {
|
|
612
|
+
audioBitsPerSecond: 32000,
|
|
613
|
+
});
|
|
614
|
+
active.ondataavailable = (event) => {
|
|
615
|
+
if (event.data.size > 0)
|
|
616
|
+
audioChunks.push(event.data);
|
|
617
|
+
};
|
|
618
|
+
audioRecorder = active;
|
|
619
|
+
active.start(100);
|
|
620
|
+
}
|
|
621
|
+
// sdk2 keeps the detector running through the reading unless asked not to
|
|
622
|
+
// (`disableFaceDetectionWhileAudioCapture`, default false).
|
|
623
|
+
if (config.disableFaceDetectionWhileReading) {
|
|
624
|
+
const delayMs = config.disableFaceDetectionWhileReadingMsDelay ?? 0;
|
|
625
|
+
if (delayMs > 0) {
|
|
626
|
+
readingDetectionTimer = io.setTimeout(() => {
|
|
627
|
+
readingDetectionTimer = null;
|
|
628
|
+
pipeline?.stop();
|
|
629
|
+
}, delayMs);
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
pipeline?.stop();
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
const minMs = config.readTextMinReadingMs ?? 0;
|
|
636
|
+
update({
|
|
637
|
+
guidance: VideoIdCaptureGuidanceCode.READ_TEXT,
|
|
638
|
+
reading: { ...state.reading, active: true, canFinish: minMs <= 0 },
|
|
639
|
+
});
|
|
640
|
+
if (minMs > 0) {
|
|
641
|
+
readingMinTimer = io.setTimeout(() => {
|
|
642
|
+
readingMinTimer = null;
|
|
643
|
+
update({ reading: { ...state.reading, canFinish: true } });
|
|
644
|
+
}, minMs);
|
|
645
|
+
}
|
|
646
|
+
const timeoutMs = config.readTextTimeoutDurationMs;
|
|
647
|
+
if (timeoutMs && timeoutMs > 0) {
|
|
648
|
+
readingTimeoutTimer = io.setTimeout(() => {
|
|
649
|
+
readingTimeoutTimer = null;
|
|
650
|
+
// The kick-out finishes the capture with whatever was read, rather
|
|
651
|
+
// than failing it: sdk2 stops the recording and moves on.
|
|
652
|
+
void finishCapture();
|
|
653
|
+
}, timeoutMs);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
async function stopReading() {
|
|
657
|
+
if (readingMinTimer !== null)
|
|
658
|
+
io.clearTimeout(readingMinTimer);
|
|
659
|
+
if (readingTimeoutTimer !== null)
|
|
660
|
+
io.clearTimeout(readingTimeoutTimer);
|
|
661
|
+
readingMinTimer = null;
|
|
662
|
+
readingTimeoutTimer = null;
|
|
663
|
+
const active = audioRecorder;
|
|
664
|
+
audioRecorder = null;
|
|
665
|
+
if (!active)
|
|
666
|
+
return null;
|
|
667
|
+
await waitForStop(active);
|
|
668
|
+
// `audioChunks` is BlobPart[]; only the Blob members carry a type, and the
|
|
669
|
+
// recorder's own mimeType is the authority anyway.
|
|
670
|
+
const first = audioChunks[0];
|
|
671
|
+
const type = active.mimeType || (first instanceof Blob ? first.type : '') || 'audio/webm';
|
|
672
|
+
return new Blob(audioChunks, { type });
|
|
673
|
+
}
|
|
674
|
+
async function finishReading() {
|
|
675
|
+
if (!state.reading.active || !state.reading.canFinish)
|
|
676
|
+
return;
|
|
677
|
+
await finishCapture();
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Latch shared by every route into `finishCapture`.
|
|
681
|
+
*
|
|
682
|
+
* `capture()`'s own `captureInFlight` does not cover the reading stage: the
|
|
683
|
+
* kick-out timer and the user's Done tap both call `finishCapture` directly,
|
|
684
|
+
* and it awaits `stopReading()` before it mutates state — so the second
|
|
685
|
+
* caller passed the phase/reading guards while the first was still awaiting,
|
|
686
|
+
* reached `stopRecording()` after the recorder had been nulled, and threw
|
|
687
|
+
* 'Video ID recorder is not active'.
|
|
688
|
+
*/
|
|
689
|
+
let finishInFlight = false;
|
|
690
|
+
async function finishCapture() {
|
|
691
|
+
if (!frontImage)
|
|
692
|
+
throw new Error('Video ID front frame was not captured');
|
|
693
|
+
// The reading stage sits BETWEEN the last capture and the artifact: enter
|
|
694
|
+
// it here rather than at the call sites, so every route into "the ID is
|
|
695
|
+
// captured" (front-only, back, passport) reaches it the same way.
|
|
696
|
+
if (config.readText && !state.reading.active) {
|
|
697
|
+
beginReading();
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
if (finishInFlight)
|
|
701
|
+
return;
|
|
702
|
+
finishInFlight = true;
|
|
703
|
+
const run = generation;
|
|
704
|
+
let audioBlob = null;
|
|
705
|
+
try {
|
|
706
|
+
audioBlob = state.reading.active ? await stopReading() : null;
|
|
707
|
+
}
|
|
708
|
+
catch (cause) {
|
|
709
|
+
finishInFlight = false;
|
|
710
|
+
throw cause;
|
|
711
|
+
}
|
|
712
|
+
if (run !== generation) {
|
|
713
|
+
finishInFlight = false;
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
update({ phase: 'processing' });
|
|
717
|
+
pipeline?.stop();
|
|
718
|
+
let videoBlob;
|
|
719
|
+
try {
|
|
720
|
+
videoBlob = await stopRecording();
|
|
721
|
+
}
|
|
722
|
+
catch (cause) {
|
|
723
|
+
finishInFlight = false;
|
|
724
|
+
throw cause;
|
|
725
|
+
}
|
|
726
|
+
finishInFlight = false;
|
|
727
|
+
if (run !== generation)
|
|
728
|
+
return;
|
|
729
|
+
const capturedAt = io.now();
|
|
730
|
+
update({
|
|
731
|
+
phase: 'reviewing',
|
|
732
|
+
recording: { ...state.recording, active: false },
|
|
733
|
+
reading: { ...state.reading, active: false },
|
|
734
|
+
artifact: {
|
|
735
|
+
videoBlob,
|
|
736
|
+
capturedAt,
|
|
737
|
+
frontImage: frontImage.data,
|
|
738
|
+
frontCapturedAt: frontImage.at,
|
|
739
|
+
backImage: backImage?.data ?? null,
|
|
740
|
+
backCapturedAt: backImage?.at ?? null,
|
|
741
|
+
audioBlob,
|
|
742
|
+
audioStartsAtMs,
|
|
743
|
+
},
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
async function retry() {
|
|
747
|
+
if (state.phase !== 'reviewing' && state.phase !== 'error')
|
|
748
|
+
return;
|
|
749
|
+
const failedVideo = state.phase === 'error' ? video : null;
|
|
750
|
+
if (failedVideo) {
|
|
751
|
+
detach();
|
|
752
|
+
await attach(failedVideo);
|
|
753
|
+
if (config.deferCameraAcquisition)
|
|
754
|
+
await requestCamera();
|
|
755
|
+
await start();
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
if (recorder && recorder.state !== 'inactive') {
|
|
759
|
+
recorder.ondataavailable = null;
|
|
760
|
+
recorder.onstop = null;
|
|
761
|
+
recorder.onerror = null;
|
|
762
|
+
recorder.stop();
|
|
763
|
+
}
|
|
764
|
+
resetCaptureData();
|
|
765
|
+
update({ phase: 'ready', artifact: null, error: null });
|
|
766
|
+
await start();
|
|
767
|
+
}
|
|
768
|
+
function detach() {
|
|
769
|
+
generation += 1;
|
|
770
|
+
captureInFlight = false;
|
|
771
|
+
clearTimers();
|
|
772
|
+
pipeline?.close();
|
|
773
|
+
pipeline = null;
|
|
774
|
+
pipelineLoadPromise = null;
|
|
775
|
+
activeCameraRequest = null;
|
|
776
|
+
if (recorder && recorder.state !== 'inactive') {
|
|
777
|
+
recorder.ondataavailable = null;
|
|
778
|
+
recorder.onstop = null;
|
|
779
|
+
recorder.onerror = null;
|
|
780
|
+
try {
|
|
781
|
+
recorder.stop();
|
|
782
|
+
}
|
|
783
|
+
catch {
|
|
784
|
+
// Best-effort disposal; no artifact is assembled after detach.
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
recorder = null;
|
|
788
|
+
if (audioRecorder && audioRecorder.state !== 'inactive') {
|
|
789
|
+
audioRecorder.ondataavailable = null;
|
|
790
|
+
audioRecorder.onstop = null;
|
|
791
|
+
audioRecorder.onerror = null;
|
|
792
|
+
try {
|
|
793
|
+
audioRecorder.stop();
|
|
794
|
+
}
|
|
795
|
+
catch {
|
|
796
|
+
// Best-effort disposal, same as the video recorder above.
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
audioRecorder = null;
|
|
800
|
+
audioStream?.getTracks().forEach((track) => track.stop());
|
|
801
|
+
audioStream = null;
|
|
802
|
+
audioChunks = [];
|
|
803
|
+
audioStartsAtMs = null;
|
|
804
|
+
camera?.release();
|
|
805
|
+
camera = null;
|
|
806
|
+
recentDetectionSamples = [];
|
|
807
|
+
if (video)
|
|
808
|
+
video.srcObject = null;
|
|
809
|
+
video = null;
|
|
810
|
+
update(createInitialVideoIdCaptureState(documentType));
|
|
811
|
+
}
|
|
812
|
+
return {
|
|
813
|
+
attach,
|
|
814
|
+
detach,
|
|
815
|
+
getState: () => state,
|
|
816
|
+
subscribe(listener) {
|
|
817
|
+
listeners.add(listener);
|
|
818
|
+
return () => listeners.delete(listener);
|
|
819
|
+
},
|
|
820
|
+
collectArtifacts: () => buildVideoIdCaptureArtifacts(state.artifact),
|
|
821
|
+
actions: {
|
|
822
|
+
start,
|
|
823
|
+
requestCamera,
|
|
824
|
+
capture,
|
|
825
|
+
finishReading,
|
|
826
|
+
retry,
|
|
827
|
+
done() {
|
|
828
|
+
if (state.phase === 'reviewing')
|
|
829
|
+
update({ phase: 'completed' });
|
|
830
|
+
},
|
|
831
|
+
},
|
|
832
|
+
};
|
|
833
|
+
}
|