biometry-react-components 1.3.2 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -13,7 +13,11 @@ 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 (videoRef.current && isMounted) {
16
+ if (!isMounted) {
17
+ stream.getTracks().forEach((track) => track.stop());
18
+ return;
19
+ }
20
+ if (videoRef.current) {
17
21
  videoRef.current.srcObject = stream;
18
22
  videoRef.current.onloadedmetadata = () => {
19
23
  var _a;
@@ -61,6 +65,11 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
61
65
  ctx.drawImage(video, sx, sy, sw, sh, 0, 0, canvas.width, canvas.height);
62
66
  canvas.toBlob((blob) => {
63
67
  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
+ }
64
73
  const file = new File([blob], "document.jpg", { type: "image/jpeg" });
65
74
  setCapturedFile(file);
66
75
  setCapturedUrl(URL.createObjectURL(blob));
@@ -208,7 +217,11 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
208
217
  (async () => {
209
218
  try {
210
219
  const stream = await navigator.mediaDevices.getUserMedia({ video: { width: rectWidth, height: rectHeight } });
211
- if (videoRef.current && isMounted) {
220
+ if (!isMounted) {
221
+ stream.getTracks().forEach((track) => track.stop());
222
+ return;
223
+ }
224
+ if (videoRef.current) {
212
225
  videoRef.current.srcObject = stream;
213
226
  videoRef.current.onloadedmetadata = () => {
214
227
  var _a;
@@ -242,6 +255,11 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
242
255
  ctx.drawImage(video, 0, 0, rectWidth, rectHeight, 0, 0, rectWidth * QUALITY_MULTIPLIER, rectHeight * QUALITY_MULTIPLIER);
243
256
  canvas.toBlob((blob) => {
244
257
  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
+ }
245
263
  const file = new File([blob], "face.jpg", { type: "image/jpeg" });
246
264
  setCapturedFile(file);
247
265
  setCapturedUrl(URL.createObjectURL(blob));
@@ -7179,11 +7197,13 @@ const useRecorder = (stream, type, onStopRecording) => {
7179
7197
  const [permission, setPermission] = useState(false);
7180
7198
  const [stream, setStream] = useState(null);
7181
7199
  const [isLoading, setIsLoading] = useState(true);
7200
+ const streamRef = useRef(null);
7201
+ const isMountedRef = useRef(false);
7182
7202
  const stopStreamTracks = () => {
7183
- if (stream) {
7184
- stream.getTracks().forEach(track => {
7185
- track.stop();
7186
- });
7203
+ const currentStream = streamRef.current;
7204
+ if (currentStream) {
7205
+ currentStream.getTracks().forEach(track => track.stop());
7206
+ streamRef.current = null;
7187
7207
  setStream(null);
7188
7208
  }
7189
7209
  };
@@ -7253,19 +7273,35 @@ const useRecorder = (stream, type, onStopRecording) => {
7253
7273
  const constraints = getAdaptiveConstraints();
7254
7274
  const streamData = await navigator.mediaDevices.getUserMedia(constraints);
7255
7275
  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;
7256
7282
  setPermission(true);
7257
7283
  setStream(streamData);
7258
7284
  }
7259
7285
  catch (err) {
7260
7286
  console.error('Camera/mic permission denied:', err);
7261
- setPermission(false);
7287
+ if (isMountedRef.current)
7288
+ setPermission(false);
7262
7289
  }
7263
7290
  finally {
7264
- setIsLoading(false);
7291
+ if (isMountedRef.current)
7292
+ setIsLoading(false);
7265
7293
  }
7266
7294
  };
7267
7295
  useEffect(() => {
7296
+ isMountedRef.current = true;
7268
7297
  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
+ };
7269
7305
  }, [rectWidth, rectHeight]);
7270
7306
  return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
7271
7307
  };// spinner animation
@@ -7297,7 +7333,7 @@ function generateRandomDigits$1(count) {
7297
7333
  }
7298
7334
  return digits.slice(0, count);
7299
7335
  }
7300
- const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, onRecorded, className, style, noShadow = false, }) => {
7336
+ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, onRecorded, className, style, noShadow = false, }) => {
7301
7337
  const [state, setState] = useState('preparation');
7302
7338
  const [prepTimer, setPrepTimer] = useState(PREP_SECONDS$1);
7303
7339
  const [recordTimer, setRecordTimer] = useState(RECORD_SECONDS$1);
@@ -7522,7 +7558,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, o
7522
7558
  alignItems: 'center',
7523
7559
  justifyContent: 'center',
7524
7560
  width: rectWidth,
7525
- height: rectHeight + 100,
7561
+ height: rectHeight + 80,
7526
7562
  margin: '0 auto',
7527
7563
  ...style,
7528
7564
  };
@@ -7540,11 +7576,11 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, o
7540
7576
  };
7541
7577
  const ovalArea = {
7542
7578
  position: 'absolute',
7543
- top: '15%',
7544
- left: '50%',
7545
- transform: 'translateX(-50%)',
7546
- width: '75%',
7547
- height: '70%',
7579
+ top: '25%',
7580
+ left: '20%',
7581
+ // transform: 'translateX(-50%)',
7582
+ width: '60%',
7583
+ height: '50%',
7548
7584
  zIndex: 2,
7549
7585
  display: 'flex',
7550
7586
  flexDirection: 'column',
@@ -7737,11 +7773,13 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, o
7737
7773
  const [permission, setPermission] = useState(false);
7738
7774
  const [stream, setStream] = useState(null);
7739
7775
  const [isLoading, setIsLoading] = useState(true);
7776
+ const streamRef = useRef(null);
7777
+ const isMountedRef = useRef(false);
7740
7778
  const stopStreamTracks = () => {
7741
- if (stream) {
7742
- stream.getTracks().forEach(track => {
7743
- track.stop();
7744
- });
7779
+ const currentStream = streamRef.current;
7780
+ if (currentStream) {
7781
+ currentStream.getTracks().forEach(track => track.stop());
7782
+ streamRef.current = null;
7745
7783
  setStream(null);
7746
7784
  }
7747
7785
  };
@@ -7789,19 +7827,35 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, o
7789
7827
  setIsLoading(true);
7790
7828
  const constraints = getAudioConstraints();
7791
7829
  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;
7792
7836
  setPermission(true);
7793
7837
  setStream(streamData);
7794
7838
  }
7795
7839
  catch (err) {
7796
7840
  console.error('Microphone permission denied:', err);
7797
- setPermission(false);
7841
+ if (isMountedRef.current)
7842
+ setPermission(false);
7798
7843
  }
7799
7844
  finally {
7800
- setIsLoading(false);
7845
+ if (isMountedRef.current)
7846
+ setIsLoading(false);
7801
7847
  }
7802
7848
  };
7803
7849
  useEffect(() => {
7850
+ isMountedRef.current = true;
7804
7851
  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
+ };
7805
7859
  }, []);
7806
7860
  return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
7807
7861
  };// spinner animation
package/dist/index.js CHANGED
@@ -13,7 +13,11 @@
13
13
  (async () => {
14
14
  try {
15
15
  const stream = await navigator.mediaDevices.getUserMedia({ video: { width: rectWidth, height: rectHeight } });
16
- if (videoRef.current && isMounted) {
16
+ if (!isMounted) {
17
+ stream.getTracks().forEach((track) => track.stop());
18
+ return;
19
+ }
20
+ if (videoRef.current) {
17
21
  videoRef.current.srcObject = stream;
18
22
  videoRef.current.onloadedmetadata = () => {
19
23
  var _a;
@@ -61,6 +65,11 @@
61
65
  ctx.drawImage(video, sx, sy, sw, sh, 0, 0, canvas.width, canvas.height);
62
66
  canvas.toBlob((blob) => {
63
67
  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
+ }
64
73
  const file = new File([blob], "document.jpg", { type: "image/jpeg" });
65
74
  setCapturedFile(file);
66
75
  setCapturedUrl(URL.createObjectURL(blob));
@@ -208,7 +217,11 @@
208
217
  (async () => {
209
218
  try {
210
219
  const stream = await navigator.mediaDevices.getUserMedia({ video: { width: rectWidth, height: rectHeight } });
211
- if (videoRef.current && isMounted) {
220
+ if (!isMounted) {
221
+ stream.getTracks().forEach((track) => track.stop());
222
+ return;
223
+ }
224
+ if (videoRef.current) {
212
225
  videoRef.current.srcObject = stream;
213
226
  videoRef.current.onloadedmetadata = () => {
214
227
  var _a;
@@ -242,6 +255,11 @@
242
255
  ctx.drawImage(video, 0, 0, rectWidth, rectHeight, 0, 0, rectWidth * QUALITY_MULTIPLIER, rectHeight * QUALITY_MULTIPLIER);
243
256
  canvas.toBlob((blob) => {
244
257
  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
+ }
245
263
  const file = new File([blob], "face.jpg", { type: "image/jpeg" });
246
264
  setCapturedFile(file);
247
265
  setCapturedUrl(URL.createObjectURL(blob));
@@ -7179,11 +7197,13 @@ const useRecorder = (stream, type, onStopRecording) => {
7179
7197
  const [permission, setPermission] = React.useState(false);
7180
7198
  const [stream, setStream] = React.useState(null);
7181
7199
  const [isLoading, setIsLoading] = React.useState(true);
7200
+ const streamRef = React.useRef(null);
7201
+ const isMountedRef = React.useRef(false);
7182
7202
  const stopStreamTracks = () => {
7183
- if (stream) {
7184
- stream.getTracks().forEach(track => {
7185
- track.stop();
7186
- });
7203
+ const currentStream = streamRef.current;
7204
+ if (currentStream) {
7205
+ currentStream.getTracks().forEach(track => track.stop());
7206
+ streamRef.current = null;
7187
7207
  setStream(null);
7188
7208
  }
7189
7209
  };
@@ -7253,19 +7273,35 @@ const useRecorder = (stream, type, onStopRecording) => {
7253
7273
  const constraints = getAdaptiveConstraints();
7254
7274
  const streamData = await navigator.mediaDevices.getUserMedia(constraints);
7255
7275
  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;
7256
7282
  setPermission(true);
7257
7283
  setStream(streamData);
7258
7284
  }
7259
7285
  catch (err) {
7260
7286
  console.error('Camera/mic permission denied:', err);
7261
- setPermission(false);
7287
+ if (isMountedRef.current)
7288
+ setPermission(false);
7262
7289
  }
7263
7290
  finally {
7264
- setIsLoading(false);
7291
+ if (isMountedRef.current)
7292
+ setIsLoading(false);
7265
7293
  }
7266
7294
  };
7267
7295
  React.useEffect(() => {
7296
+ isMountedRef.current = true;
7268
7297
  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
+ };
7269
7305
  }, [rectWidth, rectHeight]);
7270
7306
  return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
7271
7307
  };// spinner animation
@@ -7297,7 +7333,7 @@ function generateRandomDigits$1(count) {
7297
7333
  }
7298
7334
  return digits.slice(0, count);
7299
7335
  }
7300
- const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, onRecorded, className, style, noShadow = false, }) => {
7336
+ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, onRecorded, className, style, noShadow = false, }) => {
7301
7337
  const [state, setState] = React.useState('preparation');
7302
7338
  const [prepTimer, setPrepTimer] = React.useState(PREP_SECONDS$1);
7303
7339
  const [recordTimer, setRecordTimer] = React.useState(RECORD_SECONDS$1);
@@ -7522,7 +7558,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, o
7522
7558
  alignItems: 'center',
7523
7559
  justifyContent: 'center',
7524
7560
  width: rectWidth,
7525
- height: rectHeight + 100,
7561
+ height: rectHeight + 80,
7526
7562
  margin: '0 auto',
7527
7563
  ...style,
7528
7564
  };
@@ -7540,11 +7576,11 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, o
7540
7576
  };
7541
7577
  const ovalArea = {
7542
7578
  position: 'absolute',
7543
- top: '15%',
7544
- left: '50%',
7545
- transform: 'translateX(-50%)',
7546
- width: '75%',
7547
- height: '70%',
7579
+ top: '25%',
7580
+ left: '20%',
7581
+ // transform: 'translateX(-50%)',
7582
+ width: '60%',
7583
+ height: '50%',
7548
7584
  zIndex: 2,
7549
7585
  display: 'flex',
7550
7586
  flexDirection: 'column',
@@ -7737,11 +7773,13 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, o
7737
7773
  const [permission, setPermission] = React.useState(false);
7738
7774
  const [stream, setStream] = React.useState(null);
7739
7775
  const [isLoading, setIsLoading] = React.useState(true);
7776
+ const streamRef = React.useRef(null);
7777
+ const isMountedRef = React.useRef(false);
7740
7778
  const stopStreamTracks = () => {
7741
- if (stream) {
7742
- stream.getTracks().forEach(track => {
7743
- track.stop();
7744
- });
7779
+ const currentStream = streamRef.current;
7780
+ if (currentStream) {
7781
+ currentStream.getTracks().forEach(track => track.stop());
7782
+ streamRef.current = null;
7745
7783
  setStream(null);
7746
7784
  }
7747
7785
  };
@@ -7789,19 +7827,35 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, o
7789
7827
  setIsLoading(true);
7790
7828
  const constraints = getAudioConstraints();
7791
7829
  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;
7792
7836
  setPermission(true);
7793
7837
  setStream(streamData);
7794
7838
  }
7795
7839
  catch (err) {
7796
7840
  console.error('Microphone permission denied:', err);
7797
- setPermission(false);
7841
+ if (isMountedRef.current)
7842
+ setPermission(false);
7798
7843
  }
7799
7844
  finally {
7800
- setIsLoading(false);
7845
+ if (isMountedRef.current)
7846
+ setIsLoading(false);
7801
7847
  }
7802
7848
  };
7803
7849
  React.useEffect(() => {
7850
+ isMountedRef.current = true;
7804
7851
  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
+ };
7805
7859
  }, []);
7806
7860
  return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
7807
7861
  };// spinner animation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "biometry-react-components",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
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,6 +13,7 @@
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",
16
17
  "test": "echo \"Error: no test specified\" && exit 1",
17
18
  "prepublishOnly": "npm run build:clean"
18
19
  },
@@ -30,23 +31,15 @@
30
31
  ],
31
32
  "author": "Biometry Team",
32
33
  "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",
41
34
  "devDependencies": {
42
35
  "@rollup/plugin-commonjs": "^28.0.6",
43
36
  "@rollup/plugin-node-resolve": "^16.0.1",
44
37
  "@rollup/plugin-typescript": "^12.1.4",
45
- "@types/react": "^19.1.8",
46
- "@types/react-dom": "^19.1.6",
38
+ "@types/react": "^18.3.1",
39
+ "@types/react-dom": "^18.3.1",
47
40
  "@types/recordrtc": "^5.6.14",
48
- "react": "^19.1.0",
49
- "react-dom": "^19.1.0",
41
+ "react": "^18.3.1",
42
+ "react-dom": "^18.3.1",
50
43
  "rollup": "^4.45.1",
51
44
  "rollup-plugin-dts": "^6.2.1",
52
45
  "rollup-plugin-peer-deps-external": "^2.2.4",