biometry-react-components 1.2.0 → 1.2.2
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.d.ts +1 -1
- package/dist/index.esm.js +168 -107
- package/dist/index.js +168 -107
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ declare const FaceCapture: React.FC<FaceCaptureProps>;
|
|
|
23
23
|
interface FaceRecorderProps {
|
|
24
24
|
rectWidth?: number;
|
|
25
25
|
rectHeight?: number;
|
|
26
|
-
onCapture: (
|
|
26
|
+
onCapture: (video: File, face: File, audio: File, phrase: string) => void;
|
|
27
27
|
className?: string;
|
|
28
28
|
style?: React.CSSProperties;
|
|
29
29
|
noShadow?: boolean;
|
package/dist/index.esm.js
CHANGED
|
@@ -7248,6 +7248,77 @@ function numbersToPhrase(numbers) {
|
|
|
7248
7248
|
void requestPermissions();
|
|
7249
7249
|
}, [rectWidth, rectHeight]);
|
|
7250
7250
|
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7251
|
+
};const useAudioPermissions = () => {
|
|
7252
|
+
const [permission, setPermission] = useState(false);
|
|
7253
|
+
const [stream, setStream] = useState(null);
|
|
7254
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
7255
|
+
const stopStreamTracks = () => {
|
|
7256
|
+
if (stream) {
|
|
7257
|
+
stream.getTracks().forEach(track => {
|
|
7258
|
+
track.stop();
|
|
7259
|
+
});
|
|
7260
|
+
setStream(null);
|
|
7261
|
+
}
|
|
7262
|
+
};
|
|
7263
|
+
const getAudioConstraints = () => {
|
|
7264
|
+
// Detect device capabilities and choose appropriate quality
|
|
7265
|
+
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7266
|
+
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7267
|
+
// High-end device settings
|
|
7268
|
+
if (!isMobile && !isLowEndDevice) {
|
|
7269
|
+
return {
|
|
7270
|
+
audio: {
|
|
7271
|
+
echoCancellation: true,
|
|
7272
|
+
noiseSuppression: true,
|
|
7273
|
+
autoGainControl: true,
|
|
7274
|
+
sampleRate: 48000,
|
|
7275
|
+
channelCount: 2
|
|
7276
|
+
}
|
|
7277
|
+
};
|
|
7278
|
+
}
|
|
7279
|
+
// Mobile device settings
|
|
7280
|
+
if (isMobile) {
|
|
7281
|
+
return {
|
|
7282
|
+
audio: {
|
|
7283
|
+
echoCancellation: true,
|
|
7284
|
+
noiseSuppression: true,
|
|
7285
|
+
autoGainControl: true,
|
|
7286
|
+
sampleRate: 22050, // Lower for mobile
|
|
7287
|
+
channelCount: 1
|
|
7288
|
+
}
|
|
7289
|
+
};
|
|
7290
|
+
}
|
|
7291
|
+
// Low-end device settings
|
|
7292
|
+
return {
|
|
7293
|
+
audio: {
|
|
7294
|
+
echoCancellation: true,
|
|
7295
|
+
noiseSuppression: true,
|
|
7296
|
+
autoGainControl: true,
|
|
7297
|
+
sampleRate: 22050,
|
|
7298
|
+
channelCount: 1
|
|
7299
|
+
}
|
|
7300
|
+
};
|
|
7301
|
+
};
|
|
7302
|
+
const requestPermissions = async () => {
|
|
7303
|
+
try {
|
|
7304
|
+
setIsLoading(true);
|
|
7305
|
+
const constraints = getAudioConstraints();
|
|
7306
|
+
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7307
|
+
setPermission(true);
|
|
7308
|
+
setStream(streamData);
|
|
7309
|
+
}
|
|
7310
|
+
catch (err) {
|
|
7311
|
+
console.error('Microphone permission denied:', err);
|
|
7312
|
+
setPermission(false);
|
|
7313
|
+
}
|
|
7314
|
+
finally {
|
|
7315
|
+
setIsLoading(false);
|
|
7316
|
+
}
|
|
7317
|
+
};
|
|
7318
|
+
useEffect(() => {
|
|
7319
|
+
void requestPermissions();
|
|
7320
|
+
}, []);
|
|
7321
|
+
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7251
7322
|
};// spinner animation
|
|
7252
7323
|
const spinnerStyle$1 = `
|
|
7253
7324
|
@keyframes spin {
|
|
@@ -7268,21 +7339,32 @@ if (typeof window !== 'undefined' && typeof console !== 'undefined') {
|
|
|
7268
7339
|
}
|
|
7269
7340
|
const RECORD_SECONDS$1 = 10;
|
|
7270
7341
|
const PREP_SECONDS$1 = 3;
|
|
7342
|
+
const FACE_CAPTURE_SECOND = 5;
|
|
7271
7343
|
function generateRandomDigits$1(count) {
|
|
7272
|
-
|
|
7344
|
+
const digits = Array.from({ length: 10 }, (_, i) => i);
|
|
7345
|
+
for (let i = digits.length - 1; i > 0; i--) {
|
|
7346
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
7347
|
+
[digits[i], digits[j]] = [digits[j], digits[i]];
|
|
7348
|
+
}
|
|
7349
|
+
return digits.slice(0, count);
|
|
7273
7350
|
}
|
|
7274
7351
|
const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className, style, noShadow = false, }) => {
|
|
7275
7352
|
const [state, setState] = useState('preparation');
|
|
7276
7353
|
const [prepTimer, setPrepTimer] = useState(PREP_SECONDS$1);
|
|
7277
7354
|
const [recordTimer, setRecordTimer] = useState(RECORD_SECONDS$1);
|
|
7278
|
-
const [digits, setDigits] = useState(generateRandomDigits$1(
|
|
7355
|
+
const [digits, setDigits] = useState(generateRandomDigits$1(10));
|
|
7279
7356
|
const { permission, stream, stopStreamTracks, requestPermissions, isLoading } = usePermissions({ rectWidth, rectHeight });
|
|
7357
|
+
const { permission: audioPermission, stream: audioStream, stopStreamTracks: stopAudioStreamTracks, requestPermissions: requestAudioPermissions, isLoading: audioIsLoading } = useAudioPermissions();
|
|
7280
7358
|
const [videoBlob, setVideoBlob] = useState(null);
|
|
7281
7359
|
const [videoUrl, setVideoUrl] = useState(null);
|
|
7360
|
+
const [audioBlob, setAudioBlob] = useState(null);
|
|
7361
|
+
const [faceImageBlob, setFaceImageBlob] = useState(null);
|
|
7282
7362
|
const [isConfirming, setIsConfirming] = useState(false);
|
|
7363
|
+
const [faceCaptured, setFaceCaptured] = useState(false);
|
|
7283
7364
|
const videoRef = useRef(null);
|
|
7284
7365
|
const previewRef = useRef(null);
|
|
7285
|
-
const
|
|
7366
|
+
const canvasRef = useRef(null);
|
|
7367
|
+
const { startRecording: startVideoRecording, cancelRecording: cancelVideoRecording } = useRecorder(stream, "video", (blob) => {
|
|
7286
7368
|
stopStreamTracks();
|
|
7287
7369
|
if (blob && blob.size > 0) {
|
|
7288
7370
|
setVideoBlob(blob);
|
|
@@ -7300,6 +7382,34 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7300
7382
|
setIsConfirming(true);
|
|
7301
7383
|
}
|
|
7302
7384
|
});
|
|
7385
|
+
const { startRecording: startAudioRecording, cancelRecording: cancelAudioRecording } = useRecorder(audioStream, "audio", (blob) => {
|
|
7386
|
+
stopAudioStreamTracks();
|
|
7387
|
+
if (blob && blob.size > 0) {
|
|
7388
|
+
setAudioBlob(blob);
|
|
7389
|
+
}
|
|
7390
|
+
else {
|
|
7391
|
+
const dummyBlob = new Blob(['dummy audio data'], { type: 'audio/webm' });
|
|
7392
|
+
setAudioBlob(dummyBlob);
|
|
7393
|
+
}
|
|
7394
|
+
});
|
|
7395
|
+
const captureFaceImage = () => {
|
|
7396
|
+
if (videoRef.current && canvasRef.current && !faceCaptured) {
|
|
7397
|
+
const video = videoRef.current;
|
|
7398
|
+
const canvas = canvasRef.current;
|
|
7399
|
+
const ctx = canvas.getContext('2d');
|
|
7400
|
+
if (ctx) {
|
|
7401
|
+
canvas.width = video.videoWidth;
|
|
7402
|
+
canvas.height = video.videoHeight;
|
|
7403
|
+
ctx.drawImage(video, 0, 0);
|
|
7404
|
+
canvas.toBlob((blob) => {
|
|
7405
|
+
if (blob) {
|
|
7406
|
+
setFaceImageBlob(blob);
|
|
7407
|
+
setFaceCaptured(true);
|
|
7408
|
+
}
|
|
7409
|
+
}, 'image/jpeg', 0.9);
|
|
7410
|
+
}
|
|
7411
|
+
}
|
|
7412
|
+
};
|
|
7303
7413
|
useEffect(() => {
|
|
7304
7414
|
let isMounted = true;
|
|
7305
7415
|
console.log('Camera setup useEffect - state:', state, 'isConfirming:', isConfirming);
|
|
@@ -7327,15 +7437,22 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7327
7437
|
else {
|
|
7328
7438
|
setState('recording');
|
|
7329
7439
|
setPrepTimer(PREP_SECONDS$1);
|
|
7330
|
-
|
|
7440
|
+
startVideoRecording();
|
|
7441
|
+
startAudioRecording();
|
|
7331
7442
|
}
|
|
7332
7443
|
}
|
|
7333
|
-
}, [state, prepTimer,
|
|
7444
|
+
}, [state, prepTimer, startVideoRecording, startAudioRecording]);
|
|
7334
7445
|
// Recording timer
|
|
7335
7446
|
useEffect(() => {
|
|
7336
7447
|
if (state === 'recording') {
|
|
7337
7448
|
if (recordTimer > 0) {
|
|
7338
|
-
const t = setTimeout(() =>
|
|
7449
|
+
const t = setTimeout(() => {
|
|
7450
|
+
const newTimer = recordTimer - 1;
|
|
7451
|
+
setRecordTimer(newTimer);
|
|
7452
|
+
if (newTimer === RECORD_SECONDS$1 - FACE_CAPTURE_SECOND) {
|
|
7453
|
+
captureFaceImage();
|
|
7454
|
+
}
|
|
7455
|
+
}, 1000);
|
|
7339
7456
|
return () => clearTimeout(t);
|
|
7340
7457
|
}
|
|
7341
7458
|
else {
|
|
@@ -7344,30 +7461,39 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7344
7461
|
}
|
|
7345
7462
|
}, [state, recordTimer]);
|
|
7346
7463
|
const startRecording = async () => {
|
|
7347
|
-
setDigits(generateRandomDigits$1(
|
|
7464
|
+
setDigits(generateRandomDigits$1(10));
|
|
7348
7465
|
setRecordTimer(RECORD_SECONDS$1);
|
|
7466
|
+
setFaceCaptured(false);
|
|
7349
7467
|
setState('countdown');
|
|
7350
7468
|
};
|
|
7351
7469
|
const handleCancel = () => {
|
|
7352
|
-
|
|
7353
|
-
|
|
7354
|
-
// Then stop stream and reset state
|
|
7470
|
+
cancelVideoRecording();
|
|
7471
|
+
cancelAudioRecording();
|
|
7355
7472
|
stopStreamTracks();
|
|
7473
|
+
stopAudioStreamTracks();
|
|
7356
7474
|
setState('preparation');
|
|
7357
7475
|
setIsConfirming(false);
|
|
7358
7476
|
setVideoUrl(null);
|
|
7359
7477
|
setVideoBlob(null);
|
|
7360
|
-
|
|
7478
|
+
setAudioBlob(null);
|
|
7479
|
+
setFaceImageBlob(null);
|
|
7480
|
+
setFaceCaptured(false);
|
|
7361
7481
|
requestPermissions();
|
|
7482
|
+
requestAudioPermissions();
|
|
7362
7483
|
};
|
|
7363
7484
|
const handleConfirm = () => {
|
|
7364
|
-
if (videoBlob) {
|
|
7365
|
-
const
|
|
7366
|
-
|
|
7485
|
+
if (videoBlob && audioBlob && faceImageBlob) {
|
|
7486
|
+
const videoFile = new File([videoBlob], 'face-video.webm', { type: videoBlob.type });
|
|
7487
|
+
const audioFile = new File([audioBlob], 'face-audio.webm', { type: audioBlob.type });
|
|
7488
|
+
const faceFile = new File([faceImageBlob], 'face-image.jpg', { type: 'image/jpeg' });
|
|
7489
|
+
onCapture(videoFile, faceFile, audioFile, numbersToPhrase(digits));
|
|
7367
7490
|
if (videoUrl)
|
|
7368
7491
|
URL.revokeObjectURL(videoUrl);
|
|
7369
7492
|
setVideoUrl(null);
|
|
7370
7493
|
setVideoBlob(null);
|
|
7494
|
+
setAudioBlob(null);
|
|
7495
|
+
setFaceImageBlob(null);
|
|
7496
|
+
setFaceCaptured(false);
|
|
7371
7497
|
setIsConfirming(false);
|
|
7372
7498
|
setState('preparation');
|
|
7373
7499
|
}
|
|
@@ -7377,10 +7503,13 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7377
7503
|
URL.revokeObjectURL(videoUrl);
|
|
7378
7504
|
setVideoUrl(null);
|
|
7379
7505
|
setVideoBlob(null);
|
|
7506
|
+
setAudioBlob(null);
|
|
7507
|
+
setFaceImageBlob(null);
|
|
7508
|
+
setFaceCaptured(false);
|
|
7380
7509
|
setIsConfirming(false);
|
|
7381
7510
|
setState('preparation');
|
|
7382
|
-
// Restart the stream for retake
|
|
7383
7511
|
requestPermissions();
|
|
7512
|
+
requestAudioPermissions();
|
|
7384
7513
|
};
|
|
7385
7514
|
const wrapperStyle = {
|
|
7386
7515
|
background: '#fff',
|
|
@@ -7445,16 +7574,18 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7445
7574
|
const numberRow = {
|
|
7446
7575
|
display: 'flex',
|
|
7447
7576
|
justifyContent: 'center',
|
|
7448
|
-
gap:
|
|
7577
|
+
gap: 4,
|
|
7449
7578
|
margin: '16px 0 24px 0',
|
|
7579
|
+
flexWrap: 'nowrap',
|
|
7580
|
+
maxWidth: rectWidth - 40,
|
|
7450
7581
|
};
|
|
7451
7582
|
const numberBox = {
|
|
7452
|
-
minWidth:
|
|
7453
|
-
minHeight:
|
|
7583
|
+
minWidth: 22,
|
|
7584
|
+
minHeight: 30,
|
|
7454
7585
|
background: '#f5f5f5',
|
|
7455
7586
|
border: '2px solid #333',
|
|
7456
|
-
borderRadius:
|
|
7457
|
-
fontSize:
|
|
7587
|
+
borderRadius: 4,
|
|
7588
|
+
fontSize: 14,
|
|
7458
7589
|
fontWeight: 600,
|
|
7459
7590
|
color: '#333',
|
|
7460
7591
|
display: 'flex',
|
|
@@ -7531,8 +7662,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7531
7662
|
transition: 'background 0.2s',
|
|
7532
7663
|
margin: '0 8px',
|
|
7533
7664
|
};
|
|
7534
|
-
|
|
7535
|
-
if (isLoading) {
|
|
7665
|
+
if (isLoading || audioIsLoading) {
|
|
7536
7666
|
return (jsx("div", { className: className, style: wrapperStyle, children: jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsx("div", { style: {
|
|
7537
7667
|
width: 48,
|
|
7538
7668
|
height: 48,
|
|
@@ -7541,13 +7671,15 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7541
7671
|
borderRadius: '50%',
|
|
7542
7672
|
animation: 'spin 1s linear infinite',
|
|
7543
7673
|
margin: '0 auto 16px auto',
|
|
7544
|
-
} }), jsx("h3", { children: "Initializing Camera..." }), jsx("p", { children: "Please wait while we set up your camera." })] }) }));
|
|
7674
|
+
} }), jsx("h3", { children: "Initializing Camera & Microphone..." }), jsx("p", { children: "Please wait while we set up your camera and microphone." })] }) }));
|
|
7545
7675
|
}
|
|
7546
|
-
|
|
7547
|
-
|
|
7548
|
-
|
|
7676
|
+
if (!permission || !audioPermission) {
|
|
7677
|
+
return (jsx("div", { className: className, style: wrapperStyle, children: jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsx("h3", { children: "Camera & Microphone Permission Required" }), jsx("p", { children: "Please allow camera and microphone access to use this component." }), jsx("button", { type: "button", style: actionButton, onClick: () => {
|
|
7678
|
+
requestPermissions();
|
|
7679
|
+
requestAudioPermissions();
|
|
7680
|
+
}, children: "Grant Permissions" })] }) }));
|
|
7549
7681
|
}
|
|
7550
|
-
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: {
|
|
7682
|
+
return (jsxs("div", { className: className, style: wrapperStyle, children: [jsx("canvas", { ref: canvasRef, style: { display: 'none' } }), 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: {
|
|
7551
7683
|
width: rectWidth - 40,
|
|
7552
7684
|
height: rectHeight - 40,
|
|
7553
7685
|
objectFit: 'cover',
|
|
@@ -7562,7 +7694,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7562
7694
|
background: 'rgba(0,0,0,0.4)',
|
|
7563
7695
|
zIndex: 1,
|
|
7564
7696
|
borderRadius: noShadow ? 0 : 8,
|
|
7565
|
-
} }), 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 }))] }), jsx("div", { style: numberRow, children: (state === 'recording' ? digits : Array(
|
|
7697
|
+
} }), 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 }))] }), jsx("div", { style: numberRow, children: (state === 'recording' ? digits : Array(10).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: {
|
|
7566
7698
|
display: 'flex',
|
|
7567
7699
|
flexDirection: 'column',
|
|
7568
7700
|
alignItems: 'center',
|
|
@@ -7583,77 +7715,6 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7583
7715
|
borderRadius: 8,
|
|
7584
7716
|
objectFit: 'cover'
|
|
7585
7717
|
}, onLoadedData: () => console.log('Video loaded successfully'), onError: (e) => console.error('Video error:', e), onLoadStart: () => console.log('Video load started'), onCanPlay: () => console.log('Video can play') })) }), jsx("div", { className: "facerecorder-confirm-text", style: confirmText, children: "Do you want to use this video?" }), jsxs("div", { className: "facerecorder-confirm-btns", style: { display: 'flex', justifyContent: 'center', gap: 32, marginTop: 16, width: '100%' }, children: [jsx("button", { type: "button", "aria-label": "Retake", className: "facerecorder-icon-btn", style: iconButton, onClick: handleDecline, onMouseOver: e => (e.currentTarget.style.background = 'rgba(211,47,47,0.12)'), onMouseOut: e => (e.currentTarget.style.background = 'none'), children: jsxs("svg", { width: "36", height: "36", viewBox: "0 0 36 36", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx("circle", { cx: "18", cy: "18", r: "18", fill: "#fff", fillOpacity: "0.15" }), jsx("path", { d: "M12 12L24 24", stroke: "#d32f2f", strokeWidth: "3", strokeLinecap: "round" }), jsx("path", { d: "M24 12L12 24", stroke: "#d32f2f", strokeWidth: "3", strokeLinecap: "round" })] }) }), jsx("button", { type: "button", "aria-label": "Confirm", className: "facerecorder-icon-btn", style: iconButton, onClick: handleConfirm, onMouseOver: e => (e.currentTarget.style.background = 'rgba(56,142,60,0.12)'), onMouseOut: e => (e.currentTarget.style.background = 'none'), children: jsxs("svg", { width: "36", height: "36", viewBox: "0 0 36 36", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx("circle", { cx: "18", cy: "18", r: "18", fill: "#fff", fillOpacity: "0.15" }), jsx("path", { d: "M10 19L16 25L26 13", stroke: "#388e3c", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round" })] }) })] })] }))] }));
|
|
7586
|
-
};const useAudioPermissions = () => {
|
|
7587
|
-
const [permission, setPermission] = useState(false);
|
|
7588
|
-
const [stream, setStream] = useState(null);
|
|
7589
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
7590
|
-
const stopStreamTracks = () => {
|
|
7591
|
-
if (stream) {
|
|
7592
|
-
stream.getTracks().forEach(track => {
|
|
7593
|
-
track.stop();
|
|
7594
|
-
});
|
|
7595
|
-
setStream(null);
|
|
7596
|
-
}
|
|
7597
|
-
};
|
|
7598
|
-
const getAudioConstraints = () => {
|
|
7599
|
-
// Detect device capabilities and choose appropriate quality
|
|
7600
|
-
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7601
|
-
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7602
|
-
// High-end device settings
|
|
7603
|
-
if (!isMobile && !isLowEndDevice) {
|
|
7604
|
-
return {
|
|
7605
|
-
audio: {
|
|
7606
|
-
echoCancellation: true,
|
|
7607
|
-
noiseSuppression: true,
|
|
7608
|
-
autoGainControl: true,
|
|
7609
|
-
sampleRate: 48000,
|
|
7610
|
-
channelCount: 2
|
|
7611
|
-
}
|
|
7612
|
-
};
|
|
7613
|
-
}
|
|
7614
|
-
// Mobile device settings
|
|
7615
|
-
if (isMobile) {
|
|
7616
|
-
return {
|
|
7617
|
-
audio: {
|
|
7618
|
-
echoCancellation: true,
|
|
7619
|
-
noiseSuppression: true,
|
|
7620
|
-
autoGainControl: true,
|
|
7621
|
-
sampleRate: 22050, // Lower for mobile
|
|
7622
|
-
channelCount: 1
|
|
7623
|
-
}
|
|
7624
|
-
};
|
|
7625
|
-
}
|
|
7626
|
-
// Low-end device settings
|
|
7627
|
-
return {
|
|
7628
|
-
audio: {
|
|
7629
|
-
echoCancellation: true,
|
|
7630
|
-
noiseSuppression: true,
|
|
7631
|
-
autoGainControl: true,
|
|
7632
|
-
sampleRate: 22050,
|
|
7633
|
-
channelCount: 1
|
|
7634
|
-
}
|
|
7635
|
-
};
|
|
7636
|
-
};
|
|
7637
|
-
const requestPermissions = async () => {
|
|
7638
|
-
try {
|
|
7639
|
-
setIsLoading(true);
|
|
7640
|
-
const constraints = getAudioConstraints();
|
|
7641
|
-
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7642
|
-
setPermission(true);
|
|
7643
|
-
setStream(streamData);
|
|
7644
|
-
}
|
|
7645
|
-
catch (err) {
|
|
7646
|
-
console.error('Microphone permission denied:', err);
|
|
7647
|
-
setPermission(false);
|
|
7648
|
-
}
|
|
7649
|
-
finally {
|
|
7650
|
-
setIsLoading(false);
|
|
7651
|
-
}
|
|
7652
|
-
};
|
|
7653
|
-
useEffect(() => {
|
|
7654
|
-
void requestPermissions();
|
|
7655
|
-
}, []);
|
|
7656
|
-
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7657
7718
|
};// spinner animation
|
|
7658
7719
|
const spinnerStyle = `
|
|
7659
7720
|
@keyframes spin {
|
|
@@ -7681,7 +7742,7 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
|
|
|
7681
7742
|
const [state, setState] = useState('preparation');
|
|
7682
7743
|
const [prepTimer, setPrepTimer] = useState(PREP_SECONDS);
|
|
7683
7744
|
const [recordTimer, setRecordTimer] = useState(RECORD_SECONDS);
|
|
7684
|
-
const [digits, setDigits] = useState(generateRandomDigits(
|
|
7745
|
+
const [digits, setDigits] = useState(generateRandomDigits(10));
|
|
7685
7746
|
const [audioLevel, setAudioLevel] = useState(0);
|
|
7686
7747
|
const [waveformData, setWaveformData] = useState([]);
|
|
7687
7748
|
const { permission, stream, stopStreamTracks, requestPermissions, isLoading } = useAudioPermissions();
|
|
@@ -7768,7 +7829,7 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
|
|
|
7768
7829
|
}
|
|
7769
7830
|
}, [state, recordTimer]);
|
|
7770
7831
|
const startRecording = async () => {
|
|
7771
|
-
setDigits(generateRandomDigits(
|
|
7832
|
+
setDigits(generateRandomDigits(10));
|
|
7772
7833
|
setRecordTimer(RECORD_SECONDS);
|
|
7773
7834
|
setState('countdown');
|
|
7774
7835
|
};
|
|
@@ -7865,16 +7926,16 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
|
|
|
7865
7926
|
const numberRow = {
|
|
7866
7927
|
display: 'flex',
|
|
7867
7928
|
justifyContent: 'center',
|
|
7868
|
-
gap:
|
|
7929
|
+
gap: 6,
|
|
7869
7930
|
margin: '16px 0 24px 0',
|
|
7870
7931
|
};
|
|
7871
7932
|
const numberBox = {
|
|
7872
|
-
minWidth:
|
|
7873
|
-
minHeight:
|
|
7933
|
+
minWidth: 24,
|
|
7934
|
+
minHeight: 32,
|
|
7874
7935
|
background: '#f5f5f5',
|
|
7875
7936
|
border: '2px solid #333',
|
|
7876
|
-
borderRadius:
|
|
7877
|
-
fontSize:
|
|
7937
|
+
borderRadius: 4,
|
|
7938
|
+
fontSize: 16,
|
|
7878
7939
|
fontWeight: 600,
|
|
7879
7940
|
color: '#333',
|
|
7880
7941
|
display: 'flex',
|
|
@@ -7983,7 +8044,7 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
|
|
|
7983
8044
|
justifyContent: 'center',
|
|
7984
8045
|
height: '120px',
|
|
7985
8046
|
gap: '2px',
|
|
7986
|
-
}, children: waveformData.map((value, index) => (jsx("div", { style: waveformBar(value / 255) }, index))) }) }), jsx("div", { style: timerStyle, children: recordTimer }), jsx("div", { style: guidanceText, children: "Speak clearly into your microphone" })] }))] })] }), jsx("div", { style: numberRow, children: (state === 'recording' ? digits : Array(
|
|
8047
|
+
}, children: waveformData.map((value, index) => (jsx("div", { style: waveformBar(value / 255) }, index))) }) }), jsx("div", { style: timerStyle, children: recordTimer }), jsx("div", { style: guidanceText, children: "Speak clearly into your microphone" })] }))] })] }), jsx("div", { style: numberRow, children: (state === 'recording' ? digits : Array(10).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: "voicerecorder-processing", style: preview, children: jsxs("div", { style: {
|
|
7987
8048
|
display: 'flex',
|
|
7988
8049
|
flexDirection: 'column',
|
|
7989
8050
|
alignItems: 'center',
|
package/dist/index.js
CHANGED
|
@@ -7248,6 +7248,77 @@ function numbersToPhrase(numbers) {
|
|
|
7248
7248
|
void requestPermissions();
|
|
7249
7249
|
}, [rectWidth, rectHeight]);
|
|
7250
7250
|
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7251
|
+
};const useAudioPermissions = () => {
|
|
7252
|
+
const [permission, setPermission] = react.useState(false);
|
|
7253
|
+
const [stream, setStream] = react.useState(null);
|
|
7254
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
7255
|
+
const stopStreamTracks = () => {
|
|
7256
|
+
if (stream) {
|
|
7257
|
+
stream.getTracks().forEach(track => {
|
|
7258
|
+
track.stop();
|
|
7259
|
+
});
|
|
7260
|
+
setStream(null);
|
|
7261
|
+
}
|
|
7262
|
+
};
|
|
7263
|
+
const getAudioConstraints = () => {
|
|
7264
|
+
// Detect device capabilities and choose appropriate quality
|
|
7265
|
+
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7266
|
+
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7267
|
+
// High-end device settings
|
|
7268
|
+
if (!isMobile && !isLowEndDevice) {
|
|
7269
|
+
return {
|
|
7270
|
+
audio: {
|
|
7271
|
+
echoCancellation: true,
|
|
7272
|
+
noiseSuppression: true,
|
|
7273
|
+
autoGainControl: true,
|
|
7274
|
+
sampleRate: 48000,
|
|
7275
|
+
channelCount: 2
|
|
7276
|
+
}
|
|
7277
|
+
};
|
|
7278
|
+
}
|
|
7279
|
+
// Mobile device settings
|
|
7280
|
+
if (isMobile) {
|
|
7281
|
+
return {
|
|
7282
|
+
audio: {
|
|
7283
|
+
echoCancellation: true,
|
|
7284
|
+
noiseSuppression: true,
|
|
7285
|
+
autoGainControl: true,
|
|
7286
|
+
sampleRate: 22050, // Lower for mobile
|
|
7287
|
+
channelCount: 1
|
|
7288
|
+
}
|
|
7289
|
+
};
|
|
7290
|
+
}
|
|
7291
|
+
// Low-end device settings
|
|
7292
|
+
return {
|
|
7293
|
+
audio: {
|
|
7294
|
+
echoCancellation: true,
|
|
7295
|
+
noiseSuppression: true,
|
|
7296
|
+
autoGainControl: true,
|
|
7297
|
+
sampleRate: 22050,
|
|
7298
|
+
channelCount: 1
|
|
7299
|
+
}
|
|
7300
|
+
};
|
|
7301
|
+
};
|
|
7302
|
+
const requestPermissions = async () => {
|
|
7303
|
+
try {
|
|
7304
|
+
setIsLoading(true);
|
|
7305
|
+
const constraints = getAudioConstraints();
|
|
7306
|
+
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7307
|
+
setPermission(true);
|
|
7308
|
+
setStream(streamData);
|
|
7309
|
+
}
|
|
7310
|
+
catch (err) {
|
|
7311
|
+
console.error('Microphone permission denied:', err);
|
|
7312
|
+
setPermission(false);
|
|
7313
|
+
}
|
|
7314
|
+
finally {
|
|
7315
|
+
setIsLoading(false);
|
|
7316
|
+
}
|
|
7317
|
+
};
|
|
7318
|
+
react.useEffect(() => {
|
|
7319
|
+
void requestPermissions();
|
|
7320
|
+
}, []);
|
|
7321
|
+
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7251
7322
|
};// spinner animation
|
|
7252
7323
|
const spinnerStyle$1 = `
|
|
7253
7324
|
@keyframes spin {
|
|
@@ -7268,21 +7339,32 @@ if (typeof window !== 'undefined' && typeof console !== 'undefined') {
|
|
|
7268
7339
|
}
|
|
7269
7340
|
const RECORD_SECONDS$1 = 10;
|
|
7270
7341
|
const PREP_SECONDS$1 = 3;
|
|
7342
|
+
const FACE_CAPTURE_SECOND = 5;
|
|
7271
7343
|
function generateRandomDigits$1(count) {
|
|
7272
|
-
|
|
7344
|
+
const digits = Array.from({ length: 10 }, (_, i) => i);
|
|
7345
|
+
for (let i = digits.length - 1; i > 0; i--) {
|
|
7346
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
7347
|
+
[digits[i], digits[j]] = [digits[j], digits[i]];
|
|
7348
|
+
}
|
|
7349
|
+
return digits.slice(0, count);
|
|
7273
7350
|
}
|
|
7274
7351
|
const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className, style, noShadow = false, }) => {
|
|
7275
7352
|
const [state, setState] = react.useState('preparation');
|
|
7276
7353
|
const [prepTimer, setPrepTimer] = react.useState(PREP_SECONDS$1);
|
|
7277
7354
|
const [recordTimer, setRecordTimer] = react.useState(RECORD_SECONDS$1);
|
|
7278
|
-
const [digits, setDigits] = react.useState(generateRandomDigits$1(
|
|
7355
|
+
const [digits, setDigits] = react.useState(generateRandomDigits$1(10));
|
|
7279
7356
|
const { permission, stream, stopStreamTracks, requestPermissions, isLoading } = usePermissions({ rectWidth, rectHeight });
|
|
7357
|
+
const { permission: audioPermission, stream: audioStream, stopStreamTracks: stopAudioStreamTracks, requestPermissions: requestAudioPermissions, isLoading: audioIsLoading } = useAudioPermissions();
|
|
7280
7358
|
const [videoBlob, setVideoBlob] = react.useState(null);
|
|
7281
7359
|
const [videoUrl, setVideoUrl] = react.useState(null);
|
|
7360
|
+
const [audioBlob, setAudioBlob] = react.useState(null);
|
|
7361
|
+
const [faceImageBlob, setFaceImageBlob] = react.useState(null);
|
|
7282
7362
|
const [isConfirming, setIsConfirming] = react.useState(false);
|
|
7363
|
+
const [faceCaptured, setFaceCaptured] = react.useState(false);
|
|
7283
7364
|
const videoRef = react.useRef(null);
|
|
7284
7365
|
const previewRef = react.useRef(null);
|
|
7285
|
-
const
|
|
7366
|
+
const canvasRef = react.useRef(null);
|
|
7367
|
+
const { startRecording: startVideoRecording, cancelRecording: cancelVideoRecording } = useRecorder(stream, "video", (blob) => {
|
|
7286
7368
|
stopStreamTracks();
|
|
7287
7369
|
if (blob && blob.size > 0) {
|
|
7288
7370
|
setVideoBlob(blob);
|
|
@@ -7300,6 +7382,34 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7300
7382
|
setIsConfirming(true);
|
|
7301
7383
|
}
|
|
7302
7384
|
});
|
|
7385
|
+
const { startRecording: startAudioRecording, cancelRecording: cancelAudioRecording } = useRecorder(audioStream, "audio", (blob) => {
|
|
7386
|
+
stopAudioStreamTracks();
|
|
7387
|
+
if (blob && blob.size > 0) {
|
|
7388
|
+
setAudioBlob(blob);
|
|
7389
|
+
}
|
|
7390
|
+
else {
|
|
7391
|
+
const dummyBlob = new Blob(['dummy audio data'], { type: 'audio/webm' });
|
|
7392
|
+
setAudioBlob(dummyBlob);
|
|
7393
|
+
}
|
|
7394
|
+
});
|
|
7395
|
+
const captureFaceImage = () => {
|
|
7396
|
+
if (videoRef.current && canvasRef.current && !faceCaptured) {
|
|
7397
|
+
const video = videoRef.current;
|
|
7398
|
+
const canvas = canvasRef.current;
|
|
7399
|
+
const ctx = canvas.getContext('2d');
|
|
7400
|
+
if (ctx) {
|
|
7401
|
+
canvas.width = video.videoWidth;
|
|
7402
|
+
canvas.height = video.videoHeight;
|
|
7403
|
+
ctx.drawImage(video, 0, 0);
|
|
7404
|
+
canvas.toBlob((blob) => {
|
|
7405
|
+
if (blob) {
|
|
7406
|
+
setFaceImageBlob(blob);
|
|
7407
|
+
setFaceCaptured(true);
|
|
7408
|
+
}
|
|
7409
|
+
}, 'image/jpeg', 0.9);
|
|
7410
|
+
}
|
|
7411
|
+
}
|
|
7412
|
+
};
|
|
7303
7413
|
react.useEffect(() => {
|
|
7304
7414
|
let isMounted = true;
|
|
7305
7415
|
console.log('Camera setup useEffect - state:', state, 'isConfirming:', isConfirming);
|
|
@@ -7327,15 +7437,22 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7327
7437
|
else {
|
|
7328
7438
|
setState('recording');
|
|
7329
7439
|
setPrepTimer(PREP_SECONDS$1);
|
|
7330
|
-
|
|
7440
|
+
startVideoRecording();
|
|
7441
|
+
startAudioRecording();
|
|
7331
7442
|
}
|
|
7332
7443
|
}
|
|
7333
|
-
}, [state, prepTimer,
|
|
7444
|
+
}, [state, prepTimer, startVideoRecording, startAudioRecording]);
|
|
7334
7445
|
// Recording timer
|
|
7335
7446
|
react.useEffect(() => {
|
|
7336
7447
|
if (state === 'recording') {
|
|
7337
7448
|
if (recordTimer > 0) {
|
|
7338
|
-
const t = setTimeout(() =>
|
|
7449
|
+
const t = setTimeout(() => {
|
|
7450
|
+
const newTimer = recordTimer - 1;
|
|
7451
|
+
setRecordTimer(newTimer);
|
|
7452
|
+
if (newTimer === RECORD_SECONDS$1 - FACE_CAPTURE_SECOND) {
|
|
7453
|
+
captureFaceImage();
|
|
7454
|
+
}
|
|
7455
|
+
}, 1000);
|
|
7339
7456
|
return () => clearTimeout(t);
|
|
7340
7457
|
}
|
|
7341
7458
|
else {
|
|
@@ -7344,30 +7461,39 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7344
7461
|
}
|
|
7345
7462
|
}, [state, recordTimer]);
|
|
7346
7463
|
const startRecording = async () => {
|
|
7347
|
-
setDigits(generateRandomDigits$1(
|
|
7464
|
+
setDigits(generateRandomDigits$1(10));
|
|
7348
7465
|
setRecordTimer(RECORD_SECONDS$1);
|
|
7466
|
+
setFaceCaptured(false);
|
|
7349
7467
|
setState('countdown');
|
|
7350
7468
|
};
|
|
7351
7469
|
const handleCancel = () => {
|
|
7352
|
-
|
|
7353
|
-
|
|
7354
|
-
// Then stop stream and reset state
|
|
7470
|
+
cancelVideoRecording();
|
|
7471
|
+
cancelAudioRecording();
|
|
7355
7472
|
stopStreamTracks();
|
|
7473
|
+
stopAudioStreamTracks();
|
|
7356
7474
|
setState('preparation');
|
|
7357
7475
|
setIsConfirming(false);
|
|
7358
7476
|
setVideoUrl(null);
|
|
7359
7477
|
setVideoBlob(null);
|
|
7360
|
-
|
|
7478
|
+
setAudioBlob(null);
|
|
7479
|
+
setFaceImageBlob(null);
|
|
7480
|
+
setFaceCaptured(false);
|
|
7361
7481
|
requestPermissions();
|
|
7482
|
+
requestAudioPermissions();
|
|
7362
7483
|
};
|
|
7363
7484
|
const handleConfirm = () => {
|
|
7364
|
-
if (videoBlob) {
|
|
7365
|
-
const
|
|
7366
|
-
|
|
7485
|
+
if (videoBlob && audioBlob && faceImageBlob) {
|
|
7486
|
+
const videoFile = new File([videoBlob], 'face-video.webm', { type: videoBlob.type });
|
|
7487
|
+
const audioFile = new File([audioBlob], 'face-audio.webm', { type: audioBlob.type });
|
|
7488
|
+
const faceFile = new File([faceImageBlob], 'face-image.jpg', { type: 'image/jpeg' });
|
|
7489
|
+
onCapture(videoFile, faceFile, audioFile, numbersToPhrase(digits));
|
|
7367
7490
|
if (videoUrl)
|
|
7368
7491
|
URL.revokeObjectURL(videoUrl);
|
|
7369
7492
|
setVideoUrl(null);
|
|
7370
7493
|
setVideoBlob(null);
|
|
7494
|
+
setAudioBlob(null);
|
|
7495
|
+
setFaceImageBlob(null);
|
|
7496
|
+
setFaceCaptured(false);
|
|
7371
7497
|
setIsConfirming(false);
|
|
7372
7498
|
setState('preparation');
|
|
7373
7499
|
}
|
|
@@ -7377,10 +7503,13 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7377
7503
|
URL.revokeObjectURL(videoUrl);
|
|
7378
7504
|
setVideoUrl(null);
|
|
7379
7505
|
setVideoBlob(null);
|
|
7506
|
+
setAudioBlob(null);
|
|
7507
|
+
setFaceImageBlob(null);
|
|
7508
|
+
setFaceCaptured(false);
|
|
7380
7509
|
setIsConfirming(false);
|
|
7381
7510
|
setState('preparation');
|
|
7382
|
-
// Restart the stream for retake
|
|
7383
7511
|
requestPermissions();
|
|
7512
|
+
requestAudioPermissions();
|
|
7384
7513
|
};
|
|
7385
7514
|
const wrapperStyle = {
|
|
7386
7515
|
background: '#fff',
|
|
@@ -7445,16 +7574,18 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7445
7574
|
const numberRow = {
|
|
7446
7575
|
display: 'flex',
|
|
7447
7576
|
justifyContent: 'center',
|
|
7448
|
-
gap:
|
|
7577
|
+
gap: 4,
|
|
7449
7578
|
margin: '16px 0 24px 0',
|
|
7579
|
+
flexWrap: 'nowrap',
|
|
7580
|
+
maxWidth: rectWidth - 40,
|
|
7450
7581
|
};
|
|
7451
7582
|
const numberBox = {
|
|
7452
|
-
minWidth:
|
|
7453
|
-
minHeight:
|
|
7583
|
+
minWidth: 22,
|
|
7584
|
+
minHeight: 30,
|
|
7454
7585
|
background: '#f5f5f5',
|
|
7455
7586
|
border: '2px solid #333',
|
|
7456
|
-
borderRadius:
|
|
7457
|
-
fontSize:
|
|
7587
|
+
borderRadius: 4,
|
|
7588
|
+
fontSize: 14,
|
|
7458
7589
|
fontWeight: 600,
|
|
7459
7590
|
color: '#333',
|
|
7460
7591
|
display: 'flex',
|
|
@@ -7531,8 +7662,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7531
7662
|
transition: 'background 0.2s',
|
|
7532
7663
|
margin: '0 8px',
|
|
7533
7664
|
};
|
|
7534
|
-
|
|
7535
|
-
if (isLoading) {
|
|
7665
|
+
if (isLoading || audioIsLoading) {
|
|
7536
7666
|
return (jsxRuntime.jsx("div", { className: className, style: wrapperStyle, children: jsxRuntime.jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsxRuntime.jsx("div", { style: {
|
|
7537
7667
|
width: 48,
|
|
7538
7668
|
height: 48,
|
|
@@ -7541,13 +7671,15 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7541
7671
|
borderRadius: '50%',
|
|
7542
7672
|
animation: 'spin 1s linear infinite',
|
|
7543
7673
|
margin: '0 auto 16px auto',
|
|
7544
|
-
} }), jsxRuntime.jsx("h3", { children: "Initializing Camera..." }), jsxRuntime.jsx("p", { children: "Please wait while we set up your camera." })] }) }));
|
|
7674
|
+
} }), jsxRuntime.jsx("h3", { children: "Initializing Camera & Microphone..." }), jsxRuntime.jsx("p", { children: "Please wait while we set up your camera and microphone." })] }) }));
|
|
7545
7675
|
}
|
|
7546
|
-
|
|
7547
|
-
|
|
7548
|
-
|
|
7676
|
+
if (!permission || !audioPermission) {
|
|
7677
|
+
return (jsxRuntime.jsx("div", { className: className, style: wrapperStyle, children: jsxRuntime.jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsxRuntime.jsx("h3", { children: "Camera & Microphone Permission Required" }), jsxRuntime.jsx("p", { children: "Please allow camera and microphone access to use this component." }), jsxRuntime.jsx("button", { type: "button", style: actionButton, onClick: () => {
|
|
7678
|
+
requestPermissions();
|
|
7679
|
+
requestAudioPermissions();
|
|
7680
|
+
}, children: "Grant Permissions" })] }) }));
|
|
7549
7681
|
}
|
|
7550
|
-
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: {
|
|
7682
|
+
return (jsxRuntime.jsxs("div", { className: className, style: wrapperStyle, children: [jsxRuntime.jsx("canvas", { ref: canvasRef, style: { display: 'none' } }), 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: {
|
|
7551
7683
|
width: rectWidth - 40,
|
|
7552
7684
|
height: rectHeight - 40,
|
|
7553
7685
|
objectFit: 'cover',
|
|
@@ -7562,7 +7694,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7562
7694
|
background: 'rgba(0,0,0,0.4)',
|
|
7563
7695
|
zIndex: 1,
|
|
7564
7696
|
borderRadius: noShadow ? 0 : 8,
|
|
7565
|
-
} }), 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 }))] }), jsxRuntime.jsx("div", { style: numberRow, children: (state === 'recording' ? digits : Array(
|
|
7697
|
+
} }), 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 }))] }), jsxRuntime.jsx("div", { style: numberRow, children: (state === 'recording' ? digits : Array(10).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: {
|
|
7566
7698
|
display: 'flex',
|
|
7567
7699
|
flexDirection: 'column',
|
|
7568
7700
|
alignItems: 'center',
|
|
@@ -7583,77 +7715,6 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7583
7715
|
borderRadius: 8,
|
|
7584
7716
|
objectFit: 'cover'
|
|
7585
7717
|
}, onLoadedData: () => console.log('Video loaded successfully'), onError: (e) => console.error('Video error:', e), onLoadStart: () => console.log('Video load started'), onCanPlay: () => console.log('Video can play') })) }), jsxRuntime.jsx("div", { className: "facerecorder-confirm-text", style: confirmText, children: "Do you want to use this video?" }), jsxRuntime.jsxs("div", { className: "facerecorder-confirm-btns", style: { display: 'flex', justifyContent: 'center', gap: 32, marginTop: 16, width: '100%' }, children: [jsxRuntime.jsx("button", { type: "button", "aria-label": "Retake", className: "facerecorder-icon-btn", style: iconButton, onClick: handleDecline, onMouseOver: e => (e.currentTarget.style.background = 'rgba(211,47,47,0.12)'), onMouseOut: e => (e.currentTarget.style.background = 'none'), children: jsxRuntime.jsxs("svg", { width: "36", height: "36", viewBox: "0 0 36 36", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsxRuntime.jsx("circle", { cx: "18", cy: "18", r: "18", fill: "#fff", fillOpacity: "0.15" }), jsxRuntime.jsx("path", { d: "M12 12L24 24", stroke: "#d32f2f", strokeWidth: "3", strokeLinecap: "round" }), jsxRuntime.jsx("path", { d: "M24 12L12 24", stroke: "#d32f2f", strokeWidth: "3", strokeLinecap: "round" })] }) }), jsxRuntime.jsx("button", { type: "button", "aria-label": "Confirm", className: "facerecorder-icon-btn", style: iconButton, onClick: handleConfirm, onMouseOver: e => (e.currentTarget.style.background = 'rgba(56,142,60,0.12)'), onMouseOut: e => (e.currentTarget.style.background = 'none'), children: jsxRuntime.jsxs("svg", { width: "36", height: "36", viewBox: "0 0 36 36", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsxRuntime.jsx("circle", { cx: "18", cy: "18", r: "18", fill: "#fff", fillOpacity: "0.15" }), jsxRuntime.jsx("path", { d: "M10 19L16 25L26 13", stroke: "#388e3c", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round" })] }) })] })] }))] }));
|
|
7586
|
-
};const useAudioPermissions = () => {
|
|
7587
|
-
const [permission, setPermission] = react.useState(false);
|
|
7588
|
-
const [stream, setStream] = react.useState(null);
|
|
7589
|
-
const [isLoading, setIsLoading] = react.useState(true);
|
|
7590
|
-
const stopStreamTracks = () => {
|
|
7591
|
-
if (stream) {
|
|
7592
|
-
stream.getTracks().forEach(track => {
|
|
7593
|
-
track.stop();
|
|
7594
|
-
});
|
|
7595
|
-
setStream(null);
|
|
7596
|
-
}
|
|
7597
|
-
};
|
|
7598
|
-
const getAudioConstraints = () => {
|
|
7599
|
-
// Detect device capabilities and choose appropriate quality
|
|
7600
|
-
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7601
|
-
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7602
|
-
// High-end device settings
|
|
7603
|
-
if (!isMobile && !isLowEndDevice) {
|
|
7604
|
-
return {
|
|
7605
|
-
audio: {
|
|
7606
|
-
echoCancellation: true,
|
|
7607
|
-
noiseSuppression: true,
|
|
7608
|
-
autoGainControl: true,
|
|
7609
|
-
sampleRate: 48000,
|
|
7610
|
-
channelCount: 2
|
|
7611
|
-
}
|
|
7612
|
-
};
|
|
7613
|
-
}
|
|
7614
|
-
// Mobile device settings
|
|
7615
|
-
if (isMobile) {
|
|
7616
|
-
return {
|
|
7617
|
-
audio: {
|
|
7618
|
-
echoCancellation: true,
|
|
7619
|
-
noiseSuppression: true,
|
|
7620
|
-
autoGainControl: true,
|
|
7621
|
-
sampleRate: 22050, // Lower for mobile
|
|
7622
|
-
channelCount: 1
|
|
7623
|
-
}
|
|
7624
|
-
};
|
|
7625
|
-
}
|
|
7626
|
-
// Low-end device settings
|
|
7627
|
-
return {
|
|
7628
|
-
audio: {
|
|
7629
|
-
echoCancellation: true,
|
|
7630
|
-
noiseSuppression: true,
|
|
7631
|
-
autoGainControl: true,
|
|
7632
|
-
sampleRate: 22050,
|
|
7633
|
-
channelCount: 1
|
|
7634
|
-
}
|
|
7635
|
-
};
|
|
7636
|
-
};
|
|
7637
|
-
const requestPermissions = async () => {
|
|
7638
|
-
try {
|
|
7639
|
-
setIsLoading(true);
|
|
7640
|
-
const constraints = getAudioConstraints();
|
|
7641
|
-
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7642
|
-
setPermission(true);
|
|
7643
|
-
setStream(streamData);
|
|
7644
|
-
}
|
|
7645
|
-
catch (err) {
|
|
7646
|
-
console.error('Microphone permission denied:', err);
|
|
7647
|
-
setPermission(false);
|
|
7648
|
-
}
|
|
7649
|
-
finally {
|
|
7650
|
-
setIsLoading(false);
|
|
7651
|
-
}
|
|
7652
|
-
};
|
|
7653
|
-
react.useEffect(() => {
|
|
7654
|
-
void requestPermissions();
|
|
7655
|
-
}, []);
|
|
7656
|
-
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7657
7718
|
};// spinner animation
|
|
7658
7719
|
const spinnerStyle = `
|
|
7659
7720
|
@keyframes spin {
|
|
@@ -7681,7 +7742,7 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
|
|
|
7681
7742
|
const [state, setState] = react.useState('preparation');
|
|
7682
7743
|
const [prepTimer, setPrepTimer] = react.useState(PREP_SECONDS);
|
|
7683
7744
|
const [recordTimer, setRecordTimer] = react.useState(RECORD_SECONDS);
|
|
7684
|
-
const [digits, setDigits] = react.useState(generateRandomDigits(
|
|
7745
|
+
const [digits, setDigits] = react.useState(generateRandomDigits(10));
|
|
7685
7746
|
const [audioLevel, setAudioLevel] = react.useState(0);
|
|
7686
7747
|
const [waveformData, setWaveformData] = react.useState([]);
|
|
7687
7748
|
const { permission, stream, stopStreamTracks, requestPermissions, isLoading } = useAudioPermissions();
|
|
@@ -7768,7 +7829,7 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
|
|
|
7768
7829
|
}
|
|
7769
7830
|
}, [state, recordTimer]);
|
|
7770
7831
|
const startRecording = async () => {
|
|
7771
|
-
setDigits(generateRandomDigits(
|
|
7832
|
+
setDigits(generateRandomDigits(10));
|
|
7772
7833
|
setRecordTimer(RECORD_SECONDS);
|
|
7773
7834
|
setState('countdown');
|
|
7774
7835
|
};
|
|
@@ -7865,16 +7926,16 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
|
|
|
7865
7926
|
const numberRow = {
|
|
7866
7927
|
display: 'flex',
|
|
7867
7928
|
justifyContent: 'center',
|
|
7868
|
-
gap:
|
|
7929
|
+
gap: 6,
|
|
7869
7930
|
margin: '16px 0 24px 0',
|
|
7870
7931
|
};
|
|
7871
7932
|
const numberBox = {
|
|
7872
|
-
minWidth:
|
|
7873
|
-
minHeight:
|
|
7933
|
+
minWidth: 24,
|
|
7934
|
+
minHeight: 32,
|
|
7874
7935
|
background: '#f5f5f5',
|
|
7875
7936
|
border: '2px solid #333',
|
|
7876
|
-
borderRadius:
|
|
7877
|
-
fontSize:
|
|
7937
|
+
borderRadius: 4,
|
|
7938
|
+
fontSize: 16,
|
|
7878
7939
|
fontWeight: 600,
|
|
7879
7940
|
color: '#333',
|
|
7880
7941
|
display: 'flex',
|
|
@@ -7983,7 +8044,7 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
|
|
|
7983
8044
|
justifyContent: 'center',
|
|
7984
8045
|
height: '120px',
|
|
7985
8046
|
gap: '2px',
|
|
7986
|
-
}, children: waveformData.map((value, index) => (jsxRuntime.jsx("div", { style: waveformBar(value / 255) }, index))) }) }), jsxRuntime.jsx("div", { style: timerStyle, children: recordTimer }), jsxRuntime.jsx("div", { style: guidanceText, children: "Speak clearly into your microphone" })] }))] })] }), jsxRuntime.jsx("div", { style: numberRow, children: (state === 'recording' ? digits : Array(
|
|
8047
|
+
}, children: waveformData.map((value, index) => (jsxRuntime.jsx("div", { style: waveformBar(value / 255) }, index))) }) }), jsxRuntime.jsx("div", { style: timerStyle, children: recordTimer }), jsxRuntime.jsx("div", { style: guidanceText, children: "Speak clearly into your microphone" })] }))] })] }), jsxRuntime.jsx("div", { style: numberRow, children: (state === 'recording' ? digits : Array(10).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: "voicerecorder-processing", style: preview, children: jsxRuntime.jsxs("div", { style: {
|
|
7987
8048
|
display: 'flex',
|
|
7988
8049
|
flexDirection: 'column',
|
|
7989
8050
|
alignItems: 'center',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "biometry-react-components",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
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",
|