biometry-react-components 1.2.5 → 1.2.7
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 +162 -328
- package/dist/index.js +162 -328
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -7156,6 +7156,99 @@ function numbersToPhrase(numbers) {
|
|
|
7156
7156
|
}
|
|
7157
7157
|
};
|
|
7158
7158
|
return { isRecording, startRecording, stopRecording, cancelRecording };
|
|
7159
|
+
};const usePermissions = ({ rectWidth = 1920, rectHeight = 1080 } = {}) => {
|
|
7160
|
+
const [permission, setPermission] = useState(false);
|
|
7161
|
+
const [stream, setStream] = useState(null);
|
|
7162
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
7163
|
+
const stopStreamTracks = () => {
|
|
7164
|
+
if (stream) {
|
|
7165
|
+
stream.getTracks().forEach(track => {
|
|
7166
|
+
track.stop();
|
|
7167
|
+
});
|
|
7168
|
+
setStream(null);
|
|
7169
|
+
}
|
|
7170
|
+
};
|
|
7171
|
+
const getAdaptiveConstraints = () => {
|
|
7172
|
+
// Detect device capabilities and choose appropriate quality
|
|
7173
|
+
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7174
|
+
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7175
|
+
// High-end device settings
|
|
7176
|
+
if (!isMobile && !isLowEndDevice) {
|
|
7177
|
+
return {
|
|
7178
|
+
audio: {
|
|
7179
|
+
echoCancellation: true,
|
|
7180
|
+
noiseSuppression: true,
|
|
7181
|
+
autoGainControl: true,
|
|
7182
|
+
sampleRate: 48000,
|
|
7183
|
+
channelCount: 2
|
|
7184
|
+
},
|
|
7185
|
+
video: {
|
|
7186
|
+
width: { ideal: Math.min(rectWidth, 1920), min: 1280 },
|
|
7187
|
+
height: { ideal: Math.min(rectHeight, 1080), min: 720 },
|
|
7188
|
+
frameRate: { ideal: 30, min: 24 },
|
|
7189
|
+
facingMode: 'user',
|
|
7190
|
+
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
7191
|
+
}
|
|
7192
|
+
};
|
|
7193
|
+
}
|
|
7194
|
+
// Mobile device settings
|
|
7195
|
+
if (isMobile) {
|
|
7196
|
+
return {
|
|
7197
|
+
audio: {
|
|
7198
|
+
echoCancellation: true,
|
|
7199
|
+
noiseSuppression: true,
|
|
7200
|
+
autoGainControl: true,
|
|
7201
|
+
sampleRate: 22050, // Lower for mobile
|
|
7202
|
+
channelCount: 1
|
|
7203
|
+
},
|
|
7204
|
+
video: {
|
|
7205
|
+
width: { ideal: Math.min(rectWidth, 1280), min: 640 },
|
|
7206
|
+
height: { ideal: Math.min(rectHeight, 720), min: 480 },
|
|
7207
|
+
frameRate: { ideal: 24, min: 15 },
|
|
7208
|
+
facingMode: 'user',
|
|
7209
|
+
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
7210
|
+
}
|
|
7211
|
+
};
|
|
7212
|
+
}
|
|
7213
|
+
// Low-end device settings
|
|
7214
|
+
return {
|
|
7215
|
+
audio: {
|
|
7216
|
+
echoCancellation: true,
|
|
7217
|
+
noiseSuppression: true,
|
|
7218
|
+
autoGainControl: true,
|
|
7219
|
+
sampleRate: 22050,
|
|
7220
|
+
channelCount: 1
|
|
7221
|
+
},
|
|
7222
|
+
video: {
|
|
7223
|
+
width: { ideal: Math.min(rectWidth, 1280), min: 640 },
|
|
7224
|
+
height: { ideal: Math.min(rectHeight, 720), min: 480 },
|
|
7225
|
+
frameRate: { ideal: 20, min: 15 },
|
|
7226
|
+
facingMode: 'user',
|
|
7227
|
+
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
7228
|
+
}
|
|
7229
|
+
};
|
|
7230
|
+
};
|
|
7231
|
+
const requestPermissions = async () => {
|
|
7232
|
+
try {
|
|
7233
|
+
setIsLoading(true);
|
|
7234
|
+
const constraints = getAdaptiveConstraints();
|
|
7235
|
+
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7236
|
+
console.log('Media stream obtained, active:', streamData.active);
|
|
7237
|
+
setPermission(true);
|
|
7238
|
+
setStream(streamData);
|
|
7239
|
+
}
|
|
7240
|
+
catch (err) {
|
|
7241
|
+
console.error('Camera/mic permission denied:', err);
|
|
7242
|
+
setPermission(false);
|
|
7243
|
+
}
|
|
7244
|
+
finally {
|
|
7245
|
+
setIsLoading(false);
|
|
7246
|
+
}
|
|
7247
|
+
};
|
|
7248
|
+
useEffect(() => {
|
|
7249
|
+
void requestPermissions();
|
|
7250
|
+
}, [rectWidth, rectHeight]);
|
|
7251
|
+
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7159
7252
|
};// spinner animation
|
|
7160
7253
|
const spinnerStyle$1 = `
|
|
7161
7254
|
@keyframes spin {
|
|
@@ -7174,9 +7267,9 @@ if (typeof window !== 'undefined' && typeof console !== 'undefined') {
|
|
|
7174
7267
|
console.log('MediaRecorder supported:', typeof MediaRecorder !== 'undefined');
|
|
7175
7268
|
console.log('getUserMedia supported:', !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia));
|
|
7176
7269
|
}
|
|
7177
|
-
const RECORD_SECONDS$1 =
|
|
7270
|
+
const RECORD_SECONDS$1 = 7;
|
|
7178
7271
|
const PREP_SECONDS$1 = 3;
|
|
7179
|
-
const
|
|
7272
|
+
const DIGITS_NUMBER$1 = 7;
|
|
7180
7273
|
function generateRandomDigits$1(count) {
|
|
7181
7274
|
const digits = Array.from({ length: 10 }, (_, i) => i);
|
|
7182
7275
|
for (let i = digits.length - 1; i > 0; i--) {
|
|
@@ -7189,87 +7282,30 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7189
7282
|
const [state, setState] = useState('preparation');
|
|
7190
7283
|
const [prepTimer, setPrepTimer] = useState(PREP_SECONDS$1);
|
|
7191
7284
|
const [recordTimer, setRecordTimer] = useState(RECORD_SECONDS$1);
|
|
7192
|
-
const [digits, setDigits] = useState(generateRandomDigits$1(
|
|
7193
|
-
const
|
|
7194
|
-
const audioStreamRef = useRef(null);
|
|
7195
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
7196
|
-
const [permission, setPermission] = useState(false);
|
|
7197
|
-
const [audioPermission, setAudioPermission] = useState(false);
|
|
7285
|
+
const [digits, setDigits] = useState(generateRandomDigits$1(DIGITS_NUMBER$1));
|
|
7286
|
+
const { permission, stream, stopStreamTracks, requestPermissions, isLoading } = usePermissions({ rectWidth, rectHeight });
|
|
7198
7287
|
const [videoBlob, setVideoBlob] = useState(null);
|
|
7199
|
-
const [videoUrl, setVideoUrl] = useState(null);
|
|
7200
7288
|
const [audioBlob, setAudioBlob] = useState(null);
|
|
7201
|
-
const [
|
|
7289
|
+
const [videoUrl, setVideoUrl] = useState(null);
|
|
7202
7290
|
const [isConfirming, setIsConfirming] = useState(false);
|
|
7203
|
-
const [faceCaptured, setFaceCaptured] = useState(false);
|
|
7204
|
-
const [isReinitializing, setIsReinitializing] = useState(false);
|
|
7205
|
-
const [streamAvailable, setStreamAvailable] = useState(false);
|
|
7206
7291
|
const videoRef = useRef(null);
|
|
7207
|
-
const requestPermissions = async () => {
|
|
7208
|
-
try {
|
|
7209
|
-
setIsLoading(true);
|
|
7210
|
-
const videoStream = await navigator.mediaDevices.getUserMedia({
|
|
7211
|
-
video: {
|
|
7212
|
-
width: rectWidth,
|
|
7213
|
-
height: rectHeight,
|
|
7214
|
-
facingMode: 'user'
|
|
7215
|
-
}
|
|
7216
|
-
});
|
|
7217
|
-
streamRef.current = videoStream;
|
|
7218
|
-
setPermission(true);
|
|
7219
|
-
}
|
|
7220
|
-
catch (err) {
|
|
7221
|
-
console.error('Video permission denied:', err);
|
|
7222
|
-
setPermission(false);
|
|
7223
|
-
}
|
|
7224
|
-
finally {
|
|
7225
|
-
setIsLoading(false);
|
|
7226
|
-
}
|
|
7227
|
-
};
|
|
7228
|
-
const requestAudioPermissions = async () => {
|
|
7229
|
-
try {
|
|
7230
|
-
const audioStream = await navigator.mediaDevices.getUserMedia({
|
|
7231
|
-
audio: {
|
|
7232
|
-
echoCancellation: true,
|
|
7233
|
-
noiseSuppression: true,
|
|
7234
|
-
autoGainControl: true
|
|
7235
|
-
}
|
|
7236
|
-
});
|
|
7237
|
-
audioStreamRef.current = audioStream;
|
|
7238
|
-
setAudioPermission(true);
|
|
7239
|
-
}
|
|
7240
|
-
catch (err) {
|
|
7241
|
-
console.error('Audio permission denied:', err);
|
|
7242
|
-
setAudioPermission(false);
|
|
7243
|
-
}
|
|
7244
|
-
};
|
|
7245
7292
|
const previewRef = useRef(null);
|
|
7246
|
-
|
|
7247
|
-
const { startRecording: startVideoRecording, cancelRecording: cancelVideoRecording } = useRecorder(
|
|
7248
|
-
if (streamRef.current) {
|
|
7249
|
-
streamRef.current.getTracks().forEach(track => track.stop());
|
|
7250
|
-
streamRef.current = null;
|
|
7251
|
-
}
|
|
7293
|
+
// Video recorder
|
|
7294
|
+
const { startRecording: startVideoRecording, cancelRecording: cancelVideoRecording } = useRecorder(stream, "video", (blob) => {
|
|
7252
7295
|
if (blob && blob.size > 0) {
|
|
7253
7296
|
setVideoBlob(blob);
|
|
7254
7297
|
const url = URL.createObjectURL(blob);
|
|
7255
7298
|
setVideoUrl(url);
|
|
7256
|
-
setState('result');
|
|
7257
|
-
setIsConfirming(true);
|
|
7258
7299
|
}
|
|
7259
7300
|
else {
|
|
7260
7301
|
const dummyBlob = new Blob(['dummy video data'], { type: 'video/webm' });
|
|
7261
7302
|
setVideoBlob(dummyBlob);
|
|
7262
7303
|
const url = URL.createObjectURL(dummyBlob);
|
|
7263
7304
|
setVideoUrl(url);
|
|
7264
|
-
setState('result');
|
|
7265
|
-
setIsConfirming(true);
|
|
7266
7305
|
}
|
|
7267
7306
|
});
|
|
7268
|
-
|
|
7269
|
-
|
|
7270
|
-
audioStreamRef.current.getTracks().forEach(track => track.stop());
|
|
7271
|
-
audioStreamRef.current = null;
|
|
7272
|
-
}
|
|
7307
|
+
// Audio recorder
|
|
7308
|
+
const { startRecording: startAudioRecording, cancelRecording: cancelAudioRecording } = useRecorder(stream, "audio", (blob) => {
|
|
7273
7309
|
if (blob && blob.size > 0) {
|
|
7274
7310
|
setAudioBlob(blob);
|
|
7275
7311
|
}
|
|
@@ -7277,100 +7313,28 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7277
7313
|
const dummyBlob = new Blob(['dummy audio data'], { type: 'audio/webm' });
|
|
7278
7314
|
setAudioBlob(dummyBlob);
|
|
7279
7315
|
}
|
|
7316
|
+
// Only show result when both recordings are done
|
|
7317
|
+
// Video callback will be called first, then audio
|
|
7318
|
+
stopStreamTracks();
|
|
7319
|
+
setState('result');
|
|
7320
|
+
setIsConfirming(true);
|
|
7280
7321
|
});
|
|
7281
|
-
const captureFaceImage = () => {
|
|
7282
|
-
if (videoRef.current && canvasRef.current && !faceCaptured) {
|
|
7283
|
-
const video = videoRef.current;
|
|
7284
|
-
const canvas = canvasRef.current;
|
|
7285
|
-
const ctx = canvas.getContext('2d');
|
|
7286
|
-
if (ctx) {
|
|
7287
|
-
canvas.width = video.videoWidth;
|
|
7288
|
-
canvas.height = video.videoHeight;
|
|
7289
|
-
ctx.drawImage(video, 0, 0);
|
|
7290
|
-
canvas.toBlob((blob) => {
|
|
7291
|
-
if (blob) {
|
|
7292
|
-
setFaceImageBlob(blob);
|
|
7293
|
-
setFaceCaptured(true);
|
|
7294
|
-
}
|
|
7295
|
-
}, 'image/jpeg', 0.9);
|
|
7296
|
-
}
|
|
7297
|
-
}
|
|
7298
|
-
};
|
|
7299
|
-
// Initialize camera and audio streams
|
|
7300
7322
|
useEffect(() => {
|
|
7301
7323
|
let isMounted = true;
|
|
7302
|
-
|
|
7303
|
-
|
|
7304
|
-
try {
|
|
7305
|
-
// Get video stream
|
|
7306
|
-
const videoStream = await navigator.mediaDevices.getUserMedia({
|
|
7307
|
-
video: {
|
|
7308
|
-
width: rectWidth,
|
|
7309
|
-
height: rectHeight,
|
|
7310
|
-
facingMode: 'user'
|
|
7311
|
-
}
|
|
7312
|
-
});
|
|
7313
|
-
// Get audio stream
|
|
7314
|
-
const audioStream = await navigator.mediaDevices.getUserMedia({
|
|
7315
|
-
audio: {
|
|
7316
|
-
echoCancellation: true,
|
|
7317
|
-
noiseSuppression: true,
|
|
7318
|
-
autoGainControl: true
|
|
7319
|
-
}
|
|
7320
|
-
});
|
|
7321
|
-
if (isMounted) {
|
|
7322
|
-
streamRef.current = videoStream;
|
|
7323
|
-
audioStreamRef.current = audioStream;
|
|
7324
|
-
setPermission(true);
|
|
7325
|
-
setAudioPermission(true);
|
|
7326
|
-
setIsLoading(false);
|
|
7327
|
-
setStreamAvailable(true);
|
|
7328
|
-
// Video element will be set up by separate useEffect
|
|
7329
|
-
}
|
|
7330
|
-
}
|
|
7331
|
-
catch (err) {
|
|
7332
|
-
console.error('Failed to get media streams:', err);
|
|
7333
|
-
setIsLoading(false);
|
|
7334
|
-
}
|
|
7335
|
-
})();
|
|
7336
|
-
}
|
|
7337
|
-
return () => {
|
|
7338
|
-
isMounted = false;
|
|
7339
|
-
if (streamRef.current) {
|
|
7340
|
-
streamRef.current.getTracks().forEach(track => track.stop());
|
|
7341
|
-
streamRef.current = null;
|
|
7342
|
-
}
|
|
7343
|
-
if (audioStreamRef.current) {
|
|
7344
|
-
audioStreamRef.current.getTracks().forEach(track => track.stop());
|
|
7345
|
-
audioStreamRef.current = null;
|
|
7346
|
-
}
|
|
7347
|
-
setStreamAvailable(false);
|
|
7348
|
-
};
|
|
7349
|
-
}, [state, isConfirming, rectWidth, rectHeight]);
|
|
7350
|
-
// Set up video element when stream becomes available
|
|
7351
|
-
useEffect(() => {
|
|
7352
|
-
console.log('Video setup useEffect - streamAvailable:', streamAvailable, 'state:', state, 'isConfirming:', isConfirming);
|
|
7353
|
-
console.log('streamRef.current:', !!streamRef.current, 'videoRef.current:', !!videoRef.current);
|
|
7354
|
-
if (streamRef.current && videoRef.current && state === 'preparation' && !isConfirming && streamAvailable) {
|
|
7355
|
-
const videoElement = videoRef.current;
|
|
7356
|
-
const stream = streamRef.current;
|
|
7324
|
+
console.log('Camera setup useEffect - state:', state, 'isConfirming:', isConfirming);
|
|
7325
|
+
if (!isConfirming && state !== 'result' && stream) {
|
|
7357
7326
|
console.log('Setting up video element with stream');
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
console.
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
|
|
7367
|
-
// Auto-start countdown when streams become available after reinitialization
|
|
7368
|
-
useEffect(() => {
|
|
7369
|
-
if (state === 'preparation' && streamRef.current && audioStreamRef.current && !isConfirming && isReinitializing) {
|
|
7370
|
-
console.log('Streams reinitialized, ready for next recording');
|
|
7371
|
-
setIsReinitializing(false);
|
|
7327
|
+
if (videoRef.current && isMounted) {
|
|
7328
|
+
videoRef.current.srcObject = stream;
|
|
7329
|
+
videoRef.current.onloadedmetadata = () => {
|
|
7330
|
+
var _a;
|
|
7331
|
+
console.log('Video metadata loaded, playing...');
|
|
7332
|
+
(_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.play();
|
|
7333
|
+
};
|
|
7334
|
+
}
|
|
7335
|
+
console.log('Stream ref set successfully');
|
|
7372
7336
|
}
|
|
7373
|
-
}, [
|
|
7337
|
+
}, [isConfirming, state, stream]);
|
|
7374
7338
|
// Preparation countdown
|
|
7375
7339
|
useEffect(() => {
|
|
7376
7340
|
console.log('Countdown useEffect - state:', state, 'prepTimer:', prepTimer);
|
|
@@ -7380,15 +7344,9 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7380
7344
|
return () => clearTimeout(t);
|
|
7381
7345
|
}
|
|
7382
7346
|
else {
|
|
7383
|
-
// Ensure streams are available before starting recording
|
|
7384
|
-
if (!streamRef.current || !audioStreamRef.current) {
|
|
7385
|
-
console.error('Streams not available for recording, resetting to preparation');
|
|
7386
|
-
setState('preparation');
|
|
7387
|
-
setPrepTimer(PREP_SECONDS$1);
|
|
7388
|
-
return;
|
|
7389
|
-
}
|
|
7390
7347
|
setState('recording');
|
|
7391
7348
|
setPrepTimer(PREP_SECONDS$1);
|
|
7349
|
+
// Start both video and audio recording simultaneously
|
|
7392
7350
|
startVideoRecording();
|
|
7393
7351
|
startAudioRecording();
|
|
7394
7352
|
}
|
|
@@ -7398,13 +7356,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7398
7356
|
useEffect(() => {
|
|
7399
7357
|
if (state === 'recording') {
|
|
7400
7358
|
if (recordTimer > 0) {
|
|
7401
|
-
const t = setTimeout(() =>
|
|
7402
|
-
const newTimer = recordTimer - 1;
|
|
7403
|
-
setRecordTimer(newTimer);
|
|
7404
|
-
if (newTimer === RECORD_SECONDS$1 - FACE_CAPTURE_SECOND) {
|
|
7405
|
-
captureFaceImage();
|
|
7406
|
-
}
|
|
7407
|
-
}, 1000);
|
|
7359
|
+
const t = setTimeout(() => setRecordTimer(recordTimer - 1), 1000);
|
|
7408
7360
|
return () => clearTimeout(t);
|
|
7409
7361
|
}
|
|
7410
7362
|
else {
|
|
@@ -7413,72 +7365,45 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7413
7365
|
}
|
|
7414
7366
|
}, [state, recordTimer]);
|
|
7415
7367
|
const startRecording = async () => {
|
|
7416
|
-
|
|
7417
|
-
if (isReinitializing) {
|
|
7418
|
-
console.log('Streams are being reinitialized, please wait...');
|
|
7419
|
-
return;
|
|
7420
|
-
}
|
|
7421
|
-
// Ensure streams are available before starting
|
|
7422
|
-
if (!streamRef.current || !audioStreamRef.current) {
|
|
7423
|
-
console.log('Streams not available, requesting permissions...');
|
|
7424
|
-
setIsReinitializing(true);
|
|
7425
|
-
await requestPermissions();
|
|
7426
|
-
await requestAudioPermissions();
|
|
7427
|
-
// Wait a bit for streams to initialize
|
|
7428
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
7429
|
-
// Check again after waiting
|
|
7430
|
-
if (!streamRef.current || !audioStreamRef.current) {
|
|
7431
|
-
console.error('Streams still not available after requesting permissions');
|
|
7432
|
-
setIsReinitializing(false);
|
|
7433
|
-
return;
|
|
7434
|
-
}
|
|
7435
|
-
}
|
|
7436
|
-
setDigits(generateRandomDigits$1(10));
|
|
7368
|
+
setDigits(generateRandomDigits$1(DIGITS_NUMBER$1));
|
|
7437
7369
|
setRecordTimer(RECORD_SECONDS$1);
|
|
7438
|
-
setFaceCaptured(false);
|
|
7439
7370
|
setState('countdown');
|
|
7440
7371
|
};
|
|
7441
7372
|
const handleCancel = () => {
|
|
7373
|
+
// Cancel both recordings first
|
|
7442
7374
|
cancelVideoRecording();
|
|
7443
7375
|
cancelAudioRecording();
|
|
7444
|
-
|
|
7445
|
-
|
|
7446
|
-
streamRef.current = null;
|
|
7447
|
-
}
|
|
7448
|
-
if (audioStreamRef.current) {
|
|
7449
|
-
audioStreamRef.current.getTracks().forEach(track => track.stop());
|
|
7450
|
-
audioStreamRef.current = null;
|
|
7451
|
-
}
|
|
7452
|
-
setStreamAvailable(false);
|
|
7376
|
+
// Then stop stream and reset state
|
|
7377
|
+
stopStreamTracks();
|
|
7453
7378
|
setState('preparation');
|
|
7454
7379
|
setIsConfirming(false);
|
|
7455
7380
|
setVideoUrl(null);
|
|
7456
7381
|
setVideoBlob(null);
|
|
7457
7382
|
setAudioBlob(null);
|
|
7458
|
-
|
|
7459
|
-
|
|
7383
|
+
// Reset digits for next recording
|
|
7384
|
+
setDigits(generateRandomDigits$1(DIGITS_NUMBER$1));
|
|
7385
|
+
// Restart the stream for cancellation
|
|
7460
7386
|
requestPermissions();
|
|
7461
|
-
requestAudioPermissions();
|
|
7462
7387
|
};
|
|
7463
7388
|
const handleConfirm = () => {
|
|
7464
|
-
if (videoBlob && audioBlob
|
|
7389
|
+
if (videoBlob && audioBlob) {
|
|
7390
|
+
// Create file objects
|
|
7465
7391
|
const videoFile = new File([videoBlob], 'face-video.webm', { type: videoBlob.type });
|
|
7466
7392
|
const audioFile = new File([audioBlob], 'face-audio.webm', { type: audioBlob.type });
|
|
7467
|
-
|
|
7468
|
-
onCapture(videoFile,
|
|
7393
|
+
// Call onCapture immediately with both files
|
|
7394
|
+
onCapture(videoFile, audioFile, numbersToPhrase(digits));
|
|
7395
|
+
// Clean up and reset state
|
|
7469
7396
|
if (videoUrl)
|
|
7470
7397
|
URL.revokeObjectURL(videoUrl);
|
|
7471
7398
|
setVideoUrl(null);
|
|
7472
7399
|
setVideoBlob(null);
|
|
7473
7400
|
setAudioBlob(null);
|
|
7474
|
-
setFaceImageBlob(null);
|
|
7475
|
-
setFaceCaptured(false);
|
|
7476
7401
|
setIsConfirming(false);
|
|
7477
7402
|
setState('preparation');
|
|
7478
|
-
|
|
7479
|
-
|
|
7403
|
+
// Reset digits for next recording
|
|
7404
|
+
setDigits(generateRandomDigits$1(DIGITS_NUMBER$1));
|
|
7405
|
+
// Restart stream for next recording
|
|
7480
7406
|
requestPermissions();
|
|
7481
|
-
requestAudioPermissions();
|
|
7482
7407
|
}
|
|
7483
7408
|
};
|
|
7484
7409
|
const handleDecline = () => {
|
|
@@ -7487,12 +7412,12 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7487
7412
|
setVideoUrl(null);
|
|
7488
7413
|
setVideoBlob(null);
|
|
7489
7414
|
setAudioBlob(null);
|
|
7490
|
-
setFaceImageBlob(null);
|
|
7491
|
-
setFaceCaptured(false);
|
|
7492
7415
|
setIsConfirming(false);
|
|
7493
7416
|
setState('preparation');
|
|
7417
|
+
// Reset digits for next recording
|
|
7418
|
+
setDigits(generateRandomDigits$1(DIGITS_NUMBER$1));
|
|
7419
|
+
// Restart the stream for retake
|
|
7494
7420
|
requestPermissions();
|
|
7495
|
-
requestAudioPermissions();
|
|
7496
7421
|
};
|
|
7497
7422
|
const wrapperStyle = {
|
|
7498
7423
|
background: '#fff',
|
|
@@ -7527,7 +7452,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7527
7452
|
transform: 'translateX(-50%)',
|
|
7528
7453
|
width: '72%',
|
|
7529
7454
|
height: '68%',
|
|
7530
|
-
zIndex:
|
|
7455
|
+
zIndex: 2,
|
|
7531
7456
|
display: 'flex',
|
|
7532
7457
|
flexDirection: 'column',
|
|
7533
7458
|
alignItems: 'center',
|
|
@@ -7559,16 +7484,16 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7559
7484
|
justifyContent: 'center',
|
|
7560
7485
|
gap: 4,
|
|
7561
7486
|
margin: '16px 0 24px 0',
|
|
7562
|
-
|
|
7487
|
+
width: '100%',
|
|
7563
7488
|
maxWidth: rectWidth - 40,
|
|
7564
7489
|
};
|
|
7565
7490
|
const numberBox = {
|
|
7566
|
-
minWidth:
|
|
7567
|
-
minHeight:
|
|
7491
|
+
minWidth: 24,
|
|
7492
|
+
minHeight: 32,
|
|
7568
7493
|
background: '#f5f5f5',
|
|
7569
7494
|
border: '2px solid #333',
|
|
7570
7495
|
borderRadius: 4,
|
|
7571
|
-
fontSize:
|
|
7496
|
+
fontSize: 16,
|
|
7572
7497
|
fontWeight: 600,
|
|
7573
7498
|
color: '#333',
|
|
7574
7499
|
display: 'flex',
|
|
@@ -7576,6 +7501,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7576
7501
|
justifyContent: 'center',
|
|
7577
7502
|
boxShadow: '0 1px 4px rgba(0,0,0,0.08)',
|
|
7578
7503
|
transition: 'background 0.3s',
|
|
7504
|
+
flex: '1',
|
|
7505
|
+
maxWidth: '28px',
|
|
7579
7506
|
};
|
|
7580
7507
|
const timerStyle = {
|
|
7581
7508
|
position: 'absolute',
|
|
@@ -7587,7 +7514,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7587
7514
|
fontWeight: 600,
|
|
7588
7515
|
borderRadius: 8,
|
|
7589
7516
|
padding: '4px 14px',
|
|
7590
|
-
zIndex:
|
|
7517
|
+
zIndex: 10,
|
|
7591
7518
|
transition: 'all 0.3s',
|
|
7592
7519
|
letterSpacing: 1.5,
|
|
7593
7520
|
};
|
|
@@ -7600,7 +7527,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7600
7527
|
fontSize: 64,
|
|
7601
7528
|
fontWeight: 700,
|
|
7602
7529
|
textShadow: '0 2px 12px rgba(0,0,0,0.25)',
|
|
7603
|
-
zIndex:
|
|
7530
|
+
zIndex: 20,
|
|
7604
7531
|
transition: 'all 0.3s',
|
|
7605
7532
|
pointerEvents: 'none',
|
|
7606
7533
|
};
|
|
@@ -7645,7 +7572,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7645
7572
|
transition: 'background 0.2s',
|
|
7646
7573
|
margin: '0 8px',
|
|
7647
7574
|
};
|
|
7648
|
-
|
|
7575
|
+
// Show loading state while checking permissions
|
|
7576
|
+
if (isLoading) {
|
|
7649
7577
|
return (jsx("div", { className: className, style: wrapperStyle, children: jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsx("div", { style: {
|
|
7650
7578
|
width: 48,
|
|
7651
7579
|
height: 48,
|
|
@@ -7654,28 +7582,26 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7654
7582
|
borderRadius: '50%',
|
|
7655
7583
|
animation: 'spin 1s linear infinite',
|
|
7656
7584
|
margin: '0 auto 16px auto',
|
|
7657
|
-
} }), jsx("h3", { children:
|
|
7585
|
+
} }), jsx("h3", { children: "Initializing Camera..." }), jsx("p", { children: "Please wait while we set up your camera." })] }) }));
|
|
7658
7586
|
}
|
|
7659
|
-
|
|
7660
|
-
|
|
7661
|
-
|
|
7662
|
-
requestAudioPermissions();
|
|
7663
|
-
}, children: "Grant Permissions" })] }) }));
|
|
7587
|
+
// Show permission request if no permission
|
|
7588
|
+
if (!permission) {
|
|
7589
|
+
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" })] }) }));
|
|
7664
7590
|
}
|
|
7665
|
-
return (jsxs("div", { className: className, style: wrapperStyle, children: [
|
|
7591
|
+
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: {
|
|
7666
7592
|
width: rectWidth - 40,
|
|
7667
7593
|
height: rectHeight - 40,
|
|
7668
7594
|
objectFit: 'cover',
|
|
7669
7595
|
borderRadius: noShadow ? 0 : 8,
|
|
7670
|
-
zIndex:
|
|
7671
|
-
}, playsInline: true, muted: true, autoPlay: true
|
|
7596
|
+
zIndex: 0,
|
|
7597
|
+
}, playsInline: true, muted: true, autoPlay: true }), jsx("div", { className: "facerecorder-dark-overlay", style: {
|
|
7672
7598
|
position: 'absolute',
|
|
7673
7599
|
top: 0,
|
|
7674
7600
|
left: 0,
|
|
7675
7601
|
width: '100%',
|
|
7676
7602
|
height: '100%',
|
|
7677
7603
|
background: 'rgba(0,0,0,0.4)',
|
|
7678
|
-
zIndex:
|
|
7604
|
+
zIndex: 1,
|
|
7679
7605
|
borderRadius: noShadow ? 0 : 8,
|
|
7680
7606
|
} }), 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: {
|
|
7681
7607
|
display: 'flex',
|
|
@@ -7782,8 +7708,9 @@ if (typeof document !== 'undefined') {
|
|
|
7782
7708
|
style.textContent = spinnerStyle;
|
|
7783
7709
|
document.head.appendChild(style);
|
|
7784
7710
|
}
|
|
7785
|
-
const RECORD_SECONDS =
|
|
7711
|
+
const RECORD_SECONDS = 7;
|
|
7786
7712
|
const PREP_SECONDS = 3;
|
|
7713
|
+
const DIGITS_NUMBER = 7;
|
|
7787
7714
|
function generateRandomDigits(count) {
|
|
7788
7715
|
const digits = Array.from({ length: 10 }, (_, i) => i);
|
|
7789
7716
|
for (let i = digits.length - 1; i > 0; i--) {
|
|
@@ -7796,7 +7723,7 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
|
|
|
7796
7723
|
const [state, setState] = useState('preparation');
|
|
7797
7724
|
const [prepTimer, setPrepTimer] = useState(PREP_SECONDS);
|
|
7798
7725
|
const [recordTimer, setRecordTimer] = useState(RECORD_SECONDS);
|
|
7799
|
-
const [digits, setDigits] = useState(generateRandomDigits(
|
|
7726
|
+
const [digits, setDigits] = useState(generateRandomDigits(DIGITS_NUMBER));
|
|
7800
7727
|
const [audioLevel, setAudioLevel] = useState(0);
|
|
7801
7728
|
const [waveformData, setWaveformData] = useState([]);
|
|
7802
7729
|
const { permission, stream, stopStreamTracks, requestPermissions, isLoading } = useAudioPermissions();
|
|
@@ -7883,7 +7810,7 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
|
|
|
7883
7810
|
}
|
|
7884
7811
|
}, [state, recordTimer]);
|
|
7885
7812
|
const startRecording = async () => {
|
|
7886
|
-
setDigits(generateRandomDigits(
|
|
7813
|
+
setDigits(generateRandomDigits(DIGITS_NUMBER));
|
|
7887
7814
|
setRecordTimer(RECORD_SECONDS);
|
|
7888
7815
|
setState('countdown');
|
|
7889
7816
|
};
|
|
@@ -8125,97 +8052,4 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
|
|
|
8125
8052
|
maxWidth: '300px',
|
|
8126
8053
|
marginBottom: '16px',
|
|
8127
8054
|
} })), jsx("div", { className: "voicerecorder-confirm-text", style: confirmText, children: "Do you want to use this recording?" }), jsxs("div", { className: "voicerecorder-confirm-btns", style: { display: 'flex', justifyContent: 'center', gap: 32, marginTop: 12, width: '100%' }, children: [jsx("button", { type: "button", "aria-label": "Retake", className: "voicerecorder-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: "voicerecorder-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" })] }) })] })] }) }))] }));
|
|
8128
|
-
};const usePermissions = ({ rectWidth = 1920, rectHeight = 1080 } = {}) => {
|
|
8129
|
-
const [permission, setPermission] = useState(false);
|
|
8130
|
-
const [stream, setStream] = useState(null);
|
|
8131
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
8132
|
-
const stopStreamTracks = () => {
|
|
8133
|
-
if (stream) {
|
|
8134
|
-
stream.getTracks().forEach(track => {
|
|
8135
|
-
track.stop();
|
|
8136
|
-
});
|
|
8137
|
-
setStream(null);
|
|
8138
|
-
}
|
|
8139
|
-
};
|
|
8140
|
-
const getAdaptiveConstraints = () => {
|
|
8141
|
-
// Detect device capabilities and choose appropriate quality
|
|
8142
|
-
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
8143
|
-
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
8144
|
-
// High-end device settings
|
|
8145
|
-
if (!isMobile && !isLowEndDevice) {
|
|
8146
|
-
return {
|
|
8147
|
-
audio: {
|
|
8148
|
-
echoCancellation: true,
|
|
8149
|
-
noiseSuppression: true,
|
|
8150
|
-
autoGainControl: true,
|
|
8151
|
-
sampleRate: 48000,
|
|
8152
|
-
channelCount: 2
|
|
8153
|
-
},
|
|
8154
|
-
video: {
|
|
8155
|
-
width: { ideal: Math.min(rectWidth, 1920), min: 1280 },
|
|
8156
|
-
height: { ideal: Math.min(rectHeight, 1080), min: 720 },
|
|
8157
|
-
frameRate: { ideal: 30, min: 24 },
|
|
8158
|
-
facingMode: 'user',
|
|
8159
|
-
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
8160
|
-
}
|
|
8161
|
-
};
|
|
8162
|
-
}
|
|
8163
|
-
// Mobile device settings
|
|
8164
|
-
if (isMobile) {
|
|
8165
|
-
return {
|
|
8166
|
-
audio: {
|
|
8167
|
-
echoCancellation: true,
|
|
8168
|
-
noiseSuppression: true,
|
|
8169
|
-
autoGainControl: true,
|
|
8170
|
-
sampleRate: 22050, // Lower for mobile
|
|
8171
|
-
channelCount: 1
|
|
8172
|
-
},
|
|
8173
|
-
video: {
|
|
8174
|
-
width: { ideal: Math.min(rectWidth, 1280), min: 640 },
|
|
8175
|
-
height: { ideal: Math.min(rectHeight, 720), min: 480 },
|
|
8176
|
-
frameRate: { ideal: 24, min: 15 },
|
|
8177
|
-
facingMode: 'user',
|
|
8178
|
-
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
8179
|
-
}
|
|
8180
|
-
};
|
|
8181
|
-
}
|
|
8182
|
-
// Low-end device settings
|
|
8183
|
-
return {
|
|
8184
|
-
audio: {
|
|
8185
|
-
echoCancellation: true,
|
|
8186
|
-
noiseSuppression: true,
|
|
8187
|
-
autoGainControl: true,
|
|
8188
|
-
sampleRate: 22050,
|
|
8189
|
-
channelCount: 1
|
|
8190
|
-
},
|
|
8191
|
-
video: {
|
|
8192
|
-
width: { ideal: Math.min(rectWidth, 1280), min: 640 },
|
|
8193
|
-
height: { ideal: Math.min(rectHeight, 720), min: 480 },
|
|
8194
|
-
frameRate: { ideal: 20, min: 15 },
|
|
8195
|
-
facingMode: 'user',
|
|
8196
|
-
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
8197
|
-
}
|
|
8198
|
-
};
|
|
8199
|
-
};
|
|
8200
|
-
const requestPermissions = async () => {
|
|
8201
|
-
try {
|
|
8202
|
-
setIsLoading(true);
|
|
8203
|
-
const constraints = getAdaptiveConstraints();
|
|
8204
|
-
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
8205
|
-
console.log('Media stream obtained, active:', streamData.active);
|
|
8206
|
-
setPermission(true);
|
|
8207
|
-
setStream(streamData);
|
|
8208
|
-
}
|
|
8209
|
-
catch (err) {
|
|
8210
|
-
console.error('Camera/mic permission denied:', err);
|
|
8211
|
-
setPermission(false);
|
|
8212
|
-
}
|
|
8213
|
-
finally {
|
|
8214
|
-
setIsLoading(false);
|
|
8215
|
-
}
|
|
8216
|
-
};
|
|
8217
|
-
useEffect(() => {
|
|
8218
|
-
void requestPermissions();
|
|
8219
|
-
}, [rectWidth, rectHeight]);
|
|
8220
|
-
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
8221
8055
|
};export{DocScan,FaceCapture,FaceRecorder,VoiceRecorder,useAudioPermissions,usePermissions,useRecorder};
|