biometry-react-components 1.2.4 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +123 -244
- package/dist/index.js +123 -244
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,21 +85,19 @@ function FaceCapture() {
|
|
|
85
85
|
|
|
86
86
|
### FaceRecorder
|
|
87
87
|
|
|
88
|
-
Records video with facial guidance overlay. This component could be used for [Process Video](https://developer.biometrysolutions.com/api/process-video/)
|
|
88
|
+
Records video with facial guidance overlay and displays 10 random numbers (0-9) for the user to read aloud. Automatically extracts audio from the recorded video. This component could be used for [Process Video](https://developer.biometrysolutions.com/api/process-video/) and [Voice Enrollment](https://developer.biometrysolutions.com/api/voice-enrollment/)
|
|
89
89
|
|
|
90
90
|
```tsx
|
|
91
91
|
import { FaceRecorder } from 'biometry-react-components';
|
|
92
92
|
|
|
93
93
|
function FaceRecorder() {
|
|
94
|
-
const handleCapture = (video: File,
|
|
94
|
+
const handleCapture = (video: File, audio: File, phrase: string) => {
|
|
95
95
|
console.log('Captured video:', video);
|
|
96
|
-
console.log('Captured face image:', face);
|
|
97
96
|
console.log('Captured audio:', audio);
|
|
98
97
|
console.log('Phrase:', phrase);
|
|
99
98
|
// Send files to your endpoint that will process the biometric data
|
|
100
99
|
// or
|
|
101
100
|
// const response = await sdk.processVideo(video, phrase, userFullName);
|
|
102
|
-
// const faceResponse = await sdk.enrollFace(face, userFullName);
|
|
103
101
|
// const voiceResponse = await sdk.enrollVoice(audio, userFullName);
|
|
104
102
|
};
|
|
105
103
|
|
|
@@ -111,7 +109,7 @@ function FaceRecorder() {
|
|
|
111
109
|
|
|
112
110
|
| Prop | Type | Default | Description |
|
|
113
111
|
|------|------|---------|-------------|
|
|
114
|
-
| `onCapture` | `(video: File,
|
|
112
|
+
| `onCapture` | `(video: File, audio: File, phrase: string) => void` | **required** | Callback with captured video file, audio file, and phrase |
|
|
115
113
|
| `rectWidth` | `number` | `360` | Width of camera area |
|
|
116
114
|
| `rectHeight` | `number` | `576` | Height of camera area |
|
|
117
115
|
| `className` | `string` | - | Custom CSS class |
|
|
@@ -142,7 +140,7 @@ function VoiceRecorder() {
|
|
|
142
140
|
|
|
143
141
|
| Prop | Type | Default | Description |
|
|
144
142
|
|------|------|---------|-------------|
|
|
145
|
-
| `onCapture` | `(file: File) => void` | **required** | Callback with captured audio file |
|
|
143
|
+
| `onCapture` | `(file: File, phrase: string) => void` | **required** | Callback with captured audio file and phrase |
|
|
146
144
|
| `rectWidth` | `number` | `360` | Width of component area |
|
|
147
145
|
| `rectHeight` | `number` | `undefined` | Height of component area (optional) |
|
|
148
146
|
| `className` | `string` | - | Custom CSS class |
|
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: (file: 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
|
@@ -7060,23 +7060,7 @@ function numberToWord(num) {
|
|
|
7060
7060
|
}
|
|
7061
7061
|
function numbersToPhrase(numbers) {
|
|
7062
7062
|
return numbers.map(numberToWord).join(' ');
|
|
7063
|
-
}
|
|
7064
|
-
const VIDEO_READY_STATES = {
|
|
7065
|
-
// 0 means the video element is not ready
|
|
7066
|
-
// 1 means the video element is ready
|
|
7067
|
-
// 2 means the video element is loading
|
|
7068
|
-
// 3 means the video element is ended
|
|
7069
|
-
// 4 means the video element is seeking
|
|
7070
|
-
// 5 means the video element is paused
|
|
7071
|
-
// 6 means the video element is playing
|
|
7072
|
-
0: 'not ready',
|
|
7073
|
-
1: 'ready',
|
|
7074
|
-
2: 'loading',
|
|
7075
|
-
3: 'ended',
|
|
7076
|
-
4: 'seeking',
|
|
7077
|
-
5: 'paused',
|
|
7078
|
-
6: 'playing'
|
|
7079
|
-
};const useRecorder = (stream, type, onStopRecording) => {
|
|
7063
|
+
}const useRecorder = (stream, type, onStopRecording) => {
|
|
7080
7064
|
const [isRecording, setIsRecording] = useState(false);
|
|
7081
7065
|
const recorderRef = useRef(null);
|
|
7082
7066
|
const timeoutRef = useRef(null);
|
|
@@ -7265,77 +7249,6 @@ const VIDEO_READY_STATES = {
|
|
|
7265
7249
|
void requestPermissions();
|
|
7266
7250
|
}, [rectWidth, rectHeight]);
|
|
7267
7251
|
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7268
|
-
};const useAudioPermissions = () => {
|
|
7269
|
-
const [permission, setPermission] = useState(false);
|
|
7270
|
-
const [stream, setStream] = useState(null);
|
|
7271
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
7272
|
-
const stopStreamTracks = () => {
|
|
7273
|
-
if (stream) {
|
|
7274
|
-
stream.getTracks().forEach(track => {
|
|
7275
|
-
track.stop();
|
|
7276
|
-
});
|
|
7277
|
-
setStream(null);
|
|
7278
|
-
}
|
|
7279
|
-
};
|
|
7280
|
-
const getAudioConstraints = () => {
|
|
7281
|
-
// Detect device capabilities and choose appropriate quality
|
|
7282
|
-
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7283
|
-
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7284
|
-
// High-end device settings
|
|
7285
|
-
if (!isMobile && !isLowEndDevice) {
|
|
7286
|
-
return {
|
|
7287
|
-
audio: {
|
|
7288
|
-
echoCancellation: true,
|
|
7289
|
-
noiseSuppression: true,
|
|
7290
|
-
autoGainControl: true,
|
|
7291
|
-
sampleRate: 48000,
|
|
7292
|
-
channelCount: 2
|
|
7293
|
-
}
|
|
7294
|
-
};
|
|
7295
|
-
}
|
|
7296
|
-
// Mobile device settings
|
|
7297
|
-
if (isMobile) {
|
|
7298
|
-
return {
|
|
7299
|
-
audio: {
|
|
7300
|
-
echoCancellation: true,
|
|
7301
|
-
noiseSuppression: true,
|
|
7302
|
-
autoGainControl: true,
|
|
7303
|
-
sampleRate: 22050, // Lower for mobile
|
|
7304
|
-
channelCount: 1
|
|
7305
|
-
}
|
|
7306
|
-
};
|
|
7307
|
-
}
|
|
7308
|
-
// Low-end device settings
|
|
7309
|
-
return {
|
|
7310
|
-
audio: {
|
|
7311
|
-
echoCancellation: true,
|
|
7312
|
-
noiseSuppression: true,
|
|
7313
|
-
autoGainControl: true,
|
|
7314
|
-
sampleRate: 22050,
|
|
7315
|
-
channelCount: 1
|
|
7316
|
-
}
|
|
7317
|
-
};
|
|
7318
|
-
};
|
|
7319
|
-
const requestPermissions = async () => {
|
|
7320
|
-
try {
|
|
7321
|
-
setIsLoading(true);
|
|
7322
|
-
const constraints = getAudioConstraints();
|
|
7323
|
-
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7324
|
-
setPermission(true);
|
|
7325
|
-
setStream(streamData);
|
|
7326
|
-
}
|
|
7327
|
-
catch (err) {
|
|
7328
|
-
console.error('Microphone permission denied:', err);
|
|
7329
|
-
setPermission(false);
|
|
7330
|
-
}
|
|
7331
|
-
finally {
|
|
7332
|
-
setIsLoading(false);
|
|
7333
|
-
}
|
|
7334
|
-
};
|
|
7335
|
-
useEffect(() => {
|
|
7336
|
-
void requestPermissions();
|
|
7337
|
-
}, []);
|
|
7338
|
-
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7339
7252
|
};// spinner animation
|
|
7340
7253
|
const spinnerStyle$1 = `
|
|
7341
7254
|
@keyframes spin {
|
|
@@ -7356,7 +7269,6 @@ if (typeof window !== 'undefined' && typeof console !== 'undefined') {
|
|
|
7356
7269
|
}
|
|
7357
7270
|
const RECORD_SECONDS$1 = 10;
|
|
7358
7271
|
const PREP_SECONDS$1 = 3;
|
|
7359
|
-
const FACE_CAPTURE_SECOND = 5;
|
|
7360
7272
|
function generateRandomDigits$1(count) {
|
|
7361
7273
|
const digits = Array.from({ length: 10 }, (_, i) => i);
|
|
7362
7274
|
for (let i = digits.length - 1; i > 0; i--) {
|
|
@@ -7371,37 +7283,28 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7371
7283
|
const [recordTimer, setRecordTimer] = useState(RECORD_SECONDS$1);
|
|
7372
7284
|
const [digits, setDigits] = useState(generateRandomDigits$1(10));
|
|
7373
7285
|
const { permission, stream, stopStreamTracks, requestPermissions, isLoading } = usePermissions({ rectWidth, rectHeight });
|
|
7374
|
-
const { permission: audioPermission, stream: audioStream, stopStreamTracks: stopAudioStreamTracks, requestPermissions: requestAudioPermissions, isLoading: audioIsLoading } = useAudioPermissions();
|
|
7375
7286
|
const [videoBlob, setVideoBlob] = useState(null);
|
|
7376
|
-
const [videoUrl, setVideoUrl] = useState(null);
|
|
7377
7287
|
const [audioBlob, setAudioBlob] = useState(null);
|
|
7378
|
-
const [
|
|
7288
|
+
const [videoUrl, setVideoUrl] = useState(null);
|
|
7379
7289
|
const [isConfirming, setIsConfirming] = useState(false);
|
|
7380
|
-
const [faceCaptured, setFaceCaptured] = useState(false);
|
|
7381
|
-
const [isReinitializing, setIsReinitializing] = useState(false);
|
|
7382
7290
|
const videoRef = useRef(null);
|
|
7383
7291
|
const previewRef = useRef(null);
|
|
7384
|
-
|
|
7292
|
+
// Video recorder
|
|
7385
7293
|
const { startRecording: startVideoRecording, cancelRecording: cancelVideoRecording } = useRecorder(stream, "video", (blob) => {
|
|
7386
|
-
stopStreamTracks();
|
|
7387
7294
|
if (blob && blob.size > 0) {
|
|
7388
7295
|
setVideoBlob(blob);
|
|
7389
7296
|
const url = URL.createObjectURL(blob);
|
|
7390
7297
|
setVideoUrl(url);
|
|
7391
|
-
setState('result');
|
|
7392
|
-
setIsConfirming(true);
|
|
7393
7298
|
}
|
|
7394
7299
|
else {
|
|
7395
7300
|
const dummyBlob = new Blob(['dummy video data'], { type: 'video/webm' });
|
|
7396
7301
|
setVideoBlob(dummyBlob);
|
|
7397
7302
|
const url = URL.createObjectURL(dummyBlob);
|
|
7398
7303
|
setVideoUrl(url);
|
|
7399
|
-
setState('result');
|
|
7400
|
-
setIsConfirming(true);
|
|
7401
7304
|
}
|
|
7402
7305
|
});
|
|
7403
|
-
|
|
7404
|
-
|
|
7306
|
+
// Audio recorder
|
|
7307
|
+
const { startRecording: startAudioRecording, cancelRecording: cancelAudioRecording } = useRecorder(stream, "audio", (blob) => {
|
|
7405
7308
|
if (blob && blob.size > 0) {
|
|
7406
7309
|
setAudioBlob(blob);
|
|
7407
7310
|
}
|
|
@@ -7409,92 +7312,28 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7409
7312
|
const dummyBlob = new Blob(['dummy audio data'], { type: 'audio/webm' });
|
|
7410
7313
|
setAudioBlob(dummyBlob);
|
|
7411
7314
|
}
|
|
7315
|
+
// Only show result when both recordings are done
|
|
7316
|
+
// Video callback will be called first, then audio
|
|
7317
|
+
stopStreamTracks();
|
|
7318
|
+
setState('result');
|
|
7319
|
+
setIsConfirming(true);
|
|
7412
7320
|
});
|
|
7413
|
-
const captureFaceImage = () => {
|
|
7414
|
-
if (videoRef.current && canvasRef.current && !faceCaptured) {
|
|
7415
|
-
const video = videoRef.current;
|
|
7416
|
-
const canvas = canvasRef.current;
|
|
7417
|
-
const ctx = canvas.getContext('2d');
|
|
7418
|
-
if (ctx) {
|
|
7419
|
-
canvas.width = video.videoWidth;
|
|
7420
|
-
canvas.height = video.videoHeight;
|
|
7421
|
-
ctx.drawImage(video, 0, 0);
|
|
7422
|
-
canvas.toBlob((blob) => {
|
|
7423
|
-
if (blob) {
|
|
7424
|
-
setFaceImageBlob(blob);
|
|
7425
|
-
setFaceCaptured(true);
|
|
7426
|
-
}
|
|
7427
|
-
}, 'image/jpeg', 0.9);
|
|
7428
|
-
}
|
|
7429
|
-
}
|
|
7430
|
-
};
|
|
7431
7321
|
useEffect(() => {
|
|
7432
7322
|
let isMounted = true;
|
|
7433
7323
|
console.log('Camera setup useEffect - state:', state, 'isConfirming:', isConfirming);
|
|
7434
7324
|
if (!isConfirming && state !== 'result' && stream) {
|
|
7435
7325
|
console.log('Setting up video element with stream');
|
|
7436
7326
|
if (videoRef.current && isMounted) {
|
|
7437
|
-
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
const handleLoadedMetadata = () => {
|
|
7327
|
+
videoRef.current.srcObject = stream;
|
|
7328
|
+
videoRef.current.onloadedmetadata = () => {
|
|
7329
|
+
var _a;
|
|
7441
7330
|
console.log('Video metadata loaded, playing...');
|
|
7442
|
-
|
|
7443
|
-
videoElement.play().catch(err => {
|
|
7444
|
-
console.error('Failed to play video:', err);
|
|
7445
|
-
});
|
|
7446
|
-
}
|
|
7447
|
-
};
|
|
7448
|
-
const handleCanPlay = () => {
|
|
7449
|
-
console.log('Video can play');
|
|
7450
|
-
if (videoElement && videoElement.paused) {
|
|
7451
|
-
videoElement.play().catch(err => {
|
|
7452
|
-
console.error('Failed to play video on canplay:', err);
|
|
7453
|
-
});
|
|
7454
|
-
}
|
|
7455
|
-
};
|
|
7456
|
-
videoElement.onloadedmetadata = handleLoadedMetadata;
|
|
7457
|
-
videoElement.oncanplay = handleCanPlay;
|
|
7458
|
-
// Also try to play immediately if the stream is already ready
|
|
7459
|
-
if (stream.active) {
|
|
7460
|
-
console.log('Stream is active, attempting immediate play');
|
|
7461
|
-
// Ensure video element is ready
|
|
7462
|
-
if (videoElement.readyState >= 1) {
|
|
7463
|
-
videoElement.play().catch(err => {
|
|
7464
|
-
console.error('Failed to play video immediately:', err);
|
|
7465
|
-
});
|
|
7466
|
-
}
|
|
7467
|
-
else {
|
|
7468
|
-
console.log('Video element not ready yet, waiting for metadata');
|
|
7469
|
-
}
|
|
7470
|
-
}
|
|
7471
|
-
// Fallback: try to play after a short delay if not already playing
|
|
7472
|
-
const fallbackTimer = setTimeout(() => {
|
|
7473
|
-
if (videoElement && videoElement.paused) {
|
|
7474
|
-
console.log('Fallback: attempting to play video after delay');
|
|
7475
|
-
videoElement.play().catch(err => {
|
|
7476
|
-
console.error('Failed to play video in fallback:', err);
|
|
7477
|
-
});
|
|
7478
|
-
}
|
|
7479
|
-
}, 1000);
|
|
7480
|
-
return () => {
|
|
7481
|
-
clearTimeout(fallbackTimer);
|
|
7482
|
-
if (videoElement) {
|
|
7483
|
-
videoElement.onloadedmetadata = null;
|
|
7484
|
-
videoElement.oncanplay = null;
|
|
7485
|
-
}
|
|
7331
|
+
(_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.play();
|
|
7486
7332
|
};
|
|
7487
7333
|
}
|
|
7488
7334
|
console.log('Stream ref set successfully');
|
|
7489
7335
|
}
|
|
7490
7336
|
}, [isConfirming, state, stream]);
|
|
7491
|
-
// Auto-start countdown when streams become available after reinitialization
|
|
7492
|
-
useEffect(() => {
|
|
7493
|
-
if (state === 'preparation' && stream && audioStream && !isConfirming && isReinitializing) {
|
|
7494
|
-
console.log('Streams reinitialized, ready for next recording');
|
|
7495
|
-
setIsReinitializing(false);
|
|
7496
|
-
}
|
|
7497
|
-
}, [state, stream, audioStream, isConfirming, isReinitializing]);
|
|
7498
7337
|
// Preparation countdown
|
|
7499
7338
|
useEffect(() => {
|
|
7500
7339
|
console.log('Countdown useEffect - state:', state, 'prepTimer:', prepTimer);
|
|
@@ -7504,31 +7343,19 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7504
7343
|
return () => clearTimeout(t);
|
|
7505
7344
|
}
|
|
7506
7345
|
else {
|
|
7507
|
-
// Ensure streams are available before starting recording
|
|
7508
|
-
if (!stream || !audioStream) {
|
|
7509
|
-
console.error('Streams not available for recording, resetting to preparation');
|
|
7510
|
-
setState('preparation');
|
|
7511
|
-
setPrepTimer(PREP_SECONDS$1);
|
|
7512
|
-
return;
|
|
7513
|
-
}
|
|
7514
7346
|
setState('recording');
|
|
7515
7347
|
setPrepTimer(PREP_SECONDS$1);
|
|
7348
|
+
// Start both video and audio recording simultaneously
|
|
7516
7349
|
startVideoRecording();
|
|
7517
7350
|
startAudioRecording();
|
|
7518
7351
|
}
|
|
7519
7352
|
}
|
|
7520
|
-
}, [state, prepTimer, startVideoRecording, startAudioRecording
|
|
7353
|
+
}, [state, prepTimer, startVideoRecording, startAudioRecording]);
|
|
7521
7354
|
// Recording timer
|
|
7522
7355
|
useEffect(() => {
|
|
7523
7356
|
if (state === 'recording') {
|
|
7524
7357
|
if (recordTimer > 0) {
|
|
7525
|
-
const t = setTimeout(() =>
|
|
7526
|
-
const newTimer = recordTimer - 1;
|
|
7527
|
-
setRecordTimer(newTimer);
|
|
7528
|
-
if (newTimer === RECORD_SECONDS$1 - FACE_CAPTURE_SECOND) {
|
|
7529
|
-
captureFaceImage();
|
|
7530
|
-
}
|
|
7531
|
-
}, 1000);
|
|
7358
|
+
const t = setTimeout(() => setRecordTimer(recordTimer - 1), 1000);
|
|
7532
7359
|
return () => clearTimeout(t);
|
|
7533
7360
|
}
|
|
7534
7361
|
else {
|
|
@@ -7537,65 +7364,45 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7537
7364
|
}
|
|
7538
7365
|
}, [state, recordTimer]);
|
|
7539
7366
|
const startRecording = async () => {
|
|
7540
|
-
// Don't start if streams are being reinitialized
|
|
7541
|
-
if (isReinitializing) {
|
|
7542
|
-
console.log('Streams are being reinitialized, please wait...');
|
|
7543
|
-
return;
|
|
7544
|
-
}
|
|
7545
|
-
// Ensure streams are available before starting
|
|
7546
|
-
if (!stream || !audioStream) {
|
|
7547
|
-
console.log('Streams not available, requesting permissions...');
|
|
7548
|
-
setIsReinitializing(true);
|
|
7549
|
-
await requestPermissions();
|
|
7550
|
-
await requestAudioPermissions();
|
|
7551
|
-
// Wait a bit for streams to initialize
|
|
7552
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
7553
|
-
// Check again after waiting
|
|
7554
|
-
if (!stream || !audioStream) {
|
|
7555
|
-
console.error('Streams still not available after requesting permissions');
|
|
7556
|
-
setIsReinitializing(false);
|
|
7557
|
-
return;
|
|
7558
|
-
}
|
|
7559
|
-
}
|
|
7560
7367
|
setDigits(generateRandomDigits$1(10));
|
|
7561
7368
|
setRecordTimer(RECORD_SECONDS$1);
|
|
7562
|
-
setFaceCaptured(false);
|
|
7563
7369
|
setState('countdown');
|
|
7564
7370
|
};
|
|
7565
7371
|
const handleCancel = () => {
|
|
7372
|
+
// Cancel both recordings first
|
|
7566
7373
|
cancelVideoRecording();
|
|
7567
7374
|
cancelAudioRecording();
|
|
7375
|
+
// Then stop stream and reset state
|
|
7568
7376
|
stopStreamTracks();
|
|
7569
|
-
stopAudioStreamTracks();
|
|
7570
7377
|
setState('preparation');
|
|
7571
7378
|
setIsConfirming(false);
|
|
7572
7379
|
setVideoUrl(null);
|
|
7573
7380
|
setVideoBlob(null);
|
|
7574
7381
|
setAudioBlob(null);
|
|
7575
|
-
|
|
7576
|
-
|
|
7382
|
+
// Reset digits for next recording
|
|
7383
|
+
setDigits(generateRandomDigits$1(10));
|
|
7384
|
+
// Restart the stream for cancellation
|
|
7577
7385
|
requestPermissions();
|
|
7578
|
-
requestAudioPermissions();
|
|
7579
7386
|
};
|
|
7580
7387
|
const handleConfirm = () => {
|
|
7581
|
-
if (videoBlob && audioBlob
|
|
7388
|
+
if (videoBlob && audioBlob) {
|
|
7389
|
+
// Create file objects
|
|
7582
7390
|
const videoFile = new File([videoBlob], 'face-video.webm', { type: videoBlob.type });
|
|
7583
7391
|
const audioFile = new File([audioBlob], 'face-audio.webm', { type: audioBlob.type });
|
|
7584
|
-
|
|
7585
|
-
onCapture(videoFile,
|
|
7392
|
+
// Call onCapture immediately with both files
|
|
7393
|
+
onCapture(videoFile, audioFile, numbersToPhrase(digits));
|
|
7394
|
+
// Clean up and reset state
|
|
7586
7395
|
if (videoUrl)
|
|
7587
7396
|
URL.revokeObjectURL(videoUrl);
|
|
7588
7397
|
setVideoUrl(null);
|
|
7589
7398
|
setVideoBlob(null);
|
|
7590
7399
|
setAudioBlob(null);
|
|
7591
|
-
setFaceImageBlob(null);
|
|
7592
|
-
setFaceCaptured(false);
|
|
7593
7400
|
setIsConfirming(false);
|
|
7594
7401
|
setState('preparation');
|
|
7595
|
-
|
|
7596
|
-
|
|
7402
|
+
// Reset digits for next recording
|
|
7403
|
+
setDigits(generateRandomDigits$1(10));
|
|
7404
|
+
// Restart stream for next recording
|
|
7597
7405
|
requestPermissions();
|
|
7598
|
-
requestAudioPermissions();
|
|
7599
7406
|
}
|
|
7600
7407
|
};
|
|
7601
7408
|
const handleDecline = () => {
|
|
@@ -7604,12 +7411,12 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7604
7411
|
setVideoUrl(null);
|
|
7605
7412
|
setVideoBlob(null);
|
|
7606
7413
|
setAudioBlob(null);
|
|
7607
|
-
setFaceImageBlob(null);
|
|
7608
|
-
setFaceCaptured(false);
|
|
7609
7414
|
setIsConfirming(false);
|
|
7610
7415
|
setState('preparation');
|
|
7416
|
+
// Reset digits for next recording
|
|
7417
|
+
setDigits(generateRandomDigits$1(10));
|
|
7418
|
+
// Restart the stream for retake
|
|
7611
7419
|
requestPermissions();
|
|
7612
|
-
requestAudioPermissions();
|
|
7613
7420
|
};
|
|
7614
7421
|
const wrapperStyle = {
|
|
7615
7422
|
background: '#fff',
|
|
@@ -7644,7 +7451,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7644
7451
|
transform: 'translateX(-50%)',
|
|
7645
7452
|
width: '72%',
|
|
7646
7453
|
height: '68%',
|
|
7647
|
-
zIndex:
|
|
7454
|
+
zIndex: 2,
|
|
7648
7455
|
display: 'flex',
|
|
7649
7456
|
flexDirection: 'column',
|
|
7650
7457
|
alignItems: 'center',
|
|
@@ -7676,16 +7483,16 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7676
7483
|
justifyContent: 'center',
|
|
7677
7484
|
gap: 4,
|
|
7678
7485
|
margin: '16px 0 24px 0',
|
|
7679
|
-
|
|
7486
|
+
width: '100%',
|
|
7680
7487
|
maxWidth: rectWidth - 40,
|
|
7681
7488
|
};
|
|
7682
7489
|
const numberBox = {
|
|
7683
|
-
minWidth:
|
|
7684
|
-
minHeight:
|
|
7490
|
+
minWidth: 24,
|
|
7491
|
+
minHeight: 32,
|
|
7685
7492
|
background: '#f5f5f5',
|
|
7686
7493
|
border: '2px solid #333',
|
|
7687
7494
|
borderRadius: 4,
|
|
7688
|
-
fontSize:
|
|
7495
|
+
fontSize: 16,
|
|
7689
7496
|
fontWeight: 600,
|
|
7690
7497
|
color: '#333',
|
|
7691
7498
|
display: 'flex',
|
|
@@ -7693,6 +7500,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7693
7500
|
justifyContent: 'center',
|
|
7694
7501
|
boxShadow: '0 1px 4px rgba(0,0,0,0.08)',
|
|
7695
7502
|
transition: 'background 0.3s',
|
|
7503
|
+
flex: '1',
|
|
7504
|
+
maxWidth: '28px',
|
|
7696
7505
|
};
|
|
7697
7506
|
const timerStyle = {
|
|
7698
7507
|
position: 'absolute',
|
|
@@ -7704,7 +7513,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7704
7513
|
fontWeight: 600,
|
|
7705
7514
|
borderRadius: 8,
|
|
7706
7515
|
padding: '4px 14px',
|
|
7707
|
-
zIndex:
|
|
7516
|
+
zIndex: 10,
|
|
7708
7517
|
transition: 'all 0.3s',
|
|
7709
7518
|
letterSpacing: 1.5,
|
|
7710
7519
|
};
|
|
@@ -7717,7 +7526,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7717
7526
|
fontSize: 64,
|
|
7718
7527
|
fontWeight: 700,
|
|
7719
7528
|
textShadow: '0 2px 12px rgba(0,0,0,0.25)',
|
|
7720
|
-
zIndex:
|
|
7529
|
+
zIndex: 20,
|
|
7721
7530
|
transition: 'all 0.3s',
|
|
7722
7531
|
pointerEvents: 'none',
|
|
7723
7532
|
};
|
|
@@ -7762,7 +7571,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7762
7571
|
transition: 'background 0.2s',
|
|
7763
7572
|
margin: '0 8px',
|
|
7764
7573
|
};
|
|
7765
|
-
|
|
7574
|
+
// Show loading state while checking permissions
|
|
7575
|
+
if (isLoading) {
|
|
7766
7576
|
return (jsx("div", { className: className, style: wrapperStyle, children: jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsx("div", { style: {
|
|
7767
7577
|
width: 48,
|
|
7768
7578
|
height: 48,
|
|
@@ -7771,28 +7581,26 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7771
7581
|
borderRadius: '50%',
|
|
7772
7582
|
animation: 'spin 1s linear infinite',
|
|
7773
7583
|
margin: '0 auto 16px auto',
|
|
7774
|
-
} }), jsx("h3", { children:
|
|
7584
|
+
} }), jsx("h3", { children: "Initializing Camera..." }), jsx("p", { children: "Please wait while we set up your camera." })] }) }));
|
|
7775
7585
|
}
|
|
7776
|
-
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
requestAudioPermissions();
|
|
7780
|
-
}, children: "Grant Permissions" })] }) }));
|
|
7586
|
+
// Show permission request if no permission
|
|
7587
|
+
if (!permission) {
|
|
7588
|
+
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" })] }) }));
|
|
7781
7589
|
}
|
|
7782
|
-
return (jsxs("div", { className: className, style: wrapperStyle, children: [
|
|
7590
|
+
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: {
|
|
7783
7591
|
width: rectWidth - 40,
|
|
7784
7592
|
height: rectHeight - 40,
|
|
7785
7593
|
objectFit: 'cover',
|
|
7786
7594
|
borderRadius: noShadow ? 0 : 8,
|
|
7787
|
-
zIndex:
|
|
7788
|
-
}, playsInline: true, muted: true, autoPlay: true
|
|
7595
|
+
zIndex: 0,
|
|
7596
|
+
}, playsInline: true, muted: true, autoPlay: true }), jsx("div", { className: "facerecorder-dark-overlay", style: {
|
|
7789
7597
|
position: 'absolute',
|
|
7790
7598
|
top: 0,
|
|
7791
7599
|
left: 0,
|
|
7792
7600
|
width: '100%',
|
|
7793
7601
|
height: '100%',
|
|
7794
7602
|
background: 'rgba(0,0,0,0.4)',
|
|
7795
|
-
zIndex:
|
|
7603
|
+
zIndex: 1,
|
|
7796
7604
|
borderRadius: noShadow ? 0 : 8,
|
|
7797
7605
|
} }), 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: {
|
|
7798
7606
|
display: 'flex',
|
|
@@ -7815,6 +7623,77 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7815
7623
|
borderRadius: 8,
|
|
7816
7624
|
objectFit: 'cover'
|
|
7817
7625
|
}, 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" })] }) })] })] }))] }));
|
|
7626
|
+
};const useAudioPermissions = () => {
|
|
7627
|
+
const [permission, setPermission] = useState(false);
|
|
7628
|
+
const [stream, setStream] = useState(null);
|
|
7629
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
7630
|
+
const stopStreamTracks = () => {
|
|
7631
|
+
if (stream) {
|
|
7632
|
+
stream.getTracks().forEach(track => {
|
|
7633
|
+
track.stop();
|
|
7634
|
+
});
|
|
7635
|
+
setStream(null);
|
|
7636
|
+
}
|
|
7637
|
+
};
|
|
7638
|
+
const getAudioConstraints = () => {
|
|
7639
|
+
// Detect device capabilities and choose appropriate quality
|
|
7640
|
+
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7641
|
+
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7642
|
+
// High-end device settings
|
|
7643
|
+
if (!isMobile && !isLowEndDevice) {
|
|
7644
|
+
return {
|
|
7645
|
+
audio: {
|
|
7646
|
+
echoCancellation: true,
|
|
7647
|
+
noiseSuppression: true,
|
|
7648
|
+
autoGainControl: true,
|
|
7649
|
+
sampleRate: 48000,
|
|
7650
|
+
channelCount: 2
|
|
7651
|
+
}
|
|
7652
|
+
};
|
|
7653
|
+
}
|
|
7654
|
+
// Mobile device settings
|
|
7655
|
+
if (isMobile) {
|
|
7656
|
+
return {
|
|
7657
|
+
audio: {
|
|
7658
|
+
echoCancellation: true,
|
|
7659
|
+
noiseSuppression: true,
|
|
7660
|
+
autoGainControl: true,
|
|
7661
|
+
sampleRate: 22050, // Lower for mobile
|
|
7662
|
+
channelCount: 1
|
|
7663
|
+
}
|
|
7664
|
+
};
|
|
7665
|
+
}
|
|
7666
|
+
// Low-end device settings
|
|
7667
|
+
return {
|
|
7668
|
+
audio: {
|
|
7669
|
+
echoCancellation: true,
|
|
7670
|
+
noiseSuppression: true,
|
|
7671
|
+
autoGainControl: true,
|
|
7672
|
+
sampleRate: 22050,
|
|
7673
|
+
channelCount: 1
|
|
7674
|
+
}
|
|
7675
|
+
};
|
|
7676
|
+
};
|
|
7677
|
+
const requestPermissions = async () => {
|
|
7678
|
+
try {
|
|
7679
|
+
setIsLoading(true);
|
|
7680
|
+
const constraints = getAudioConstraints();
|
|
7681
|
+
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7682
|
+
setPermission(true);
|
|
7683
|
+
setStream(streamData);
|
|
7684
|
+
}
|
|
7685
|
+
catch (err) {
|
|
7686
|
+
console.error('Microphone permission denied:', err);
|
|
7687
|
+
setPermission(false);
|
|
7688
|
+
}
|
|
7689
|
+
finally {
|
|
7690
|
+
setIsLoading(false);
|
|
7691
|
+
}
|
|
7692
|
+
};
|
|
7693
|
+
useEffect(() => {
|
|
7694
|
+
void requestPermissions();
|
|
7695
|
+
}, []);
|
|
7696
|
+
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7818
7697
|
};// spinner animation
|
|
7819
7698
|
const spinnerStyle = `
|
|
7820
7699
|
@keyframes spin {
|
package/dist/index.js
CHANGED
|
@@ -7060,23 +7060,7 @@ function numberToWord(num) {
|
|
|
7060
7060
|
}
|
|
7061
7061
|
function numbersToPhrase(numbers) {
|
|
7062
7062
|
return numbers.map(numberToWord).join(' ');
|
|
7063
|
-
}
|
|
7064
|
-
const VIDEO_READY_STATES = {
|
|
7065
|
-
// 0 means the video element is not ready
|
|
7066
|
-
// 1 means the video element is ready
|
|
7067
|
-
// 2 means the video element is loading
|
|
7068
|
-
// 3 means the video element is ended
|
|
7069
|
-
// 4 means the video element is seeking
|
|
7070
|
-
// 5 means the video element is paused
|
|
7071
|
-
// 6 means the video element is playing
|
|
7072
|
-
0: 'not ready',
|
|
7073
|
-
1: 'ready',
|
|
7074
|
-
2: 'loading',
|
|
7075
|
-
3: 'ended',
|
|
7076
|
-
4: 'seeking',
|
|
7077
|
-
5: 'paused',
|
|
7078
|
-
6: 'playing'
|
|
7079
|
-
};const useRecorder = (stream, type, onStopRecording) => {
|
|
7063
|
+
}const useRecorder = (stream, type, onStopRecording) => {
|
|
7080
7064
|
const [isRecording, setIsRecording] = react.useState(false);
|
|
7081
7065
|
const recorderRef = react.useRef(null);
|
|
7082
7066
|
const timeoutRef = react.useRef(null);
|
|
@@ -7265,77 +7249,6 @@ const VIDEO_READY_STATES = {
|
|
|
7265
7249
|
void requestPermissions();
|
|
7266
7250
|
}, [rectWidth, rectHeight]);
|
|
7267
7251
|
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7268
|
-
};const useAudioPermissions = () => {
|
|
7269
|
-
const [permission, setPermission] = react.useState(false);
|
|
7270
|
-
const [stream, setStream] = react.useState(null);
|
|
7271
|
-
const [isLoading, setIsLoading] = react.useState(true);
|
|
7272
|
-
const stopStreamTracks = () => {
|
|
7273
|
-
if (stream) {
|
|
7274
|
-
stream.getTracks().forEach(track => {
|
|
7275
|
-
track.stop();
|
|
7276
|
-
});
|
|
7277
|
-
setStream(null);
|
|
7278
|
-
}
|
|
7279
|
-
};
|
|
7280
|
-
const getAudioConstraints = () => {
|
|
7281
|
-
// Detect device capabilities and choose appropriate quality
|
|
7282
|
-
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7283
|
-
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7284
|
-
// High-end device settings
|
|
7285
|
-
if (!isMobile && !isLowEndDevice) {
|
|
7286
|
-
return {
|
|
7287
|
-
audio: {
|
|
7288
|
-
echoCancellation: true,
|
|
7289
|
-
noiseSuppression: true,
|
|
7290
|
-
autoGainControl: true,
|
|
7291
|
-
sampleRate: 48000,
|
|
7292
|
-
channelCount: 2
|
|
7293
|
-
}
|
|
7294
|
-
};
|
|
7295
|
-
}
|
|
7296
|
-
// Mobile device settings
|
|
7297
|
-
if (isMobile) {
|
|
7298
|
-
return {
|
|
7299
|
-
audio: {
|
|
7300
|
-
echoCancellation: true,
|
|
7301
|
-
noiseSuppression: true,
|
|
7302
|
-
autoGainControl: true,
|
|
7303
|
-
sampleRate: 22050, // Lower for mobile
|
|
7304
|
-
channelCount: 1
|
|
7305
|
-
}
|
|
7306
|
-
};
|
|
7307
|
-
}
|
|
7308
|
-
// Low-end device settings
|
|
7309
|
-
return {
|
|
7310
|
-
audio: {
|
|
7311
|
-
echoCancellation: true,
|
|
7312
|
-
noiseSuppression: true,
|
|
7313
|
-
autoGainControl: true,
|
|
7314
|
-
sampleRate: 22050,
|
|
7315
|
-
channelCount: 1
|
|
7316
|
-
}
|
|
7317
|
-
};
|
|
7318
|
-
};
|
|
7319
|
-
const requestPermissions = async () => {
|
|
7320
|
-
try {
|
|
7321
|
-
setIsLoading(true);
|
|
7322
|
-
const constraints = getAudioConstraints();
|
|
7323
|
-
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7324
|
-
setPermission(true);
|
|
7325
|
-
setStream(streamData);
|
|
7326
|
-
}
|
|
7327
|
-
catch (err) {
|
|
7328
|
-
console.error('Microphone permission denied:', err);
|
|
7329
|
-
setPermission(false);
|
|
7330
|
-
}
|
|
7331
|
-
finally {
|
|
7332
|
-
setIsLoading(false);
|
|
7333
|
-
}
|
|
7334
|
-
};
|
|
7335
|
-
react.useEffect(() => {
|
|
7336
|
-
void requestPermissions();
|
|
7337
|
-
}, []);
|
|
7338
|
-
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7339
7252
|
};// spinner animation
|
|
7340
7253
|
const spinnerStyle$1 = `
|
|
7341
7254
|
@keyframes spin {
|
|
@@ -7356,7 +7269,6 @@ if (typeof window !== 'undefined' && typeof console !== 'undefined') {
|
|
|
7356
7269
|
}
|
|
7357
7270
|
const RECORD_SECONDS$1 = 10;
|
|
7358
7271
|
const PREP_SECONDS$1 = 3;
|
|
7359
|
-
const FACE_CAPTURE_SECOND = 5;
|
|
7360
7272
|
function generateRandomDigits$1(count) {
|
|
7361
7273
|
const digits = Array.from({ length: 10 }, (_, i) => i);
|
|
7362
7274
|
for (let i = digits.length - 1; i > 0; i--) {
|
|
@@ -7371,37 +7283,28 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7371
7283
|
const [recordTimer, setRecordTimer] = react.useState(RECORD_SECONDS$1);
|
|
7372
7284
|
const [digits, setDigits] = react.useState(generateRandomDigits$1(10));
|
|
7373
7285
|
const { permission, stream, stopStreamTracks, requestPermissions, isLoading } = usePermissions({ rectWidth, rectHeight });
|
|
7374
|
-
const { permission: audioPermission, stream: audioStream, stopStreamTracks: stopAudioStreamTracks, requestPermissions: requestAudioPermissions, isLoading: audioIsLoading } = useAudioPermissions();
|
|
7375
7286
|
const [videoBlob, setVideoBlob] = react.useState(null);
|
|
7376
|
-
const [videoUrl, setVideoUrl] = react.useState(null);
|
|
7377
7287
|
const [audioBlob, setAudioBlob] = react.useState(null);
|
|
7378
|
-
const [
|
|
7288
|
+
const [videoUrl, setVideoUrl] = react.useState(null);
|
|
7379
7289
|
const [isConfirming, setIsConfirming] = react.useState(false);
|
|
7380
|
-
const [faceCaptured, setFaceCaptured] = react.useState(false);
|
|
7381
|
-
const [isReinitializing, setIsReinitializing] = react.useState(false);
|
|
7382
7290
|
const videoRef = react.useRef(null);
|
|
7383
7291
|
const previewRef = react.useRef(null);
|
|
7384
|
-
|
|
7292
|
+
// Video recorder
|
|
7385
7293
|
const { startRecording: startVideoRecording, cancelRecording: cancelVideoRecording } = useRecorder(stream, "video", (blob) => {
|
|
7386
|
-
stopStreamTracks();
|
|
7387
7294
|
if (blob && blob.size > 0) {
|
|
7388
7295
|
setVideoBlob(blob);
|
|
7389
7296
|
const url = URL.createObjectURL(blob);
|
|
7390
7297
|
setVideoUrl(url);
|
|
7391
|
-
setState('result');
|
|
7392
|
-
setIsConfirming(true);
|
|
7393
7298
|
}
|
|
7394
7299
|
else {
|
|
7395
7300
|
const dummyBlob = new Blob(['dummy video data'], { type: 'video/webm' });
|
|
7396
7301
|
setVideoBlob(dummyBlob);
|
|
7397
7302
|
const url = URL.createObjectURL(dummyBlob);
|
|
7398
7303
|
setVideoUrl(url);
|
|
7399
|
-
setState('result');
|
|
7400
|
-
setIsConfirming(true);
|
|
7401
7304
|
}
|
|
7402
7305
|
});
|
|
7403
|
-
|
|
7404
|
-
|
|
7306
|
+
// Audio recorder
|
|
7307
|
+
const { startRecording: startAudioRecording, cancelRecording: cancelAudioRecording } = useRecorder(stream, "audio", (blob) => {
|
|
7405
7308
|
if (blob && blob.size > 0) {
|
|
7406
7309
|
setAudioBlob(blob);
|
|
7407
7310
|
}
|
|
@@ -7409,92 +7312,28 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7409
7312
|
const dummyBlob = new Blob(['dummy audio data'], { type: 'audio/webm' });
|
|
7410
7313
|
setAudioBlob(dummyBlob);
|
|
7411
7314
|
}
|
|
7315
|
+
// Only show result when both recordings are done
|
|
7316
|
+
// Video callback will be called first, then audio
|
|
7317
|
+
stopStreamTracks();
|
|
7318
|
+
setState('result');
|
|
7319
|
+
setIsConfirming(true);
|
|
7412
7320
|
});
|
|
7413
|
-
const captureFaceImage = () => {
|
|
7414
|
-
if (videoRef.current && canvasRef.current && !faceCaptured) {
|
|
7415
|
-
const video = videoRef.current;
|
|
7416
|
-
const canvas = canvasRef.current;
|
|
7417
|
-
const ctx = canvas.getContext('2d');
|
|
7418
|
-
if (ctx) {
|
|
7419
|
-
canvas.width = video.videoWidth;
|
|
7420
|
-
canvas.height = video.videoHeight;
|
|
7421
|
-
ctx.drawImage(video, 0, 0);
|
|
7422
|
-
canvas.toBlob((blob) => {
|
|
7423
|
-
if (blob) {
|
|
7424
|
-
setFaceImageBlob(blob);
|
|
7425
|
-
setFaceCaptured(true);
|
|
7426
|
-
}
|
|
7427
|
-
}, 'image/jpeg', 0.9);
|
|
7428
|
-
}
|
|
7429
|
-
}
|
|
7430
|
-
};
|
|
7431
7321
|
react.useEffect(() => {
|
|
7432
7322
|
let isMounted = true;
|
|
7433
7323
|
console.log('Camera setup useEffect - state:', state, 'isConfirming:', isConfirming);
|
|
7434
7324
|
if (!isConfirming && state !== 'result' && stream) {
|
|
7435
7325
|
console.log('Setting up video element with stream');
|
|
7436
7326
|
if (videoRef.current && isMounted) {
|
|
7437
|
-
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
const handleLoadedMetadata = () => {
|
|
7327
|
+
videoRef.current.srcObject = stream;
|
|
7328
|
+
videoRef.current.onloadedmetadata = () => {
|
|
7329
|
+
var _a;
|
|
7441
7330
|
console.log('Video metadata loaded, playing...');
|
|
7442
|
-
|
|
7443
|
-
videoElement.play().catch(err => {
|
|
7444
|
-
console.error('Failed to play video:', err);
|
|
7445
|
-
});
|
|
7446
|
-
}
|
|
7447
|
-
};
|
|
7448
|
-
const handleCanPlay = () => {
|
|
7449
|
-
console.log('Video can play');
|
|
7450
|
-
if (videoElement && videoElement.paused) {
|
|
7451
|
-
videoElement.play().catch(err => {
|
|
7452
|
-
console.error('Failed to play video on canplay:', err);
|
|
7453
|
-
});
|
|
7454
|
-
}
|
|
7455
|
-
};
|
|
7456
|
-
videoElement.onloadedmetadata = handleLoadedMetadata;
|
|
7457
|
-
videoElement.oncanplay = handleCanPlay;
|
|
7458
|
-
// Also try to play immediately if the stream is already ready
|
|
7459
|
-
if (stream.active) {
|
|
7460
|
-
console.log('Stream is active, attempting immediate play');
|
|
7461
|
-
// Ensure video element is ready
|
|
7462
|
-
if (videoElement.readyState >= 1) {
|
|
7463
|
-
videoElement.play().catch(err => {
|
|
7464
|
-
console.error('Failed to play video immediately:', err);
|
|
7465
|
-
});
|
|
7466
|
-
}
|
|
7467
|
-
else {
|
|
7468
|
-
console.log('Video element not ready yet, waiting for metadata');
|
|
7469
|
-
}
|
|
7470
|
-
}
|
|
7471
|
-
// Fallback: try to play after a short delay if not already playing
|
|
7472
|
-
const fallbackTimer = setTimeout(() => {
|
|
7473
|
-
if (videoElement && videoElement.paused) {
|
|
7474
|
-
console.log('Fallback: attempting to play video after delay');
|
|
7475
|
-
videoElement.play().catch(err => {
|
|
7476
|
-
console.error('Failed to play video in fallback:', err);
|
|
7477
|
-
});
|
|
7478
|
-
}
|
|
7479
|
-
}, 1000);
|
|
7480
|
-
return () => {
|
|
7481
|
-
clearTimeout(fallbackTimer);
|
|
7482
|
-
if (videoElement) {
|
|
7483
|
-
videoElement.onloadedmetadata = null;
|
|
7484
|
-
videoElement.oncanplay = null;
|
|
7485
|
-
}
|
|
7331
|
+
(_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.play();
|
|
7486
7332
|
};
|
|
7487
7333
|
}
|
|
7488
7334
|
console.log('Stream ref set successfully');
|
|
7489
7335
|
}
|
|
7490
7336
|
}, [isConfirming, state, stream]);
|
|
7491
|
-
// Auto-start countdown when streams become available after reinitialization
|
|
7492
|
-
react.useEffect(() => {
|
|
7493
|
-
if (state === 'preparation' && stream && audioStream && !isConfirming && isReinitializing) {
|
|
7494
|
-
console.log('Streams reinitialized, ready for next recording');
|
|
7495
|
-
setIsReinitializing(false);
|
|
7496
|
-
}
|
|
7497
|
-
}, [state, stream, audioStream, isConfirming, isReinitializing]);
|
|
7498
7337
|
// Preparation countdown
|
|
7499
7338
|
react.useEffect(() => {
|
|
7500
7339
|
console.log('Countdown useEffect - state:', state, 'prepTimer:', prepTimer);
|
|
@@ -7504,31 +7343,19 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7504
7343
|
return () => clearTimeout(t);
|
|
7505
7344
|
}
|
|
7506
7345
|
else {
|
|
7507
|
-
// Ensure streams are available before starting recording
|
|
7508
|
-
if (!stream || !audioStream) {
|
|
7509
|
-
console.error('Streams not available for recording, resetting to preparation');
|
|
7510
|
-
setState('preparation');
|
|
7511
|
-
setPrepTimer(PREP_SECONDS$1);
|
|
7512
|
-
return;
|
|
7513
|
-
}
|
|
7514
7346
|
setState('recording');
|
|
7515
7347
|
setPrepTimer(PREP_SECONDS$1);
|
|
7348
|
+
// Start both video and audio recording simultaneously
|
|
7516
7349
|
startVideoRecording();
|
|
7517
7350
|
startAudioRecording();
|
|
7518
7351
|
}
|
|
7519
7352
|
}
|
|
7520
|
-
}, [state, prepTimer, startVideoRecording, startAudioRecording
|
|
7353
|
+
}, [state, prepTimer, startVideoRecording, startAudioRecording]);
|
|
7521
7354
|
// Recording timer
|
|
7522
7355
|
react.useEffect(() => {
|
|
7523
7356
|
if (state === 'recording') {
|
|
7524
7357
|
if (recordTimer > 0) {
|
|
7525
|
-
const t = setTimeout(() =>
|
|
7526
|
-
const newTimer = recordTimer - 1;
|
|
7527
|
-
setRecordTimer(newTimer);
|
|
7528
|
-
if (newTimer === RECORD_SECONDS$1 - FACE_CAPTURE_SECOND) {
|
|
7529
|
-
captureFaceImage();
|
|
7530
|
-
}
|
|
7531
|
-
}, 1000);
|
|
7358
|
+
const t = setTimeout(() => setRecordTimer(recordTimer - 1), 1000);
|
|
7532
7359
|
return () => clearTimeout(t);
|
|
7533
7360
|
}
|
|
7534
7361
|
else {
|
|
@@ -7537,65 +7364,45 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7537
7364
|
}
|
|
7538
7365
|
}, [state, recordTimer]);
|
|
7539
7366
|
const startRecording = async () => {
|
|
7540
|
-
// Don't start if streams are being reinitialized
|
|
7541
|
-
if (isReinitializing) {
|
|
7542
|
-
console.log('Streams are being reinitialized, please wait...');
|
|
7543
|
-
return;
|
|
7544
|
-
}
|
|
7545
|
-
// Ensure streams are available before starting
|
|
7546
|
-
if (!stream || !audioStream) {
|
|
7547
|
-
console.log('Streams not available, requesting permissions...');
|
|
7548
|
-
setIsReinitializing(true);
|
|
7549
|
-
await requestPermissions();
|
|
7550
|
-
await requestAudioPermissions();
|
|
7551
|
-
// Wait a bit for streams to initialize
|
|
7552
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
7553
|
-
// Check again after waiting
|
|
7554
|
-
if (!stream || !audioStream) {
|
|
7555
|
-
console.error('Streams still not available after requesting permissions');
|
|
7556
|
-
setIsReinitializing(false);
|
|
7557
|
-
return;
|
|
7558
|
-
}
|
|
7559
|
-
}
|
|
7560
7367
|
setDigits(generateRandomDigits$1(10));
|
|
7561
7368
|
setRecordTimer(RECORD_SECONDS$1);
|
|
7562
|
-
setFaceCaptured(false);
|
|
7563
7369
|
setState('countdown');
|
|
7564
7370
|
};
|
|
7565
7371
|
const handleCancel = () => {
|
|
7372
|
+
// Cancel both recordings first
|
|
7566
7373
|
cancelVideoRecording();
|
|
7567
7374
|
cancelAudioRecording();
|
|
7375
|
+
// Then stop stream and reset state
|
|
7568
7376
|
stopStreamTracks();
|
|
7569
|
-
stopAudioStreamTracks();
|
|
7570
7377
|
setState('preparation');
|
|
7571
7378
|
setIsConfirming(false);
|
|
7572
7379
|
setVideoUrl(null);
|
|
7573
7380
|
setVideoBlob(null);
|
|
7574
7381
|
setAudioBlob(null);
|
|
7575
|
-
|
|
7576
|
-
|
|
7382
|
+
// Reset digits for next recording
|
|
7383
|
+
setDigits(generateRandomDigits$1(10));
|
|
7384
|
+
// Restart the stream for cancellation
|
|
7577
7385
|
requestPermissions();
|
|
7578
|
-
requestAudioPermissions();
|
|
7579
7386
|
};
|
|
7580
7387
|
const handleConfirm = () => {
|
|
7581
|
-
if (videoBlob && audioBlob
|
|
7388
|
+
if (videoBlob && audioBlob) {
|
|
7389
|
+
// Create file objects
|
|
7582
7390
|
const videoFile = new File([videoBlob], 'face-video.webm', { type: videoBlob.type });
|
|
7583
7391
|
const audioFile = new File([audioBlob], 'face-audio.webm', { type: audioBlob.type });
|
|
7584
|
-
|
|
7585
|
-
onCapture(videoFile,
|
|
7392
|
+
// Call onCapture immediately with both files
|
|
7393
|
+
onCapture(videoFile, audioFile, numbersToPhrase(digits));
|
|
7394
|
+
// Clean up and reset state
|
|
7586
7395
|
if (videoUrl)
|
|
7587
7396
|
URL.revokeObjectURL(videoUrl);
|
|
7588
7397
|
setVideoUrl(null);
|
|
7589
7398
|
setVideoBlob(null);
|
|
7590
7399
|
setAudioBlob(null);
|
|
7591
|
-
setFaceImageBlob(null);
|
|
7592
|
-
setFaceCaptured(false);
|
|
7593
7400
|
setIsConfirming(false);
|
|
7594
7401
|
setState('preparation');
|
|
7595
|
-
|
|
7596
|
-
|
|
7402
|
+
// Reset digits for next recording
|
|
7403
|
+
setDigits(generateRandomDigits$1(10));
|
|
7404
|
+
// Restart stream for next recording
|
|
7597
7405
|
requestPermissions();
|
|
7598
|
-
requestAudioPermissions();
|
|
7599
7406
|
}
|
|
7600
7407
|
};
|
|
7601
7408
|
const handleDecline = () => {
|
|
@@ -7604,12 +7411,12 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7604
7411
|
setVideoUrl(null);
|
|
7605
7412
|
setVideoBlob(null);
|
|
7606
7413
|
setAudioBlob(null);
|
|
7607
|
-
setFaceImageBlob(null);
|
|
7608
|
-
setFaceCaptured(false);
|
|
7609
7414
|
setIsConfirming(false);
|
|
7610
7415
|
setState('preparation');
|
|
7416
|
+
// Reset digits for next recording
|
|
7417
|
+
setDigits(generateRandomDigits$1(10));
|
|
7418
|
+
// Restart the stream for retake
|
|
7611
7419
|
requestPermissions();
|
|
7612
|
-
requestAudioPermissions();
|
|
7613
7420
|
};
|
|
7614
7421
|
const wrapperStyle = {
|
|
7615
7422
|
background: '#fff',
|
|
@@ -7644,7 +7451,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7644
7451
|
transform: 'translateX(-50%)',
|
|
7645
7452
|
width: '72%',
|
|
7646
7453
|
height: '68%',
|
|
7647
|
-
zIndex:
|
|
7454
|
+
zIndex: 2,
|
|
7648
7455
|
display: 'flex',
|
|
7649
7456
|
flexDirection: 'column',
|
|
7650
7457
|
alignItems: 'center',
|
|
@@ -7676,16 +7483,16 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7676
7483
|
justifyContent: 'center',
|
|
7677
7484
|
gap: 4,
|
|
7678
7485
|
margin: '16px 0 24px 0',
|
|
7679
|
-
|
|
7486
|
+
width: '100%',
|
|
7680
7487
|
maxWidth: rectWidth - 40,
|
|
7681
7488
|
};
|
|
7682
7489
|
const numberBox = {
|
|
7683
|
-
minWidth:
|
|
7684
|
-
minHeight:
|
|
7490
|
+
minWidth: 24,
|
|
7491
|
+
minHeight: 32,
|
|
7685
7492
|
background: '#f5f5f5',
|
|
7686
7493
|
border: '2px solid #333',
|
|
7687
7494
|
borderRadius: 4,
|
|
7688
|
-
fontSize:
|
|
7495
|
+
fontSize: 16,
|
|
7689
7496
|
fontWeight: 600,
|
|
7690
7497
|
color: '#333',
|
|
7691
7498
|
display: 'flex',
|
|
@@ -7693,6 +7500,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7693
7500
|
justifyContent: 'center',
|
|
7694
7501
|
boxShadow: '0 1px 4px rgba(0,0,0,0.08)',
|
|
7695
7502
|
transition: 'background 0.3s',
|
|
7503
|
+
flex: '1',
|
|
7504
|
+
maxWidth: '28px',
|
|
7696
7505
|
};
|
|
7697
7506
|
const timerStyle = {
|
|
7698
7507
|
position: 'absolute',
|
|
@@ -7704,7 +7513,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7704
7513
|
fontWeight: 600,
|
|
7705
7514
|
borderRadius: 8,
|
|
7706
7515
|
padding: '4px 14px',
|
|
7707
|
-
zIndex:
|
|
7516
|
+
zIndex: 10,
|
|
7708
7517
|
transition: 'all 0.3s',
|
|
7709
7518
|
letterSpacing: 1.5,
|
|
7710
7519
|
};
|
|
@@ -7717,7 +7526,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7717
7526
|
fontSize: 64,
|
|
7718
7527
|
fontWeight: 700,
|
|
7719
7528
|
textShadow: '0 2px 12px rgba(0,0,0,0.25)',
|
|
7720
|
-
zIndex:
|
|
7529
|
+
zIndex: 20,
|
|
7721
7530
|
transition: 'all 0.3s',
|
|
7722
7531
|
pointerEvents: 'none',
|
|
7723
7532
|
};
|
|
@@ -7762,7 +7571,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7762
7571
|
transition: 'background 0.2s',
|
|
7763
7572
|
margin: '0 8px',
|
|
7764
7573
|
};
|
|
7765
|
-
|
|
7574
|
+
// Show loading state while checking permissions
|
|
7575
|
+
if (isLoading) {
|
|
7766
7576
|
return (jsxRuntime.jsx("div", { className: className, style: wrapperStyle, children: jsxRuntime.jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsxRuntime.jsx("div", { style: {
|
|
7767
7577
|
width: 48,
|
|
7768
7578
|
height: 48,
|
|
@@ -7771,28 +7581,26 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7771
7581
|
borderRadius: '50%',
|
|
7772
7582
|
animation: 'spin 1s linear infinite',
|
|
7773
7583
|
margin: '0 auto 16px auto',
|
|
7774
|
-
} }), jsxRuntime.jsx("h3", { children:
|
|
7584
|
+
} }), jsxRuntime.jsx("h3", { children: "Initializing Camera..." }), jsxRuntime.jsx("p", { children: "Please wait while we set up your camera." })] }) }));
|
|
7775
7585
|
}
|
|
7776
|
-
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
requestAudioPermissions();
|
|
7780
|
-
}, children: "Grant Permissions" })] }) }));
|
|
7586
|
+
// Show permission request if no permission
|
|
7587
|
+
if (!permission) {
|
|
7588
|
+
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" })] }) }));
|
|
7781
7589
|
}
|
|
7782
|
-
return (jsxRuntime.jsxs("div", { className: className, style: wrapperStyle, children: [
|
|
7590
|
+
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: {
|
|
7783
7591
|
width: rectWidth - 40,
|
|
7784
7592
|
height: rectHeight - 40,
|
|
7785
7593
|
objectFit: 'cover',
|
|
7786
7594
|
borderRadius: noShadow ? 0 : 8,
|
|
7787
|
-
zIndex:
|
|
7788
|
-
}, playsInline: true, muted: true, autoPlay: true
|
|
7595
|
+
zIndex: 0,
|
|
7596
|
+
}, playsInline: true, muted: true, autoPlay: true }), jsxRuntime.jsx("div", { className: "facerecorder-dark-overlay", style: {
|
|
7789
7597
|
position: 'absolute',
|
|
7790
7598
|
top: 0,
|
|
7791
7599
|
left: 0,
|
|
7792
7600
|
width: '100%',
|
|
7793
7601
|
height: '100%',
|
|
7794
7602
|
background: 'rgba(0,0,0,0.4)',
|
|
7795
|
-
zIndex:
|
|
7603
|
+
zIndex: 1,
|
|
7796
7604
|
borderRadius: noShadow ? 0 : 8,
|
|
7797
7605
|
} }), 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: {
|
|
7798
7606
|
display: 'flex',
|
|
@@ -7815,6 +7623,77 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7815
7623
|
borderRadius: 8,
|
|
7816
7624
|
objectFit: 'cover'
|
|
7817
7625
|
}, 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" })] }) })] })] }))] }));
|
|
7626
|
+
};const useAudioPermissions = () => {
|
|
7627
|
+
const [permission, setPermission] = react.useState(false);
|
|
7628
|
+
const [stream, setStream] = react.useState(null);
|
|
7629
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
7630
|
+
const stopStreamTracks = () => {
|
|
7631
|
+
if (stream) {
|
|
7632
|
+
stream.getTracks().forEach(track => {
|
|
7633
|
+
track.stop();
|
|
7634
|
+
});
|
|
7635
|
+
setStream(null);
|
|
7636
|
+
}
|
|
7637
|
+
};
|
|
7638
|
+
const getAudioConstraints = () => {
|
|
7639
|
+
// Detect device capabilities and choose appropriate quality
|
|
7640
|
+
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7641
|
+
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7642
|
+
// High-end device settings
|
|
7643
|
+
if (!isMobile && !isLowEndDevice) {
|
|
7644
|
+
return {
|
|
7645
|
+
audio: {
|
|
7646
|
+
echoCancellation: true,
|
|
7647
|
+
noiseSuppression: true,
|
|
7648
|
+
autoGainControl: true,
|
|
7649
|
+
sampleRate: 48000,
|
|
7650
|
+
channelCount: 2
|
|
7651
|
+
}
|
|
7652
|
+
};
|
|
7653
|
+
}
|
|
7654
|
+
// Mobile device settings
|
|
7655
|
+
if (isMobile) {
|
|
7656
|
+
return {
|
|
7657
|
+
audio: {
|
|
7658
|
+
echoCancellation: true,
|
|
7659
|
+
noiseSuppression: true,
|
|
7660
|
+
autoGainControl: true,
|
|
7661
|
+
sampleRate: 22050, // Lower for mobile
|
|
7662
|
+
channelCount: 1
|
|
7663
|
+
}
|
|
7664
|
+
};
|
|
7665
|
+
}
|
|
7666
|
+
// Low-end device settings
|
|
7667
|
+
return {
|
|
7668
|
+
audio: {
|
|
7669
|
+
echoCancellation: true,
|
|
7670
|
+
noiseSuppression: true,
|
|
7671
|
+
autoGainControl: true,
|
|
7672
|
+
sampleRate: 22050,
|
|
7673
|
+
channelCount: 1
|
|
7674
|
+
}
|
|
7675
|
+
};
|
|
7676
|
+
};
|
|
7677
|
+
const requestPermissions = async () => {
|
|
7678
|
+
try {
|
|
7679
|
+
setIsLoading(true);
|
|
7680
|
+
const constraints = getAudioConstraints();
|
|
7681
|
+
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7682
|
+
setPermission(true);
|
|
7683
|
+
setStream(streamData);
|
|
7684
|
+
}
|
|
7685
|
+
catch (err) {
|
|
7686
|
+
console.error('Microphone permission denied:', err);
|
|
7687
|
+
setPermission(false);
|
|
7688
|
+
}
|
|
7689
|
+
finally {
|
|
7690
|
+
setIsLoading(false);
|
|
7691
|
+
}
|
|
7692
|
+
};
|
|
7693
|
+
react.useEffect(() => {
|
|
7694
|
+
void requestPermissions();
|
|
7695
|
+
}, []);
|
|
7696
|
+
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7818
7697
|
};// spinner animation
|
|
7819
7698
|
const spinnerStyle = `
|
|
7820
7699
|
@keyframes spin {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "biometry-react-components",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
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",
|