biometry-react-components 1.2.14 → 1.2.16

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 CHANGED
@@ -91,17 +91,17 @@ Records video with facial guidance overlay and displays 10 random numbers (0-9)
91
91
  import { FaceRecorder } from 'biometry-react-components';
92
92
 
93
93
  function FaceRecorder() {
94
- const handleCapture = (video: File, audio: File, phrase: string) => {
95
- console.log('Captured video:', video);
96
- console.log('Captured audio:', audio);
94
+ const handleConfirm = (video: File, audio: File, phrase: string) => {
95
+ console.log('Confirmed video:', video);
96
+ console.log('Confirmed audio:', audio);
97
97
  console.log('Phrase:', phrase);
98
98
  // Send files to your endpoint that will process the biometric data
99
- // or
100
99
  // const response = await sdk.processVideo(video, phrase, userFullName);
100
+ // or
101
101
  // const voiceResponse = await sdk.enrollVoice(audio, userFullName);
102
102
  };
103
103
 
104
- return <FaceRecorder onCapture={handleCapture} />;
104
+ return <FaceRecorder onConfirmRecording={handleConfirm} />;
105
105
  }
106
106
  ```
107
107
 
@@ -109,7 +109,8 @@ function FaceRecorder() {
109
109
 
110
110
  | Prop | Type | Default | Description |
111
111
  |------|------|---------|-------------|
112
- | `onCapture` | `(video: File, audio: File, phrase: string) => void` | **required** | Callback with captured video file, audio file, and phrase |
112
+ | `onConfirmRecording` | `(video: File, audio: File, phrase: string) => void` | **required** | Triggered when the user confirms they want to use the recorded video. Provides both media files and the spoken phrase. |
113
+ | `onRecordingComplete` | `(video: File, audio: File, phrase: string) => void` | - | Triggered automatically right after recording finishes. Useful for pre-uploading or background processing. *Optional* |
113
114
  | `rectWidth` | `number` | `360` | Width of camera area |
114
115
  | `rectHeight` | `number` | `576` | Height of camera area |
115
116
  | `className` | `string` | - | Custom CSS class |
package/dist/index.d.ts CHANGED
@@ -23,8 +23,8 @@ declare const FaceCapture: React.FC<FaceCaptureProps>;
23
23
  interface FaceRecorderProps {
24
24
  rectWidth?: number;
25
25
  rectHeight?: number;
26
- onCapture: (file: File, audio: File, phrase: string) => void;
27
- onRecorded?: (video: File, audio: File, phrase: string) => void;
26
+ onConfirmRecording: (file: File, audio: File, phrase: string) => void;
27
+ onRecordingComplete?: (video: File, audio: File, phrase: string) => void;
28
28
  className?: string;
29
29
  style?: React.CSSProperties;
30
30
  noShadow?: boolean;
package/dist/index.esm.js CHANGED
@@ -7279,7 +7279,7 @@ function generateRandomDigits$1(count) {
7279
7279
  }
7280
7280
  return digits.slice(0, count);
7281
7281
  }
7282
- const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded, className, style, noShadow = false, }) => {
7282
+ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onConfirmRecording, onRecordingComplete, className, style, noShadow = false, }) => {
7283
7283
  const [state, setState] = useState('preparation');
7284
7284
  const [prepTimer, setPrepTimer] = useState(PREP_SECONDS$1);
7285
7285
  const [recordTimer, setRecordTimer] = useState(RECORD_SECONDS$1);
@@ -7291,6 +7291,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded
7291
7291
  const [isConfirming, setIsConfirming] = useState(false);
7292
7292
  const videoRef = useRef(null);
7293
7293
  const previewRef = useRef(null);
7294
+ const hasNotifiedRef = useRef(false);
7294
7295
  const [micLevel, setMicLevel] = React.useState(0);
7295
7296
  const analyserRef = React.useRef(null);
7296
7297
  const audioCtxRef = React.useRef(null);
@@ -7311,16 +7312,12 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded
7311
7312
  });
7312
7313
  // Audio recorder
7313
7314
  const { startRecording: startAudioRecording, cancelRecording: cancelAudioRecording } = useRecorder(stream, "audio", (blob) => {
7314
- let finalAudioBlob = blob && blob.size > 0
7315
- ? blob
7316
- : new Blob(['dummy audio data'], { type: 'audio/webm' });
7317
- setAudioBlob(finalAudioBlob);
7318
- // Ensure we have both blobs before triggering new callback
7319
- if (videoBlob && finalAudioBlob && onRecorded) {
7320
- const videoFile = new File([videoBlob], 'face-video.webm', { type: videoBlob.type });
7321
- const audioFile = new File([finalAudioBlob], 'face-audio.webm', { type: finalAudioBlob.type });
7322
- const phrase = numbersToPhrase(digits);
7323
- onRecorded(videoFile, audioFile, phrase);
7315
+ if (blob && blob.size > 0) {
7316
+ setAudioBlob(blob);
7317
+ }
7318
+ else {
7319
+ const dummyBlob = new Blob(['dummy audio data'], { type: 'audio/webm' });
7320
+ setAudioBlob(dummyBlob);
7324
7321
  }
7325
7322
  // Only show result when both recordings are done
7326
7323
  // Video callback will be called first, then audio
@@ -7329,6 +7326,24 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded
7329
7326
  setIsConfirming(true);
7330
7327
  stopAudioVisualization();
7331
7328
  });
7329
+ useEffect(() => {
7330
+ // If we already notified for this recording, skip
7331
+ if (hasNotifiedRef.current)
7332
+ return;
7333
+ if (videoBlob && audioBlob && onRecordingComplete) {
7334
+ hasNotifiedRef.current = true; // prevent double-calls
7335
+ const videoFile = new File([videoBlob], 'face-video.webm', { type: videoBlob.type });
7336
+ const audioFile = new File([audioBlob], 'face-audio.webm', { type: audioBlob.type });
7337
+ const phrase = numbersToPhrase(digits);
7338
+ try {
7339
+ onRecordingComplete(videoFile, audioFile, phrase);
7340
+ }
7341
+ catch (err) {
7342
+ // swallow errors from consumer callback to avoid breaking SDK logic
7343
+ console.error('onRecordingComplete callback threw:', err);
7344
+ }
7345
+ }
7346
+ }, [videoBlob, audioBlob, digits, onRecordingComplete]);
7332
7347
  // Attach the video stream to the <video> element
7333
7348
  useEffect(() => {
7334
7349
  let isMounted = true;
@@ -7401,6 +7416,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded
7401
7416
  stopStreamTracks();
7402
7417
  setState('preparation');
7403
7418
  setIsConfirming(false);
7419
+ // Reset notified flag
7420
+ hasNotifiedRef.current = false;
7404
7421
  setVideoUrl(null);
7405
7422
  setVideoBlob(null);
7406
7423
  setAudioBlob(null);
@@ -7414,8 +7431,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded
7414
7431
  // Create file objects
7415
7432
  const videoFile = new File([videoBlob], 'face-video.webm', { type: videoBlob.type });
7416
7433
  const audioFile = new File([audioBlob], 'face-audio.webm', { type: audioBlob.type });
7417
- // Call onCapture immediately with both files
7418
- onCapture(videoFile, audioFile, numbersToPhrase(digits));
7434
+ // required callback in parent app
7435
+ onConfirmRecording(videoFile, audioFile, numbersToPhrase(digits));
7419
7436
  // Clean up and reset state
7420
7437
  if (videoUrl)
7421
7438
  URL.revokeObjectURL(videoUrl);
@@ -7424,6 +7441,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded
7424
7441
  setAudioBlob(null);
7425
7442
  setIsConfirming(false);
7426
7443
  setState('preparation');
7444
+ // Reset notified flag
7445
+ hasNotifiedRef.current = false;
7427
7446
  // Reset digits for next recording
7428
7447
  setDigits(generateRandomDigits$1(DIGITS_NUMBER$1));
7429
7448
  // Restart stream for next recording
@@ -7438,6 +7457,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded
7438
7457
  setAudioBlob(null);
7439
7458
  setIsConfirming(false);
7440
7459
  setState('preparation');
7460
+ // Reset notified flag
7461
+ hasNotifiedRef.current = false;
7441
7462
  // Reset digits for next recording
7442
7463
  setDigits(generateRandomDigits$1(DIGITS_NUMBER$1));
7443
7464
  // Restart the stream for retake
package/dist/index.js CHANGED
@@ -7279,7 +7279,7 @@ function generateRandomDigits$1(count) {
7279
7279
  }
7280
7280
  return digits.slice(0, count);
7281
7281
  }
7282
- const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded, className, style, noShadow = false, }) => {
7282
+ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onConfirmRecording, onRecordingComplete, className, style, noShadow = false, }) => {
7283
7283
  const [state, setState] = React.useState('preparation');
7284
7284
  const [prepTimer, setPrepTimer] = React.useState(PREP_SECONDS$1);
7285
7285
  const [recordTimer, setRecordTimer] = React.useState(RECORD_SECONDS$1);
@@ -7291,6 +7291,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded
7291
7291
  const [isConfirming, setIsConfirming] = React.useState(false);
7292
7292
  const videoRef = React.useRef(null);
7293
7293
  const previewRef = React.useRef(null);
7294
+ const hasNotifiedRef = React.useRef(false);
7294
7295
  const [micLevel, setMicLevel] = React.useState(0);
7295
7296
  const analyserRef = React.useRef(null);
7296
7297
  const audioCtxRef = React.useRef(null);
@@ -7311,16 +7312,12 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded
7311
7312
  });
7312
7313
  // Audio recorder
7313
7314
  const { startRecording: startAudioRecording, cancelRecording: cancelAudioRecording } = useRecorder(stream, "audio", (blob) => {
7314
- let finalAudioBlob = blob && blob.size > 0
7315
- ? blob
7316
- : new Blob(['dummy audio data'], { type: 'audio/webm' });
7317
- setAudioBlob(finalAudioBlob);
7318
- // Ensure we have both blobs before triggering new callback
7319
- if (videoBlob && finalAudioBlob && onRecorded) {
7320
- const videoFile = new File([videoBlob], 'face-video.webm', { type: videoBlob.type });
7321
- const audioFile = new File([finalAudioBlob], 'face-audio.webm', { type: finalAudioBlob.type });
7322
- const phrase = numbersToPhrase(digits);
7323
- onRecorded(videoFile, audioFile, phrase);
7315
+ if (blob && blob.size > 0) {
7316
+ setAudioBlob(blob);
7317
+ }
7318
+ else {
7319
+ const dummyBlob = new Blob(['dummy audio data'], { type: 'audio/webm' });
7320
+ setAudioBlob(dummyBlob);
7324
7321
  }
7325
7322
  // Only show result when both recordings are done
7326
7323
  // Video callback will be called first, then audio
@@ -7329,6 +7326,24 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded
7329
7326
  setIsConfirming(true);
7330
7327
  stopAudioVisualization();
7331
7328
  });
7329
+ React.useEffect(() => {
7330
+ // If we already notified for this recording, skip
7331
+ if (hasNotifiedRef.current)
7332
+ return;
7333
+ if (videoBlob && audioBlob && onRecordingComplete) {
7334
+ hasNotifiedRef.current = true; // prevent double-calls
7335
+ const videoFile = new File([videoBlob], 'face-video.webm', { type: videoBlob.type });
7336
+ const audioFile = new File([audioBlob], 'face-audio.webm', { type: audioBlob.type });
7337
+ const phrase = numbersToPhrase(digits);
7338
+ try {
7339
+ onRecordingComplete(videoFile, audioFile, phrase);
7340
+ }
7341
+ catch (err) {
7342
+ // swallow errors from consumer callback to avoid breaking SDK logic
7343
+ console.error('onRecordingComplete callback threw:', err);
7344
+ }
7345
+ }
7346
+ }, [videoBlob, audioBlob, digits, onRecordingComplete]);
7332
7347
  // Attach the video stream to the <video> element
7333
7348
  React.useEffect(() => {
7334
7349
  let isMounted = true;
@@ -7401,6 +7416,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded
7401
7416
  stopStreamTracks();
7402
7417
  setState('preparation');
7403
7418
  setIsConfirming(false);
7419
+ // Reset notified flag
7420
+ hasNotifiedRef.current = false;
7404
7421
  setVideoUrl(null);
7405
7422
  setVideoBlob(null);
7406
7423
  setAudioBlob(null);
@@ -7414,8 +7431,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded
7414
7431
  // Create file objects
7415
7432
  const videoFile = new File([videoBlob], 'face-video.webm', { type: videoBlob.type });
7416
7433
  const audioFile = new File([audioBlob], 'face-audio.webm', { type: audioBlob.type });
7417
- // Call onCapture immediately with both files
7418
- onCapture(videoFile, audioFile, numbersToPhrase(digits));
7434
+ // required callback in parent app
7435
+ onConfirmRecording(videoFile, audioFile, numbersToPhrase(digits));
7419
7436
  // Clean up and reset state
7420
7437
  if (videoUrl)
7421
7438
  URL.revokeObjectURL(videoUrl);
@@ -7424,6 +7441,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded
7424
7441
  setAudioBlob(null);
7425
7442
  setIsConfirming(false);
7426
7443
  setState('preparation');
7444
+ // Reset notified flag
7445
+ hasNotifiedRef.current = false;
7427
7446
  // Reset digits for next recording
7428
7447
  setDigits(generateRandomDigits$1(DIGITS_NUMBER$1));
7429
7448
  // Restart stream for next recording
@@ -7438,6 +7457,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, onRecorded
7438
7457
  setAudioBlob(null);
7439
7458
  setIsConfirming(false);
7440
7459
  setState('preparation');
7460
+ // Reset notified flag
7461
+ hasNotifiedRef.current = false;
7441
7462
  // Reset digits for next recording
7442
7463
  setDigits(generateRandomDigits$1(DIGITS_NUMBER$1));
7443
7464
  // Restart the stream for retake
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "biometry-react-components",
3
- "version": "1.2.14",
3
+ "version": "1.2.16",
4
4
  "type": "module",
5
5
  "description": "React UI component library for capturing high-quality biometric data (voice, face, documents, video) to facilitate integration with Biometry services",
6
6
  "main": "dist/index.js",