biometry-react-components 1.3.3 → 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 +79 -25
- package/dist/index.js +79 -25
- package/package.json +6 -13
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 (
|
|
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 (
|
|
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
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
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
|
-
|
|
7287
|
+
if (isMountedRef.current)
|
|
7288
|
+
setPermission(false);
|
|
7262
7289
|
}
|
|
7263
7290
|
finally {
|
|
7264
|
-
|
|
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
|
|
@@ -7289,7 +7325,6 @@ if (typeof window !== 'undefined' && typeof console !== 'undefined') {
|
|
|
7289
7325
|
const RECORD_SECONDS$1 = VIDEO_LENGTH_MS / 1000;
|
|
7290
7326
|
const PREP_SECONDS$1 = 3;
|
|
7291
7327
|
const DIGITS_NUMBER$1 = 7;
|
|
7292
|
-
const VIDEO_DISPLAY_HEIGHT = 536; // fixed height for consistent zoom regardless of container size
|
|
7293
7328
|
function generateRandomDigits$1(count) {
|
|
7294
7329
|
const digits = Array.from({ length: 10 }, (_, i) => i);
|
|
7295
7330
|
for (let i = digits.length - 1; i > 0; i--) {
|
|
@@ -7298,7 +7333,7 @@ function generateRandomDigits$1(count) {
|
|
|
7298
7333
|
}
|
|
7299
7334
|
return digits.slice(0, count);
|
|
7300
7335
|
}
|
|
7301
|
-
const FaceRecorder = ({ rectWidth =
|
|
7336
|
+
const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, onRecorded, className, style, noShadow = false, }) => {
|
|
7302
7337
|
const [state, setState] = useState('preparation');
|
|
7303
7338
|
const [prepTimer, setPrepTimer] = useState(PREP_SECONDS$1);
|
|
7304
7339
|
const [recordTimer, setRecordTimer] = useState(RECORD_SECONDS$1);
|
|
@@ -7523,7 +7558,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, o
|
|
|
7523
7558
|
alignItems: 'center',
|
|
7524
7559
|
justifyContent: 'center',
|
|
7525
7560
|
width: rectWidth,
|
|
7526
|
-
height: rectHeight +
|
|
7561
|
+
height: rectHeight + 80,
|
|
7527
7562
|
margin: '0 auto',
|
|
7528
7563
|
...style,
|
|
7529
7564
|
};
|
|
@@ -7541,11 +7576,11 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, o
|
|
|
7541
7576
|
};
|
|
7542
7577
|
const ovalArea = {
|
|
7543
7578
|
position: 'absolute',
|
|
7544
|
-
top: '
|
|
7545
|
-
left: '
|
|
7546
|
-
transform: 'translateX(-50%)',
|
|
7547
|
-
width: '
|
|
7548
|
-
height: '
|
|
7579
|
+
top: '25%',
|
|
7580
|
+
left: '20%',
|
|
7581
|
+
// transform: 'translateX(-50%)',
|
|
7582
|
+
width: '60%',
|
|
7583
|
+
height: '50%',
|
|
7549
7584
|
zIndex: 2,
|
|
7550
7585
|
display: 'flex',
|
|
7551
7586
|
flexDirection: 'column',
|
|
@@ -7697,12 +7732,13 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, o
|
|
|
7697
7732
|
if (!permission) {
|
|
7698
7733
|
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" })] }) }));
|
|
7699
7734
|
}
|
|
7700
|
-
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:
|
|
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: {
|
|
7701
7736
|
width: rectWidth - 40,
|
|
7702
|
-
height:
|
|
7737
|
+
height: rectHeight - 40,
|
|
7703
7738
|
objectFit: 'cover',
|
|
7739
|
+
borderRadius: noShadow ? 0 : 8,
|
|
7704
7740
|
zIndex: 0,
|
|
7705
|
-
transform: 'scaleX(-1)'
|
|
7741
|
+
transform: 'scaleX(-1)'
|
|
7706
7742
|
}, playsInline: true, muted: true, autoPlay: true }), jsx("div", { className: "facerecorder-dark-overlay", style: {
|
|
7707
7743
|
position: 'absolute',
|
|
7708
7744
|
top: 0,
|
|
@@ -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
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
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
|
-
|
|
7841
|
+
if (isMountedRef.current)
|
|
7842
|
+
setPermission(false);
|
|
7798
7843
|
}
|
|
7799
7844
|
finally {
|
|
7800
|
-
|
|
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 (
|
|
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 (
|
|
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
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
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
|
-
|
|
7287
|
+
if (isMountedRef.current)
|
|
7288
|
+
setPermission(false);
|
|
7262
7289
|
}
|
|
7263
7290
|
finally {
|
|
7264
|
-
|
|
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
|
|
@@ -7289,7 +7325,6 @@ if (typeof window !== 'undefined' && typeof console !== 'undefined') {
|
|
|
7289
7325
|
const RECORD_SECONDS$1 = VIDEO_LENGTH_MS / 1000;
|
|
7290
7326
|
const PREP_SECONDS$1 = 3;
|
|
7291
7327
|
const DIGITS_NUMBER$1 = 7;
|
|
7292
|
-
const VIDEO_DISPLAY_HEIGHT = 536; // fixed height for consistent zoom regardless of container size
|
|
7293
7328
|
function generateRandomDigits$1(count) {
|
|
7294
7329
|
const digits = Array.from({ length: 10 }, (_, i) => i);
|
|
7295
7330
|
for (let i = digits.length - 1; i > 0; i--) {
|
|
@@ -7298,7 +7333,7 @@ function generateRandomDigits$1(count) {
|
|
|
7298
7333
|
}
|
|
7299
7334
|
return digits.slice(0, count);
|
|
7300
7335
|
}
|
|
7301
|
-
const FaceRecorder = ({ rectWidth =
|
|
7336
|
+
const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, onRecorded, className, style, noShadow = false, }) => {
|
|
7302
7337
|
const [state, setState] = React.useState('preparation');
|
|
7303
7338
|
const [prepTimer, setPrepTimer] = React.useState(PREP_SECONDS$1);
|
|
7304
7339
|
const [recordTimer, setRecordTimer] = React.useState(RECORD_SECONDS$1);
|
|
@@ -7523,7 +7558,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, o
|
|
|
7523
7558
|
alignItems: 'center',
|
|
7524
7559
|
justifyContent: 'center',
|
|
7525
7560
|
width: rectWidth,
|
|
7526
|
-
height: rectHeight +
|
|
7561
|
+
height: rectHeight + 80,
|
|
7527
7562
|
margin: '0 auto',
|
|
7528
7563
|
...style,
|
|
7529
7564
|
};
|
|
@@ -7541,11 +7576,11 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, o
|
|
|
7541
7576
|
};
|
|
7542
7577
|
const ovalArea = {
|
|
7543
7578
|
position: 'absolute',
|
|
7544
|
-
top: '
|
|
7545
|
-
left: '
|
|
7546
|
-
transform: 'translateX(-50%)',
|
|
7547
|
-
width: '
|
|
7548
|
-
height: '
|
|
7579
|
+
top: '25%',
|
|
7580
|
+
left: '20%',
|
|
7581
|
+
// transform: 'translateX(-50%)',
|
|
7582
|
+
width: '60%',
|
|
7583
|
+
height: '50%',
|
|
7549
7584
|
zIndex: 2,
|
|
7550
7585
|
display: 'flex',
|
|
7551
7586
|
flexDirection: 'column',
|
|
@@ -7697,12 +7732,13 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 470, onConfirmRecording, o
|
|
|
7697
7732
|
if (!permission) {
|
|
7698
7733
|
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" })] }) }));
|
|
7699
7734
|
}
|
|
7700
|
-
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:
|
|
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: {
|
|
7701
7736
|
width: rectWidth - 40,
|
|
7702
|
-
height:
|
|
7737
|
+
height: rectHeight - 40,
|
|
7703
7738
|
objectFit: 'cover',
|
|
7739
|
+
borderRadius: noShadow ? 0 : 8,
|
|
7704
7740
|
zIndex: 0,
|
|
7705
|
-
transform: 'scaleX(-1)'
|
|
7741
|
+
transform: 'scaleX(-1)'
|
|
7706
7742
|
}, playsInline: true, muted: true, autoPlay: true }), jsxRuntime.jsx("div", { className: "facerecorder-dark-overlay", style: {
|
|
7707
7743
|
position: 'absolute',
|
|
7708
7744
|
top: 0,
|
|
@@ -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
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
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
|
-
|
|
7841
|
+
if (isMountedRef.current)
|
|
7842
|
+
setPermission(false);
|
|
7798
7843
|
}
|
|
7799
7844
|
finally {
|
|
7800
|
-
|
|
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.
|
|
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": "^
|
|
46
|
-
"@types/react-dom": "^
|
|
38
|
+
"@types/react": "^18.3.1",
|
|
39
|
+
"@types/react-dom": "^18.3.1",
|
|
47
40
|
"@types/recordrtc": "^5.6.14",
|
|
48
|
-
"react": "^
|
|
49
|
-
"react-dom": "^
|
|
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",
|