biometry-react-components 1.3.4 → 1.4.0

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
@@ -121,6 +121,10 @@ function FaceRecorder() {
121
121
 
122
122
  Records audio with real-time waveform visualization and adaptive quality settings. Use this for [Voice Enrollment](https://developer.biometrysolutions.com/api/voice-enrollment/)
123
123
 
124
+ The user is prompted with all ten digits (`0-9`) in random order and gets a 10-second recording window. Both are enrollment requirements: the engine builds a text-prompted digit voiceprint, and verification later prompts a random subset, so the enrollment sample has to cover every digit.
125
+
126
+ > **Note:** the engine builds its voiceprint from **several** recordings. A print built from a single take carries one recording's worth of acoustic variation and scores close enough to the engine's threshold that genuine users can be rejected at login. Call the component more than once and post every take in the same enrollment request (repeated `voice` parts, one `phrase` part each).
127
+
124
128
  ```tsx
125
129
  import { VoiceRecorder } from 'biometry-react-components';
126
130
 
package/dist/index.d.ts CHANGED
@@ -45,7 +45,7 @@ interface VoiceRecorderProps {
45
45
  declare const VoiceRecorder: React.FC<VoiceRecorderProps>;
46
46
 
47
47
  type OnStopRecordingFunc = (blob: Blob) => void;
48
- declare const useRecorder: (stream: MediaStream | null, type: "audio" | "video", onStopRecording: OnStopRecordingFunc) => {
48
+ declare const useRecorder: (stream: MediaStream | null, type: "audio" | "video", onStopRecording: OnStopRecordingFunc, lengthMs?: number) => {
49
49
  isRecording: boolean;
50
50
  startRecording: () => void;
51
51
  stopRecording: () => void;
package/dist/index.esm.js CHANGED
@@ -13,11 +13,7 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
13
13
  (async () => {
14
14
  try {
15
15
  const stream = await navigator.mediaDevices.getUserMedia({ video: { width: rectWidth, height: rectHeight } });
16
- if (!isMounted) {
17
- stream.getTracks().forEach((track) => track.stop());
18
- return;
19
- }
20
- if (videoRef.current) {
16
+ if (videoRef.current && isMounted) {
21
17
  videoRef.current.srcObject = stream;
22
18
  videoRef.current.onloadedmetadata = () => {
23
19
  var _a;
@@ -65,11 +61,6 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
65
61
  ctx.drawImage(video, sx, sy, sw, sh, 0, 0, canvas.width, canvas.height);
66
62
  canvas.toBlob((blob) => {
67
63
  if (blob) {
68
- // Stop the stream immediately — don't wait for useEffect cleanup
69
- if (streamRef.current) {
70
- streamRef.current.getTracks().forEach((track) => track.stop());
71
- streamRef.current = null;
72
- }
73
64
  const file = new File([blob], "document.jpg", { type: "image/jpeg" });
74
65
  setCapturedFile(file);
75
66
  setCapturedUrl(URL.createObjectURL(blob));
@@ -217,11 +208,7 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
217
208
  (async () => {
218
209
  try {
219
210
  const stream = await navigator.mediaDevices.getUserMedia({ video: { width: rectWidth, height: rectHeight } });
220
- if (!isMounted) {
221
- stream.getTracks().forEach((track) => track.stop());
222
- return;
223
- }
224
- if (videoRef.current) {
211
+ if (videoRef.current && isMounted) {
225
212
  videoRef.current.srcObject = stream;
226
213
  videoRef.current.onloadedmetadata = () => {
227
214
  var _a;
@@ -255,11 +242,6 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
255
242
  ctx.drawImage(video, 0, 0, rectWidth, rectHeight, 0, 0, rectWidth * QUALITY_MULTIPLIER, rectHeight * QUALITY_MULTIPLIER);
256
243
  canvas.toBlob((blob) => {
257
244
  if (blob) {
258
- // Stop the stream immediately — don't wait for useEffect cleanup
259
- if (streamRef.current) {
260
- streamRef.current.getTracks().forEach((track) => track.stop());
261
- streamRef.current = null;
262
- }
263
245
  const file = new File([blob], "face.jpg", { type: "image/jpeg" });
264
246
  setCapturedFile(file);
265
247
  setCapturedUrl(URL.createObjectURL(blob));
@@ -7097,7 +7079,12 @@ function numberToWord(num) {
7097
7079
  function numbersToPhrase(numbers) {
7098
7080
  return numbers.map(numberToWord).join(' ');
7099
7081
  }const VIDEO_LENGTH_MS = 7000;
7100
- const useRecorder = (stream, type, onStopRecording) => {
7082
+ /**
7083
+ * Voice *enrollment* reads all ten digits aloud, which does not fit in the
7084
+ * 7s video length unhurried. Verification keeps the shorter window (BM-407).
7085
+ */
7086
+ const VOICE_ENROLL_LENGTH_MS = 10000;
7087
+ const useRecorder = (stream, type, onStopRecording, lengthMs = VIDEO_LENGTH_MS) => {
7101
7088
  const [isRecording, setIsRecording] = useState(false);
7102
7089
  const recorderRef = useRef(null);
7103
7090
  const timeoutRef = useRef(null);
@@ -7155,7 +7142,7 @@ const useRecorder = (stream, type, onStopRecording) => {
7155
7142
  // Set timeout to auto-stop recording
7156
7143
  timeoutRef.current = window.setTimeout(() => {
7157
7144
  stopRecording();
7158
- }, VIDEO_LENGTH_MS);
7145
+ }, lengthMs);
7159
7146
  }
7160
7147
  catch (error) {
7161
7148
  console.error(error);
@@ -7171,7 +7158,7 @@ const useRecorder = (stream, type, onStopRecording) => {
7171
7158
  }
7172
7159
  recorderRef.current.stopRecording(() => {
7173
7160
  const blob = recorderRef.current.getBlob();
7174
- fixWebmDuration(blob, VIDEO_LENGTH_MS, function (fixedBlob) {
7161
+ fixWebmDuration(blob, lengthMs, function (fixedBlob) {
7175
7162
  setIsRecording(false);
7176
7163
  recorderRef.current.destroy();
7177
7164
  recorderRef.current = null;
@@ -7197,13 +7184,11 @@ const useRecorder = (stream, type, onStopRecording) => {
7197
7184
  const [permission, setPermission] = useState(false);
7198
7185
  const [stream, setStream] = useState(null);
7199
7186
  const [isLoading, setIsLoading] = useState(true);
7200
- const streamRef = useRef(null);
7201
- const isMountedRef = useRef(false);
7202
7187
  const stopStreamTracks = () => {
7203
- const currentStream = streamRef.current;
7204
- if (currentStream) {
7205
- currentStream.getTracks().forEach(track => track.stop());
7206
- streamRef.current = null;
7188
+ if (stream) {
7189
+ stream.getTracks().forEach(track => {
7190
+ track.stop();
7191
+ });
7207
7192
  setStream(null);
7208
7193
  }
7209
7194
  };
@@ -7273,35 +7258,19 @@ const useRecorder = (stream, type, onStopRecording) => {
7273
7258
  const constraints = getAdaptiveConstraints();
7274
7259
  const streamData = await navigator.mediaDevices.getUserMedia(constraints);
7275
7260
  console.log('Media stream obtained, active:', streamData.active);
7276
- // If the component unmounted while getUserMedia was resolving, stop immediately
7277
- if (!isMountedRef.current) {
7278
- streamData.getTracks().forEach(track => track.stop());
7279
- return;
7280
- }
7281
- streamRef.current = streamData;
7282
7261
  setPermission(true);
7283
7262
  setStream(streamData);
7284
7263
  }
7285
7264
  catch (err) {
7286
7265
  console.error('Camera/mic permission denied:', err);
7287
- if (isMountedRef.current)
7288
- setPermission(false);
7266
+ setPermission(false);
7289
7267
  }
7290
7268
  finally {
7291
- if (isMountedRef.current)
7292
- setIsLoading(false);
7269
+ setIsLoading(false);
7293
7270
  }
7294
7271
  };
7295
7272
  useEffect(() => {
7296
- isMountedRef.current = true;
7297
7273
  void requestPermissions();
7298
- return () => {
7299
- isMountedRef.current = false;
7300
- if (streamRef.current) {
7301
- streamRef.current.getTracks().forEach(track => track.stop());
7302
- streamRef.current = null;
7303
- }
7304
- };
7305
7274
  }, [rectWidth, rectHeight]);
7306
7275
  return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
7307
7276
  };// spinner animation
@@ -7333,7 +7302,7 @@ function generateRandomDigits$1(count) {
7333
7302
  }
7334
7303
  return digits.slice(0, count);
7335
7304
  }
7336
- const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, onRecorded, className, style, noShadow = false, }) => {
7305
+ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onConfirmRecording, onRecorded, className, style, noShadow = false, }) => {
7337
7306
  const [state, setState] = useState('preparation');
7338
7307
  const [prepTimer, setPrepTimer] = useState(PREP_SECONDS$1);
7339
7308
  const [recordTimer, setRecordTimer] = useState(RECORD_SECONDS$1);
@@ -7558,7 +7527,7 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
7558
7527
  alignItems: 'center',
7559
7528
  justifyContent: 'center',
7560
7529
  width: rectWidth,
7561
- height: rectHeight + 80,
7530
+ height: rectHeight + 120,
7562
7531
  margin: '0 auto',
7563
7532
  ...style,
7564
7533
  };
@@ -7576,11 +7545,11 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
7576
7545
  };
7577
7546
  const ovalArea = {
7578
7547
  position: 'absolute',
7579
- top: '25%',
7580
- left: '20%',
7581
- // transform: 'translateX(-50%)',
7582
- width: '60%',
7583
- height: '50%',
7548
+ top: '15%',
7549
+ left: '50%',
7550
+ transform: 'translateX(-50%)',
7551
+ width: '75%',
7552
+ height: '70%',
7584
7553
  zIndex: 2,
7585
7554
  display: 'flex',
7586
7555
  flexDirection: 'column',
@@ -7611,8 +7580,8 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
7611
7580
  const numberRow = {
7612
7581
  display: 'flex',
7613
7582
  justifyContent: 'center',
7614
- gap: 5,
7615
- marginBottom: 12,
7583
+ gap: 4,
7584
+ margin: '16px 0 24px 0',
7616
7585
  width: '100%',
7617
7586
  maxWidth: rectWidth - 40,
7618
7587
  };
@@ -7732,7 +7701,7 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
7732
7701
  if (!permission) {
7733
7702
  return (jsx("div", { className: className, style: wrapperStyle, children: jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsx("h3", { children: "Camera Permission Required" }), jsx("p", { children: "Please allow camera and microphone access to use this component." }), jsx("button", { type: "button", style: actionButton, onClick: requestPermissions, children: "Grant Permissions" })] }) }));
7734
7703
  }
7735
- return (jsxs("div", { className: className, style: wrapperStyle, children: [state !== 'result' && state !== 'processing' && !isConfirming && (jsxs(Fragment, { children: [jsx("div", { className: "facerecorder-number-row", style: numberRow, children: (state === 'recording' ? digits : Array(DIGITS_NUMBER$1).fill('*')).map((num, i) => (jsx("div", { style: numberBox, children: num }, i))) }), jsxs("div", { className: "facerecorder-camera-area", style: cameraArea, children: [jsx("video", { ref: videoRef, width: rectWidth - 40, height: rectHeight - 40, className: "facerecorder-video", style: {
7704
+ return (jsxs("div", { className: className, style: wrapperStyle, children: [state !== 'result' && state !== 'processing' && !isConfirming && (jsxs(Fragment, { children: [jsxs("div", { className: "facerecorder-camera-area", style: cameraArea, children: [jsx("video", { ref: videoRef, width: rectWidth - 40, height: rectHeight - 40, className: "facerecorder-video", style: {
7736
7705
  width: rectWidth - 40,
7737
7706
  height: rectHeight - 40,
7738
7707
  objectFit: 'cover',
@@ -7748,7 +7717,7 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
7748
7717
  background: 'rgba(0,0,0,0.4)',
7749
7718
  zIndex: 1,
7750
7719
  borderRadius: noShadow ? 0 : 8,
7751
- } }), jsxs("div", { className: "facerecorder-oval-area", style: ovalArea, children: [jsx("span", { className: "facerecorder-guidance-text", style: guidanceText, children: "Place your face in the oval" }), jsx("div", { className: "facerecorder-oval-dashed", style: ovalDashed })] }), state === 'countdown' && (jsx("div", { style: prepTimerStyle, children: prepTimer })), state === 'recording' && (jsx("div", { style: timerStyle, children: recordTimer })), (state === 'recording' || state === 'preparation') && (jsxs("div", { style: soundwaveStyle, children: [jsx("div", { style: { ...barBase, height: `${8 + micLevel * 30}px` } }), jsx("div", { style: { ...barBase, height: `${4 + micLevel * 40}px` } }), jsx("div", { style: { ...barBase, height: `${10 + micLevel * 20}px` } })] }))] }), state === 'preparation' && (jsx("button", { type: "button", style: actionButton, onClick: startRecording, children: "Start recording" })), state === 'recording' && (jsx("button", { type: "button", style: { ...actionButton, background: '#d32f2f' }, onClick: handleCancel, children: "Cancel" }))] })), state === 'processing' && (jsx(Fragment, { children: jsx("div", { className: "facerecorder-processing", style: preview, children: jsxs("div", { style: {
7720
+ } }), jsxs("div", { className: "facerecorder-oval-area", style: ovalArea, children: [jsx("span", { className: "facerecorder-guidance-text", style: guidanceText, children: "Place your face in the oval" }), jsx("div", { className: "facerecorder-oval-dashed", style: ovalDashed })] }), state === 'countdown' && (jsx("div", { style: prepTimerStyle, children: prepTimer })), state === 'recording' && (jsx("div", { style: timerStyle, children: recordTimer })), (state === 'recording' || state === 'preparation') && (jsxs("div", { style: soundwaveStyle, children: [jsx("div", { style: { ...barBase, height: `${8 + micLevel * 30}px` } }), jsx("div", { style: { ...barBase, height: `${4 + micLevel * 40}px` } }), jsx("div", { style: { ...barBase, height: `${10 + micLevel * 20}px` } })] }))] }), jsx("div", { style: numberRow, children: (state === 'recording' ? digits : Array(DIGITS_NUMBER$1).fill('*')).map((num, i) => (jsx("div", { style: numberBox, children: num }, i))) }), state === 'preparation' && (jsx("button", { type: "button", style: actionButton, onClick: startRecording, children: "Start recording" })), state === 'recording' && (jsx("button", { type: "button", style: { ...actionButton, background: '#d32f2f' }, onClick: handleCancel, children: "Cancel" }))] })), state === 'processing' && (jsx(Fragment, { children: jsx("div", { className: "facerecorder-processing", style: preview, children: jsxs("div", { style: {
7752
7721
  display: 'flex',
7753
7722
  flexDirection: 'column',
7754
7723
  alignItems: 'center',
@@ -7773,13 +7742,11 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
7773
7742
  const [permission, setPermission] = useState(false);
7774
7743
  const [stream, setStream] = useState(null);
7775
7744
  const [isLoading, setIsLoading] = useState(true);
7776
- const streamRef = useRef(null);
7777
- const isMountedRef = useRef(false);
7778
7745
  const stopStreamTracks = () => {
7779
- const currentStream = streamRef.current;
7780
- if (currentStream) {
7781
- currentStream.getTracks().forEach(track => track.stop());
7782
- streamRef.current = null;
7746
+ if (stream) {
7747
+ stream.getTracks().forEach(track => {
7748
+ track.stop();
7749
+ });
7783
7750
  setStream(null);
7784
7751
  }
7785
7752
  };
@@ -7827,35 +7794,19 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
7827
7794
  setIsLoading(true);
7828
7795
  const constraints = getAudioConstraints();
7829
7796
  const streamData = await navigator.mediaDevices.getUserMedia(constraints);
7830
- // If the component unmounted while getUserMedia was resolving, stop immediately
7831
- if (!isMountedRef.current) {
7832
- streamData.getTracks().forEach(track => track.stop());
7833
- return;
7834
- }
7835
- streamRef.current = streamData;
7836
7797
  setPermission(true);
7837
7798
  setStream(streamData);
7838
7799
  }
7839
7800
  catch (err) {
7840
7801
  console.error('Microphone permission denied:', err);
7841
- if (isMountedRef.current)
7842
- setPermission(false);
7802
+ setPermission(false);
7843
7803
  }
7844
7804
  finally {
7845
- if (isMountedRef.current)
7846
- setIsLoading(false);
7805
+ setIsLoading(false);
7847
7806
  }
7848
7807
  };
7849
7808
  useEffect(() => {
7850
- isMountedRef.current = true;
7851
7809
  void requestPermissions();
7852
- return () => {
7853
- isMountedRef.current = false;
7854
- if (streamRef.current) {
7855
- streamRef.current.getTracks().forEach(track => track.stop());
7856
- streamRef.current = null;
7857
- }
7858
- };
7859
7810
  }, []);
7860
7811
  return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
7861
7812
  };// spinner animation
@@ -7871,9 +7822,14 @@ if (typeof document !== 'undefined') {
7871
7822
  style.textContent = spinnerStyle;
7872
7823
  document.head.appendChild(style);
7873
7824
  }
7874
- const RECORD_SECONDS = VIDEO_LENGTH_MS / 1000;
7825
+ const RECORD_SECONDS = VOICE_ENROLL_LENGTH_MS / 1000;
7875
7826
  const PREP_SECONDS = 3;
7876
- const DIGITS_NUMBER = 7;
7827
+ // All ten digits. Voice enrollment builds a text-prompted digit voiceprint and
7828
+ // the enrollment sample is expected to cover 0-9; verification later prompts a
7829
+ // random subset. This was 10 until 1.2.7 shortened the recording to 7s and cut
7830
+ // the prompt to match, which silently dropped three digits from every print
7831
+ // while the README kept documenting ten (BM-407).
7832
+ const DIGITS_NUMBER = 10;
7877
7833
  function generateRandomDigits(count) {
7878
7834
  const digits = Array.from({ length: 10 }, (_, i) => i);
7879
7835
  for (let i = digits.length - 1; i > 0; i--) {
@@ -7922,7 +7878,7 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onConfirmRecording, onReco
7922
7878
  setState('result');
7923
7879
  setIsConfirming(true);
7924
7880
  }
7925
- });
7881
+ }, VOICE_ENROLL_LENGTH_MS);
7926
7882
  // Audio visualization setup
7927
7883
  useEffect(() => {
7928
7884
  if (stream && state === 'recording') {
package/dist/index.js CHANGED
@@ -13,11 +13,7 @@
13
13
  (async () => {
14
14
  try {
15
15
  const stream = await navigator.mediaDevices.getUserMedia({ video: { width: rectWidth, height: rectHeight } });
16
- if (!isMounted) {
17
- stream.getTracks().forEach((track) => track.stop());
18
- return;
19
- }
20
- if (videoRef.current) {
16
+ if (videoRef.current && isMounted) {
21
17
  videoRef.current.srcObject = stream;
22
18
  videoRef.current.onloadedmetadata = () => {
23
19
  var _a;
@@ -65,11 +61,6 @@
65
61
  ctx.drawImage(video, sx, sy, sw, sh, 0, 0, canvas.width, canvas.height);
66
62
  canvas.toBlob((blob) => {
67
63
  if (blob) {
68
- // Stop the stream immediately — don't wait for useEffect cleanup
69
- if (streamRef.current) {
70
- streamRef.current.getTracks().forEach((track) => track.stop());
71
- streamRef.current = null;
72
- }
73
64
  const file = new File([blob], "document.jpg", { type: "image/jpeg" });
74
65
  setCapturedFile(file);
75
66
  setCapturedUrl(URL.createObjectURL(blob));
@@ -217,11 +208,7 @@
217
208
  (async () => {
218
209
  try {
219
210
  const stream = await navigator.mediaDevices.getUserMedia({ video: { width: rectWidth, height: rectHeight } });
220
- if (!isMounted) {
221
- stream.getTracks().forEach((track) => track.stop());
222
- return;
223
- }
224
- if (videoRef.current) {
211
+ if (videoRef.current && isMounted) {
225
212
  videoRef.current.srcObject = stream;
226
213
  videoRef.current.onloadedmetadata = () => {
227
214
  var _a;
@@ -255,11 +242,6 @@
255
242
  ctx.drawImage(video, 0, 0, rectWidth, rectHeight, 0, 0, rectWidth * QUALITY_MULTIPLIER, rectHeight * QUALITY_MULTIPLIER);
256
243
  canvas.toBlob((blob) => {
257
244
  if (blob) {
258
- // Stop the stream immediately — don't wait for useEffect cleanup
259
- if (streamRef.current) {
260
- streamRef.current.getTracks().forEach((track) => track.stop());
261
- streamRef.current = null;
262
- }
263
245
  const file = new File([blob], "face.jpg", { type: "image/jpeg" });
264
246
  setCapturedFile(file);
265
247
  setCapturedUrl(URL.createObjectURL(blob));
@@ -7097,7 +7079,12 @@ function numberToWord(num) {
7097
7079
  function numbersToPhrase(numbers) {
7098
7080
  return numbers.map(numberToWord).join(' ');
7099
7081
  }const VIDEO_LENGTH_MS = 7000;
7100
- const useRecorder = (stream, type, onStopRecording) => {
7082
+ /**
7083
+ * Voice *enrollment* reads all ten digits aloud, which does not fit in the
7084
+ * 7s video length unhurried. Verification keeps the shorter window (BM-407).
7085
+ */
7086
+ const VOICE_ENROLL_LENGTH_MS = 10000;
7087
+ const useRecorder = (stream, type, onStopRecording, lengthMs = VIDEO_LENGTH_MS) => {
7101
7088
  const [isRecording, setIsRecording] = React.useState(false);
7102
7089
  const recorderRef = React.useRef(null);
7103
7090
  const timeoutRef = React.useRef(null);
@@ -7155,7 +7142,7 @@ const useRecorder = (stream, type, onStopRecording) => {
7155
7142
  // Set timeout to auto-stop recording
7156
7143
  timeoutRef.current = window.setTimeout(() => {
7157
7144
  stopRecording();
7158
- }, VIDEO_LENGTH_MS);
7145
+ }, lengthMs);
7159
7146
  }
7160
7147
  catch (error) {
7161
7148
  console.error(error);
@@ -7171,7 +7158,7 @@ const useRecorder = (stream, type, onStopRecording) => {
7171
7158
  }
7172
7159
  recorderRef.current.stopRecording(() => {
7173
7160
  const blob = recorderRef.current.getBlob();
7174
- fixWebmDuration(blob, VIDEO_LENGTH_MS, function (fixedBlob) {
7161
+ fixWebmDuration(blob, lengthMs, function (fixedBlob) {
7175
7162
  setIsRecording(false);
7176
7163
  recorderRef.current.destroy();
7177
7164
  recorderRef.current = null;
@@ -7197,13 +7184,11 @@ const useRecorder = (stream, type, onStopRecording) => {
7197
7184
  const [permission, setPermission] = React.useState(false);
7198
7185
  const [stream, setStream] = React.useState(null);
7199
7186
  const [isLoading, setIsLoading] = React.useState(true);
7200
- const streamRef = React.useRef(null);
7201
- const isMountedRef = React.useRef(false);
7202
7187
  const stopStreamTracks = () => {
7203
- const currentStream = streamRef.current;
7204
- if (currentStream) {
7205
- currentStream.getTracks().forEach(track => track.stop());
7206
- streamRef.current = null;
7188
+ if (stream) {
7189
+ stream.getTracks().forEach(track => {
7190
+ track.stop();
7191
+ });
7207
7192
  setStream(null);
7208
7193
  }
7209
7194
  };
@@ -7273,35 +7258,19 @@ const useRecorder = (stream, type, onStopRecording) => {
7273
7258
  const constraints = getAdaptiveConstraints();
7274
7259
  const streamData = await navigator.mediaDevices.getUserMedia(constraints);
7275
7260
  console.log('Media stream obtained, active:', streamData.active);
7276
- // If the component unmounted while getUserMedia was resolving, stop immediately
7277
- if (!isMountedRef.current) {
7278
- streamData.getTracks().forEach(track => track.stop());
7279
- return;
7280
- }
7281
- streamRef.current = streamData;
7282
7261
  setPermission(true);
7283
7262
  setStream(streamData);
7284
7263
  }
7285
7264
  catch (err) {
7286
7265
  console.error('Camera/mic permission denied:', err);
7287
- if (isMountedRef.current)
7288
- setPermission(false);
7266
+ setPermission(false);
7289
7267
  }
7290
7268
  finally {
7291
- if (isMountedRef.current)
7292
- setIsLoading(false);
7269
+ setIsLoading(false);
7293
7270
  }
7294
7271
  };
7295
7272
  React.useEffect(() => {
7296
- isMountedRef.current = true;
7297
7273
  void requestPermissions();
7298
- return () => {
7299
- isMountedRef.current = false;
7300
- if (streamRef.current) {
7301
- streamRef.current.getTracks().forEach(track => track.stop());
7302
- streamRef.current = null;
7303
- }
7304
- };
7305
7274
  }, [rectWidth, rectHeight]);
7306
7275
  return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
7307
7276
  };// spinner animation
@@ -7333,7 +7302,7 @@ function generateRandomDigits$1(count) {
7333
7302
  }
7334
7303
  return digits.slice(0, count);
7335
7304
  }
7336
- const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, onRecorded, className, style, noShadow = false, }) => {
7305
+ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onConfirmRecording, onRecorded, className, style, noShadow = false, }) => {
7337
7306
  const [state, setState] = React.useState('preparation');
7338
7307
  const [prepTimer, setPrepTimer] = React.useState(PREP_SECONDS$1);
7339
7308
  const [recordTimer, setRecordTimer] = React.useState(RECORD_SECONDS$1);
@@ -7558,7 +7527,7 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
7558
7527
  alignItems: 'center',
7559
7528
  justifyContent: 'center',
7560
7529
  width: rectWidth,
7561
- height: rectHeight + 80,
7530
+ height: rectHeight + 120,
7562
7531
  margin: '0 auto',
7563
7532
  ...style,
7564
7533
  };
@@ -7576,11 +7545,11 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
7576
7545
  };
7577
7546
  const ovalArea = {
7578
7547
  position: 'absolute',
7579
- top: '25%',
7580
- left: '20%',
7581
- // transform: 'translateX(-50%)',
7582
- width: '60%',
7583
- height: '50%',
7548
+ top: '15%',
7549
+ left: '50%',
7550
+ transform: 'translateX(-50%)',
7551
+ width: '75%',
7552
+ height: '70%',
7584
7553
  zIndex: 2,
7585
7554
  display: 'flex',
7586
7555
  flexDirection: 'column',
@@ -7611,8 +7580,8 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
7611
7580
  const numberRow = {
7612
7581
  display: 'flex',
7613
7582
  justifyContent: 'center',
7614
- gap: 5,
7615
- marginBottom: 12,
7583
+ gap: 4,
7584
+ margin: '16px 0 24px 0',
7616
7585
  width: '100%',
7617
7586
  maxWidth: rectWidth - 40,
7618
7587
  };
@@ -7732,7 +7701,7 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
7732
7701
  if (!permission) {
7733
7702
  return (jsxRuntime.jsx("div", { className: className, style: wrapperStyle, children: jsxRuntime.jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsxRuntime.jsx("h3", { children: "Camera Permission Required" }), jsxRuntime.jsx("p", { children: "Please allow camera and microphone access to use this component." }), jsxRuntime.jsx("button", { type: "button", style: actionButton, onClick: requestPermissions, children: "Grant Permissions" })] }) }));
7734
7703
  }
7735
- return (jsxRuntime.jsxs("div", { className: className, style: wrapperStyle, children: [state !== 'result' && state !== 'processing' && !isConfirming && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: "facerecorder-number-row", style: numberRow, children: (state === 'recording' ? digits : Array(DIGITS_NUMBER$1).fill('*')).map((num, i) => (jsxRuntime.jsx("div", { style: numberBox, children: num }, i))) }), jsxRuntime.jsxs("div", { className: "facerecorder-camera-area", style: cameraArea, children: [jsxRuntime.jsx("video", { ref: videoRef, width: rectWidth - 40, height: rectHeight - 40, className: "facerecorder-video", style: {
7704
+ return (jsxRuntime.jsxs("div", { className: className, style: wrapperStyle, children: [state !== 'result' && state !== 'processing' && !isConfirming && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: "facerecorder-camera-area", style: cameraArea, children: [jsxRuntime.jsx("video", { ref: videoRef, width: rectWidth - 40, height: rectHeight - 40, className: "facerecorder-video", style: {
7736
7705
  width: rectWidth - 40,
7737
7706
  height: rectHeight - 40,
7738
7707
  objectFit: 'cover',
@@ -7748,7 +7717,7 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
7748
7717
  background: 'rgba(0,0,0,0.4)',
7749
7718
  zIndex: 1,
7750
7719
  borderRadius: noShadow ? 0 : 8,
7751
- } }), jsxRuntime.jsxs("div", { className: "facerecorder-oval-area", style: ovalArea, children: [jsxRuntime.jsx("span", { className: "facerecorder-guidance-text", style: guidanceText, children: "Place your face in the oval" }), jsxRuntime.jsx("div", { className: "facerecorder-oval-dashed", style: ovalDashed })] }), state === 'countdown' && (jsxRuntime.jsx("div", { style: prepTimerStyle, children: prepTimer })), state === 'recording' && (jsxRuntime.jsx("div", { style: timerStyle, children: recordTimer })), (state === 'recording' || state === 'preparation') && (jsxRuntime.jsxs("div", { style: soundwaveStyle, children: [jsxRuntime.jsx("div", { style: { ...barBase, height: `${8 + micLevel * 30}px` } }), jsxRuntime.jsx("div", { style: { ...barBase, height: `${4 + micLevel * 40}px` } }), jsxRuntime.jsx("div", { style: { ...barBase, height: `${10 + micLevel * 20}px` } })] }))] }), state === 'preparation' && (jsxRuntime.jsx("button", { type: "button", style: actionButton, onClick: startRecording, children: "Start recording" })), state === 'recording' && (jsxRuntime.jsx("button", { type: "button", style: { ...actionButton, background: '#d32f2f' }, onClick: handleCancel, children: "Cancel" }))] })), state === 'processing' && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("div", { className: "facerecorder-processing", style: preview, children: jsxRuntime.jsxs("div", { style: {
7720
+ } }), jsxRuntime.jsxs("div", { className: "facerecorder-oval-area", style: ovalArea, children: [jsxRuntime.jsx("span", { className: "facerecorder-guidance-text", style: guidanceText, children: "Place your face in the oval" }), jsxRuntime.jsx("div", { className: "facerecorder-oval-dashed", style: ovalDashed })] }), state === 'countdown' && (jsxRuntime.jsx("div", { style: prepTimerStyle, children: prepTimer })), state === 'recording' && (jsxRuntime.jsx("div", { style: timerStyle, children: recordTimer })), (state === 'recording' || state === 'preparation') && (jsxRuntime.jsxs("div", { style: soundwaveStyle, children: [jsxRuntime.jsx("div", { style: { ...barBase, height: `${8 + micLevel * 30}px` } }), jsxRuntime.jsx("div", { style: { ...barBase, height: `${4 + micLevel * 40}px` } }), jsxRuntime.jsx("div", { style: { ...barBase, height: `${10 + micLevel * 20}px` } })] }))] }), jsxRuntime.jsx("div", { style: numberRow, children: (state === 'recording' ? digits : Array(DIGITS_NUMBER$1).fill('*')).map((num, i) => (jsxRuntime.jsx("div", { style: numberBox, children: num }, i))) }), state === 'preparation' && (jsxRuntime.jsx("button", { type: "button", style: actionButton, onClick: startRecording, children: "Start recording" })), state === 'recording' && (jsxRuntime.jsx("button", { type: "button", style: { ...actionButton, background: '#d32f2f' }, onClick: handleCancel, children: "Cancel" }))] })), state === 'processing' && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("div", { className: "facerecorder-processing", style: preview, children: jsxRuntime.jsxs("div", { style: {
7752
7721
  display: 'flex',
7753
7722
  flexDirection: 'column',
7754
7723
  alignItems: 'center',
@@ -7773,13 +7742,11 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
7773
7742
  const [permission, setPermission] = React.useState(false);
7774
7743
  const [stream, setStream] = React.useState(null);
7775
7744
  const [isLoading, setIsLoading] = React.useState(true);
7776
- const streamRef = React.useRef(null);
7777
- const isMountedRef = React.useRef(false);
7778
7745
  const stopStreamTracks = () => {
7779
- const currentStream = streamRef.current;
7780
- if (currentStream) {
7781
- currentStream.getTracks().forEach(track => track.stop());
7782
- streamRef.current = null;
7746
+ if (stream) {
7747
+ stream.getTracks().forEach(track => {
7748
+ track.stop();
7749
+ });
7783
7750
  setStream(null);
7784
7751
  }
7785
7752
  };
@@ -7827,35 +7794,19 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
7827
7794
  setIsLoading(true);
7828
7795
  const constraints = getAudioConstraints();
7829
7796
  const streamData = await navigator.mediaDevices.getUserMedia(constraints);
7830
- // If the component unmounted while getUserMedia was resolving, stop immediately
7831
- if (!isMountedRef.current) {
7832
- streamData.getTracks().forEach(track => track.stop());
7833
- return;
7834
- }
7835
- streamRef.current = streamData;
7836
7797
  setPermission(true);
7837
7798
  setStream(streamData);
7838
7799
  }
7839
7800
  catch (err) {
7840
7801
  console.error('Microphone permission denied:', err);
7841
- if (isMountedRef.current)
7842
- setPermission(false);
7802
+ setPermission(false);
7843
7803
  }
7844
7804
  finally {
7845
- if (isMountedRef.current)
7846
- setIsLoading(false);
7805
+ setIsLoading(false);
7847
7806
  }
7848
7807
  };
7849
7808
  React.useEffect(() => {
7850
- isMountedRef.current = true;
7851
7809
  void requestPermissions();
7852
- return () => {
7853
- isMountedRef.current = false;
7854
- if (streamRef.current) {
7855
- streamRef.current.getTracks().forEach(track => track.stop());
7856
- streamRef.current = null;
7857
- }
7858
- };
7859
7810
  }, []);
7860
7811
  return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
7861
7812
  };// spinner animation
@@ -7871,9 +7822,14 @@ if (typeof document !== 'undefined') {
7871
7822
  style.textContent = spinnerStyle;
7872
7823
  document.head.appendChild(style);
7873
7824
  }
7874
- const RECORD_SECONDS = VIDEO_LENGTH_MS / 1000;
7825
+ const RECORD_SECONDS = VOICE_ENROLL_LENGTH_MS / 1000;
7875
7826
  const PREP_SECONDS = 3;
7876
- const DIGITS_NUMBER = 7;
7827
+ // All ten digits. Voice enrollment builds a text-prompted digit voiceprint and
7828
+ // the enrollment sample is expected to cover 0-9; verification later prompts a
7829
+ // random subset. This was 10 until 1.2.7 shortened the recording to 7s and cut
7830
+ // the prompt to match, which silently dropped three digits from every print
7831
+ // while the README kept documenting ten (BM-407).
7832
+ const DIGITS_NUMBER = 10;
7877
7833
  function generateRandomDigits(count) {
7878
7834
  const digits = Array.from({ length: 10 }, (_, i) => i);
7879
7835
  for (let i = digits.length - 1; i > 0; i--) {
@@ -7922,7 +7878,7 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onConfirmRecording, onReco
7922
7878
  setState('result');
7923
7879
  setIsConfirming(true);
7924
7880
  }
7925
- });
7881
+ }, VOICE_ENROLL_LENGTH_MS);
7926
7882
  // Audio visualization setup
7927
7883
  React.useEffect(() => {
7928
7884
  if (stream && state === 'recording') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "biometry-react-components",
3
- "version": "1.3.4",
3
+ "version": "1.4.0",
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",
@@ -13,7 +13,6 @@
13
13
  "build": "rollup -c",
14
14
  "build:types": "rollup -c rollup.config.dts.js",
15
15
  "build:clean": "rm -rf dist && npm run build && npm run build:types",
16
- "watch": "rollup -c --watch",
17
16
  "test": "echo \"Error: no test specified\" && exit 1",
18
17
  "prepublishOnly": "npm run build:clean"
19
18
  },
@@ -31,15 +30,23 @@
31
30
  ],
32
31
  "author": "Biometry Team",
33
32
  "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/your-username/biometry-react-components.git"
36
+ },
37
+ "bugs": {
38
+ "url": "https://github.com/your-username/biometry-react-components/issues"
39
+ },
40
+ "homepage": "https://github.com/your-username/biometry-react-components#readme",
34
41
  "devDependencies": {
35
42
  "@rollup/plugin-commonjs": "^28.0.6",
36
43
  "@rollup/plugin-node-resolve": "^16.0.1",
37
44
  "@rollup/plugin-typescript": "^12.1.4",
38
- "@types/react": "^18.3.1",
39
- "@types/react-dom": "^18.3.1",
45
+ "@types/react": "^19.1.8",
46
+ "@types/react-dom": "^19.1.6",
40
47
  "@types/recordrtc": "^5.6.14",
41
- "react": "^18.3.1",
42
- "react-dom": "^18.3.1",
48
+ "react": "^19.1.0",
49
+ "react-dom": "^19.1.0",
43
50
  "rollup": "^4.45.1",
44
51
  "rollup-plugin-dts": "^6.2.1",
45
52
  "rollup-plugin-peer-deps-external": "^2.2.4",
@@ -55,4 +62,4 @@
55
62
  "recordrtc": "^5.6.2",
56
63
  "tslib": "^2.8.1"
57
64
  }
58
- }
65
+ }