biometry-react-components 1.2.3 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +338 -191
- package/dist/index.js +338 -191
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -7156,169 +7156,6 @@ 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
|
-
setPermission(true);
|
|
7237
|
-
setStream(streamData);
|
|
7238
|
-
}
|
|
7239
|
-
catch (err) {
|
|
7240
|
-
console.error('Camera/mic permission denied:', err);
|
|
7241
|
-
setPermission(false);
|
|
7242
|
-
}
|
|
7243
|
-
finally {
|
|
7244
|
-
setIsLoading(false);
|
|
7245
|
-
}
|
|
7246
|
-
};
|
|
7247
|
-
useEffect(() => {
|
|
7248
|
-
void requestPermissions();
|
|
7249
|
-
}, [rectWidth, rectHeight]);
|
|
7250
|
-
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7251
|
-
};const useAudioPermissions = () => {
|
|
7252
|
-
const [permission, setPermission] = useState(false);
|
|
7253
|
-
const [stream, setStream] = useState(null);
|
|
7254
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
7255
|
-
const stopStreamTracks = () => {
|
|
7256
|
-
if (stream) {
|
|
7257
|
-
stream.getTracks().forEach(track => {
|
|
7258
|
-
track.stop();
|
|
7259
|
-
});
|
|
7260
|
-
setStream(null);
|
|
7261
|
-
}
|
|
7262
|
-
};
|
|
7263
|
-
const getAudioConstraints = () => {
|
|
7264
|
-
// Detect device capabilities and choose appropriate quality
|
|
7265
|
-
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7266
|
-
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7267
|
-
// High-end device settings
|
|
7268
|
-
if (!isMobile && !isLowEndDevice) {
|
|
7269
|
-
return {
|
|
7270
|
-
audio: {
|
|
7271
|
-
echoCancellation: true,
|
|
7272
|
-
noiseSuppression: true,
|
|
7273
|
-
autoGainControl: true,
|
|
7274
|
-
sampleRate: 48000,
|
|
7275
|
-
channelCount: 2
|
|
7276
|
-
}
|
|
7277
|
-
};
|
|
7278
|
-
}
|
|
7279
|
-
// Mobile device settings
|
|
7280
|
-
if (isMobile) {
|
|
7281
|
-
return {
|
|
7282
|
-
audio: {
|
|
7283
|
-
echoCancellation: true,
|
|
7284
|
-
noiseSuppression: true,
|
|
7285
|
-
autoGainControl: true,
|
|
7286
|
-
sampleRate: 22050, // Lower for mobile
|
|
7287
|
-
channelCount: 1
|
|
7288
|
-
}
|
|
7289
|
-
};
|
|
7290
|
-
}
|
|
7291
|
-
// Low-end device settings
|
|
7292
|
-
return {
|
|
7293
|
-
audio: {
|
|
7294
|
-
echoCancellation: true,
|
|
7295
|
-
noiseSuppression: true,
|
|
7296
|
-
autoGainControl: true,
|
|
7297
|
-
sampleRate: 22050,
|
|
7298
|
-
channelCount: 1
|
|
7299
|
-
}
|
|
7300
|
-
};
|
|
7301
|
-
};
|
|
7302
|
-
const requestPermissions = async () => {
|
|
7303
|
-
try {
|
|
7304
|
-
setIsLoading(true);
|
|
7305
|
-
const constraints = getAudioConstraints();
|
|
7306
|
-
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7307
|
-
setPermission(true);
|
|
7308
|
-
setStream(streamData);
|
|
7309
|
-
}
|
|
7310
|
-
catch (err) {
|
|
7311
|
-
console.error('Microphone permission denied:', err);
|
|
7312
|
-
setPermission(false);
|
|
7313
|
-
}
|
|
7314
|
-
finally {
|
|
7315
|
-
setIsLoading(false);
|
|
7316
|
-
}
|
|
7317
|
-
};
|
|
7318
|
-
useEffect(() => {
|
|
7319
|
-
void requestPermissions();
|
|
7320
|
-
}, []);
|
|
7321
|
-
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7322
7159
|
};// spinner animation
|
|
7323
7160
|
const spinnerStyle$1 = `
|
|
7324
7161
|
@keyframes spin {
|
|
@@ -7353,19 +7190,65 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7353
7190
|
const [prepTimer, setPrepTimer] = useState(PREP_SECONDS$1);
|
|
7354
7191
|
const [recordTimer, setRecordTimer] = useState(RECORD_SECONDS$1);
|
|
7355
7192
|
const [digits, setDigits] = useState(generateRandomDigits$1(10));
|
|
7356
|
-
const
|
|
7357
|
-
const
|
|
7193
|
+
const streamRef = useRef(null);
|
|
7194
|
+
const audioStreamRef = useRef(null);
|
|
7195
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
7196
|
+
const [permission, setPermission] = useState(false);
|
|
7197
|
+
const [audioPermission, setAudioPermission] = useState(false);
|
|
7358
7198
|
const [videoBlob, setVideoBlob] = useState(null);
|
|
7359
7199
|
const [videoUrl, setVideoUrl] = useState(null);
|
|
7360
7200
|
const [audioBlob, setAudioBlob] = useState(null);
|
|
7361
7201
|
const [faceImageBlob, setFaceImageBlob] = useState(null);
|
|
7362
7202
|
const [isConfirming, setIsConfirming] = useState(false);
|
|
7363
7203
|
const [faceCaptured, setFaceCaptured] = useState(false);
|
|
7204
|
+
const [isReinitializing, setIsReinitializing] = useState(false);
|
|
7205
|
+
const [streamAvailable, setStreamAvailable] = useState(false);
|
|
7364
7206
|
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
|
+
};
|
|
7365
7245
|
const previewRef = useRef(null);
|
|
7366
7246
|
const canvasRef = useRef(null);
|
|
7367
|
-
const { startRecording: startVideoRecording, cancelRecording: cancelVideoRecording } = useRecorder(
|
|
7368
|
-
|
|
7247
|
+
const { startRecording: startVideoRecording, cancelRecording: cancelVideoRecording } = useRecorder(streamRef.current, "video", (blob) => {
|
|
7248
|
+
if (streamRef.current) {
|
|
7249
|
+
streamRef.current.getTracks().forEach(track => track.stop());
|
|
7250
|
+
streamRef.current = null;
|
|
7251
|
+
}
|
|
7369
7252
|
if (blob && blob.size > 0) {
|
|
7370
7253
|
setVideoBlob(blob);
|
|
7371
7254
|
const url = URL.createObjectURL(blob);
|
|
@@ -7382,8 +7265,11 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7382
7265
|
setIsConfirming(true);
|
|
7383
7266
|
}
|
|
7384
7267
|
});
|
|
7385
|
-
const { startRecording: startAudioRecording, cancelRecording: cancelAudioRecording } = useRecorder(
|
|
7386
|
-
|
|
7268
|
+
const { startRecording: startAudioRecording, cancelRecording: cancelAudioRecording } = useRecorder(audioStreamRef.current, "audio", (blob) => {
|
|
7269
|
+
if (audioStreamRef.current) {
|
|
7270
|
+
audioStreamRef.current.getTracks().forEach(track => track.stop());
|
|
7271
|
+
audioStreamRef.current = null;
|
|
7272
|
+
}
|
|
7387
7273
|
if (blob && blob.size > 0) {
|
|
7388
7274
|
setAudioBlob(blob);
|
|
7389
7275
|
}
|
|
@@ -7410,22 +7296,81 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7410
7296
|
}
|
|
7411
7297
|
}
|
|
7412
7298
|
};
|
|
7299
|
+
// Initialize camera and audio streams
|
|
7413
7300
|
useEffect(() => {
|
|
7414
7301
|
let isMounted = true;
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7302
|
+
if (state !== 'result' && !isConfirming) {
|
|
7303
|
+
(async () => {
|
|
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;
|
|
7425
7346
|
}
|
|
7426
|
-
|
|
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;
|
|
7357
|
+
console.log('Setting up video element with stream');
|
|
7358
|
+
videoElement.srcObject = stream;
|
|
7359
|
+
videoElement.onloadedmetadata = () => {
|
|
7360
|
+
console.log('Video metadata loaded, playing...');
|
|
7361
|
+
videoElement.play().catch(err => {
|
|
7362
|
+
console.error('Failed to play video:', err);
|
|
7363
|
+
});
|
|
7364
|
+
};
|
|
7365
|
+
}
|
|
7366
|
+
}, [streamAvailable, state, isConfirming]);
|
|
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);
|
|
7427
7372
|
}
|
|
7428
|
-
}, [
|
|
7373
|
+
}, [state, isConfirming, isReinitializing]);
|
|
7429
7374
|
// Preparation countdown
|
|
7430
7375
|
useEffect(() => {
|
|
7431
7376
|
console.log('Countdown useEffect - state:', state, 'prepTimer:', prepTimer);
|
|
@@ -7435,6 +7380,13 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7435
7380
|
return () => clearTimeout(t);
|
|
7436
7381
|
}
|
|
7437
7382
|
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
|
+
}
|
|
7438
7390
|
setState('recording');
|
|
7439
7391
|
setPrepTimer(PREP_SECONDS$1);
|
|
7440
7392
|
startVideoRecording();
|
|
@@ -7461,6 +7413,26 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7461
7413
|
}
|
|
7462
7414
|
}, [state, recordTimer]);
|
|
7463
7415
|
const startRecording = async () => {
|
|
7416
|
+
// Don't start if streams are being reinitialized
|
|
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
|
+
}
|
|
7464
7436
|
setDigits(generateRandomDigits$1(10));
|
|
7465
7437
|
setRecordTimer(RECORD_SECONDS$1);
|
|
7466
7438
|
setFaceCaptured(false);
|
|
@@ -7469,8 +7441,15 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7469
7441
|
const handleCancel = () => {
|
|
7470
7442
|
cancelVideoRecording();
|
|
7471
7443
|
cancelAudioRecording();
|
|
7472
|
-
|
|
7473
|
-
|
|
7444
|
+
if (streamRef.current) {
|
|
7445
|
+
streamRef.current.getTracks().forEach(track => track.stop());
|
|
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);
|
|
7474
7453
|
setState('preparation');
|
|
7475
7454
|
setIsConfirming(false);
|
|
7476
7455
|
setVideoUrl(null);
|
|
@@ -7496,6 +7475,10 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7496
7475
|
setFaceCaptured(false);
|
|
7497
7476
|
setIsConfirming(false);
|
|
7498
7477
|
setState('preparation');
|
|
7478
|
+
setIsReinitializing(true);
|
|
7479
|
+
// Reinitialize streams after confirming
|
|
7480
|
+
requestPermissions();
|
|
7481
|
+
requestAudioPermissions();
|
|
7499
7482
|
}
|
|
7500
7483
|
};
|
|
7501
7484
|
const handleDecline = () => {
|
|
@@ -7544,7 +7527,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7544
7527
|
transform: 'translateX(-50%)',
|
|
7545
7528
|
width: '72%',
|
|
7546
7529
|
height: '68%',
|
|
7547
|
-
zIndex:
|
|
7530
|
+
zIndex: 3,
|
|
7548
7531
|
display: 'flex',
|
|
7549
7532
|
flexDirection: 'column',
|
|
7550
7533
|
alignItems: 'center',
|
|
@@ -7604,7 +7587,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7604
7587
|
fontWeight: 600,
|
|
7605
7588
|
borderRadius: 8,
|
|
7606
7589
|
padding: '4px 14px',
|
|
7607
|
-
zIndex:
|
|
7590
|
+
zIndex: 4,
|
|
7608
7591
|
transition: 'all 0.3s',
|
|
7609
7592
|
letterSpacing: 1.5,
|
|
7610
7593
|
};
|
|
@@ -7617,7 +7600,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7617
7600
|
fontSize: 64,
|
|
7618
7601
|
fontWeight: 700,
|
|
7619
7602
|
textShadow: '0 2px 12px rgba(0,0,0,0.25)',
|
|
7620
|
-
zIndex:
|
|
7603
|
+
zIndex: 4,
|
|
7621
7604
|
transition: 'all 0.3s',
|
|
7622
7605
|
pointerEvents: 'none',
|
|
7623
7606
|
};
|
|
@@ -7662,7 +7645,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7662
7645
|
transition: 'background 0.2s',
|
|
7663
7646
|
margin: '0 8px',
|
|
7664
7647
|
};
|
|
7665
|
-
if (isLoading ||
|
|
7648
|
+
if (isLoading || isReinitializing) {
|
|
7666
7649
|
return (jsx("div", { className: className, style: wrapperStyle, children: jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsx("div", { style: {
|
|
7667
7650
|
width: 48,
|
|
7668
7651
|
height: 48,
|
|
@@ -7671,7 +7654,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7671
7654
|
borderRadius: '50%',
|
|
7672
7655
|
animation: 'spin 1s linear infinite',
|
|
7673
7656
|
margin: '0 auto 16px auto',
|
|
7674
|
-
} }), jsx("h3", { children:
|
|
7657
|
+
} }), jsx("h3", { children: isReinitializing ? 'Reinitializing Camera & Microphone...' : 'Initializing Camera & Microphone...' }), jsx("p", { children: "Please wait while we set up your camera and microphone." })] }) }));
|
|
7675
7658
|
}
|
|
7676
7659
|
if (!permission || !audioPermission) {
|
|
7677
7660
|
return (jsx("div", { className: className, style: wrapperStyle, children: jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsx("h3", { children: "Camera & Microphone Permission Required" }), jsx("p", { children: "Please allow camera and microphone access to use this component." }), jsx("button", { type: "button", style: actionButton, onClick: () => {
|
|
@@ -7684,15 +7667,15 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7684
7667
|
height: rectHeight - 40,
|
|
7685
7668
|
objectFit: 'cover',
|
|
7686
7669
|
borderRadius: noShadow ? 0 : 8,
|
|
7687
|
-
zIndex:
|
|
7688
|
-
}, playsInline: true, muted: true, autoPlay: true }), jsx("div", { className: "facerecorder-dark-overlay", style: {
|
|
7670
|
+
zIndex: 1,
|
|
7671
|
+
}, playsInline: true, muted: true, autoPlay: true, onLoadStart: () => console.log('Video load started'), onLoadedData: () => console.log('Video loaded data'), onCanPlay: () => console.log('Video can play event'), onError: (e) => console.error('Video error:', e) }), jsx("div", { className: "facerecorder-dark-overlay", style: {
|
|
7689
7672
|
position: 'absolute',
|
|
7690
7673
|
top: 0,
|
|
7691
7674
|
left: 0,
|
|
7692
7675
|
width: '100%',
|
|
7693
7676
|
height: '100%',
|
|
7694
7677
|
background: 'rgba(0,0,0,0.4)',
|
|
7695
|
-
zIndex:
|
|
7678
|
+
zIndex: 2,
|
|
7696
7679
|
borderRadius: noShadow ? 0 : 8,
|
|
7697
7680
|
} }), 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: {
|
|
7698
7681
|
display: 'flex',
|
|
@@ -7715,6 +7698,77 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7715
7698
|
borderRadius: 8,
|
|
7716
7699
|
objectFit: 'cover'
|
|
7717
7700
|
}, 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" })] }) })] })] }))] }));
|
|
7701
|
+
};const useAudioPermissions = () => {
|
|
7702
|
+
const [permission, setPermission] = useState(false);
|
|
7703
|
+
const [stream, setStream] = useState(null);
|
|
7704
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
7705
|
+
const stopStreamTracks = () => {
|
|
7706
|
+
if (stream) {
|
|
7707
|
+
stream.getTracks().forEach(track => {
|
|
7708
|
+
track.stop();
|
|
7709
|
+
});
|
|
7710
|
+
setStream(null);
|
|
7711
|
+
}
|
|
7712
|
+
};
|
|
7713
|
+
const getAudioConstraints = () => {
|
|
7714
|
+
// Detect device capabilities and choose appropriate quality
|
|
7715
|
+
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7716
|
+
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7717
|
+
// High-end device settings
|
|
7718
|
+
if (!isMobile && !isLowEndDevice) {
|
|
7719
|
+
return {
|
|
7720
|
+
audio: {
|
|
7721
|
+
echoCancellation: true,
|
|
7722
|
+
noiseSuppression: true,
|
|
7723
|
+
autoGainControl: true,
|
|
7724
|
+
sampleRate: 48000,
|
|
7725
|
+
channelCount: 2
|
|
7726
|
+
}
|
|
7727
|
+
};
|
|
7728
|
+
}
|
|
7729
|
+
// Mobile device settings
|
|
7730
|
+
if (isMobile) {
|
|
7731
|
+
return {
|
|
7732
|
+
audio: {
|
|
7733
|
+
echoCancellation: true,
|
|
7734
|
+
noiseSuppression: true,
|
|
7735
|
+
autoGainControl: true,
|
|
7736
|
+
sampleRate: 22050, // Lower for mobile
|
|
7737
|
+
channelCount: 1
|
|
7738
|
+
}
|
|
7739
|
+
};
|
|
7740
|
+
}
|
|
7741
|
+
// Low-end device settings
|
|
7742
|
+
return {
|
|
7743
|
+
audio: {
|
|
7744
|
+
echoCancellation: true,
|
|
7745
|
+
noiseSuppression: true,
|
|
7746
|
+
autoGainControl: true,
|
|
7747
|
+
sampleRate: 22050,
|
|
7748
|
+
channelCount: 1
|
|
7749
|
+
}
|
|
7750
|
+
};
|
|
7751
|
+
};
|
|
7752
|
+
const requestPermissions = async () => {
|
|
7753
|
+
try {
|
|
7754
|
+
setIsLoading(true);
|
|
7755
|
+
const constraints = getAudioConstraints();
|
|
7756
|
+
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7757
|
+
setPermission(true);
|
|
7758
|
+
setStream(streamData);
|
|
7759
|
+
}
|
|
7760
|
+
catch (err) {
|
|
7761
|
+
console.error('Microphone permission denied:', err);
|
|
7762
|
+
setPermission(false);
|
|
7763
|
+
}
|
|
7764
|
+
finally {
|
|
7765
|
+
setIsLoading(false);
|
|
7766
|
+
}
|
|
7767
|
+
};
|
|
7768
|
+
useEffect(() => {
|
|
7769
|
+
void requestPermissions();
|
|
7770
|
+
}, []);
|
|
7771
|
+
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7718
7772
|
};// spinner animation
|
|
7719
7773
|
const spinnerStyle = `
|
|
7720
7774
|
@keyframes spin {
|
|
@@ -8071,4 +8125,97 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
|
|
|
8071
8125
|
maxWidth: '300px',
|
|
8072
8126
|
marginBottom: '16px',
|
|
8073
8127
|
} })), 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 };
|
|
8074
8221
|
};export{DocScan,FaceCapture,FaceRecorder,VoiceRecorder,useAudioPermissions,usePermissions,useRecorder};
|
package/dist/index.js
CHANGED
|
@@ -7156,169 +7156,6 @@ 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] = react.useState(false);
|
|
7161
|
-
const [stream, setStream] = react.useState(null);
|
|
7162
|
-
const [isLoading, setIsLoading] = react.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
|
-
setPermission(true);
|
|
7237
|
-
setStream(streamData);
|
|
7238
|
-
}
|
|
7239
|
-
catch (err) {
|
|
7240
|
-
console.error('Camera/mic permission denied:', err);
|
|
7241
|
-
setPermission(false);
|
|
7242
|
-
}
|
|
7243
|
-
finally {
|
|
7244
|
-
setIsLoading(false);
|
|
7245
|
-
}
|
|
7246
|
-
};
|
|
7247
|
-
react.useEffect(() => {
|
|
7248
|
-
void requestPermissions();
|
|
7249
|
-
}, [rectWidth, rectHeight]);
|
|
7250
|
-
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7251
|
-
};const useAudioPermissions = () => {
|
|
7252
|
-
const [permission, setPermission] = react.useState(false);
|
|
7253
|
-
const [stream, setStream] = react.useState(null);
|
|
7254
|
-
const [isLoading, setIsLoading] = react.useState(true);
|
|
7255
|
-
const stopStreamTracks = () => {
|
|
7256
|
-
if (stream) {
|
|
7257
|
-
stream.getTracks().forEach(track => {
|
|
7258
|
-
track.stop();
|
|
7259
|
-
});
|
|
7260
|
-
setStream(null);
|
|
7261
|
-
}
|
|
7262
|
-
};
|
|
7263
|
-
const getAudioConstraints = () => {
|
|
7264
|
-
// Detect device capabilities and choose appropriate quality
|
|
7265
|
-
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7266
|
-
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7267
|
-
// High-end device settings
|
|
7268
|
-
if (!isMobile && !isLowEndDevice) {
|
|
7269
|
-
return {
|
|
7270
|
-
audio: {
|
|
7271
|
-
echoCancellation: true,
|
|
7272
|
-
noiseSuppression: true,
|
|
7273
|
-
autoGainControl: true,
|
|
7274
|
-
sampleRate: 48000,
|
|
7275
|
-
channelCount: 2
|
|
7276
|
-
}
|
|
7277
|
-
};
|
|
7278
|
-
}
|
|
7279
|
-
// Mobile device settings
|
|
7280
|
-
if (isMobile) {
|
|
7281
|
-
return {
|
|
7282
|
-
audio: {
|
|
7283
|
-
echoCancellation: true,
|
|
7284
|
-
noiseSuppression: true,
|
|
7285
|
-
autoGainControl: true,
|
|
7286
|
-
sampleRate: 22050, // Lower for mobile
|
|
7287
|
-
channelCount: 1
|
|
7288
|
-
}
|
|
7289
|
-
};
|
|
7290
|
-
}
|
|
7291
|
-
// Low-end device settings
|
|
7292
|
-
return {
|
|
7293
|
-
audio: {
|
|
7294
|
-
echoCancellation: true,
|
|
7295
|
-
noiseSuppression: true,
|
|
7296
|
-
autoGainControl: true,
|
|
7297
|
-
sampleRate: 22050,
|
|
7298
|
-
channelCount: 1
|
|
7299
|
-
}
|
|
7300
|
-
};
|
|
7301
|
-
};
|
|
7302
|
-
const requestPermissions = async () => {
|
|
7303
|
-
try {
|
|
7304
|
-
setIsLoading(true);
|
|
7305
|
-
const constraints = getAudioConstraints();
|
|
7306
|
-
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7307
|
-
setPermission(true);
|
|
7308
|
-
setStream(streamData);
|
|
7309
|
-
}
|
|
7310
|
-
catch (err) {
|
|
7311
|
-
console.error('Microphone permission denied:', err);
|
|
7312
|
-
setPermission(false);
|
|
7313
|
-
}
|
|
7314
|
-
finally {
|
|
7315
|
-
setIsLoading(false);
|
|
7316
|
-
}
|
|
7317
|
-
};
|
|
7318
|
-
react.useEffect(() => {
|
|
7319
|
-
void requestPermissions();
|
|
7320
|
-
}, []);
|
|
7321
|
-
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7322
7159
|
};// spinner animation
|
|
7323
7160
|
const spinnerStyle$1 = `
|
|
7324
7161
|
@keyframes spin {
|
|
@@ -7353,19 +7190,65 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7353
7190
|
const [prepTimer, setPrepTimer] = react.useState(PREP_SECONDS$1);
|
|
7354
7191
|
const [recordTimer, setRecordTimer] = react.useState(RECORD_SECONDS$1);
|
|
7355
7192
|
const [digits, setDigits] = react.useState(generateRandomDigits$1(10));
|
|
7356
|
-
const
|
|
7357
|
-
const
|
|
7193
|
+
const streamRef = react.useRef(null);
|
|
7194
|
+
const audioStreamRef = react.useRef(null);
|
|
7195
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
7196
|
+
const [permission, setPermission] = react.useState(false);
|
|
7197
|
+
const [audioPermission, setAudioPermission] = react.useState(false);
|
|
7358
7198
|
const [videoBlob, setVideoBlob] = react.useState(null);
|
|
7359
7199
|
const [videoUrl, setVideoUrl] = react.useState(null);
|
|
7360
7200
|
const [audioBlob, setAudioBlob] = react.useState(null);
|
|
7361
7201
|
const [faceImageBlob, setFaceImageBlob] = react.useState(null);
|
|
7362
7202
|
const [isConfirming, setIsConfirming] = react.useState(false);
|
|
7363
7203
|
const [faceCaptured, setFaceCaptured] = react.useState(false);
|
|
7204
|
+
const [isReinitializing, setIsReinitializing] = react.useState(false);
|
|
7205
|
+
const [streamAvailable, setStreamAvailable] = react.useState(false);
|
|
7364
7206
|
const videoRef = react.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
|
+
};
|
|
7365
7245
|
const previewRef = react.useRef(null);
|
|
7366
7246
|
const canvasRef = react.useRef(null);
|
|
7367
|
-
const { startRecording: startVideoRecording, cancelRecording: cancelVideoRecording } = useRecorder(
|
|
7368
|
-
|
|
7247
|
+
const { startRecording: startVideoRecording, cancelRecording: cancelVideoRecording } = useRecorder(streamRef.current, "video", (blob) => {
|
|
7248
|
+
if (streamRef.current) {
|
|
7249
|
+
streamRef.current.getTracks().forEach(track => track.stop());
|
|
7250
|
+
streamRef.current = null;
|
|
7251
|
+
}
|
|
7369
7252
|
if (blob && blob.size > 0) {
|
|
7370
7253
|
setVideoBlob(blob);
|
|
7371
7254
|
const url = URL.createObjectURL(blob);
|
|
@@ -7382,8 +7265,11 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7382
7265
|
setIsConfirming(true);
|
|
7383
7266
|
}
|
|
7384
7267
|
});
|
|
7385
|
-
const { startRecording: startAudioRecording, cancelRecording: cancelAudioRecording } = useRecorder(
|
|
7386
|
-
|
|
7268
|
+
const { startRecording: startAudioRecording, cancelRecording: cancelAudioRecording } = useRecorder(audioStreamRef.current, "audio", (blob) => {
|
|
7269
|
+
if (audioStreamRef.current) {
|
|
7270
|
+
audioStreamRef.current.getTracks().forEach(track => track.stop());
|
|
7271
|
+
audioStreamRef.current = null;
|
|
7272
|
+
}
|
|
7387
7273
|
if (blob && blob.size > 0) {
|
|
7388
7274
|
setAudioBlob(blob);
|
|
7389
7275
|
}
|
|
@@ -7410,22 +7296,81 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7410
7296
|
}
|
|
7411
7297
|
}
|
|
7412
7298
|
};
|
|
7299
|
+
// Initialize camera and audio streams
|
|
7413
7300
|
react.useEffect(() => {
|
|
7414
7301
|
let isMounted = true;
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7302
|
+
if (state !== 'result' && !isConfirming) {
|
|
7303
|
+
(async () => {
|
|
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;
|
|
7425
7346
|
}
|
|
7426
|
-
|
|
7347
|
+
setStreamAvailable(false);
|
|
7348
|
+
};
|
|
7349
|
+
}, [state, isConfirming, rectWidth, rectHeight]);
|
|
7350
|
+
// Set up video element when stream becomes available
|
|
7351
|
+
react.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;
|
|
7357
|
+
console.log('Setting up video element with stream');
|
|
7358
|
+
videoElement.srcObject = stream;
|
|
7359
|
+
videoElement.onloadedmetadata = () => {
|
|
7360
|
+
console.log('Video metadata loaded, playing...');
|
|
7361
|
+
videoElement.play().catch(err => {
|
|
7362
|
+
console.error('Failed to play video:', err);
|
|
7363
|
+
});
|
|
7364
|
+
};
|
|
7365
|
+
}
|
|
7366
|
+
}, [streamAvailable, state, isConfirming]);
|
|
7367
|
+
// Auto-start countdown when streams become available after reinitialization
|
|
7368
|
+
react.useEffect(() => {
|
|
7369
|
+
if (state === 'preparation' && streamRef.current && audioStreamRef.current && !isConfirming && isReinitializing) {
|
|
7370
|
+
console.log('Streams reinitialized, ready for next recording');
|
|
7371
|
+
setIsReinitializing(false);
|
|
7427
7372
|
}
|
|
7428
|
-
}, [
|
|
7373
|
+
}, [state, isConfirming, isReinitializing]);
|
|
7429
7374
|
// Preparation countdown
|
|
7430
7375
|
react.useEffect(() => {
|
|
7431
7376
|
console.log('Countdown useEffect - state:', state, 'prepTimer:', prepTimer);
|
|
@@ -7435,6 +7380,13 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7435
7380
|
return () => clearTimeout(t);
|
|
7436
7381
|
}
|
|
7437
7382
|
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
|
+
}
|
|
7438
7390
|
setState('recording');
|
|
7439
7391
|
setPrepTimer(PREP_SECONDS$1);
|
|
7440
7392
|
startVideoRecording();
|
|
@@ -7461,6 +7413,26 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7461
7413
|
}
|
|
7462
7414
|
}, [state, recordTimer]);
|
|
7463
7415
|
const startRecording = async () => {
|
|
7416
|
+
// Don't start if streams are being reinitialized
|
|
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
|
+
}
|
|
7464
7436
|
setDigits(generateRandomDigits$1(10));
|
|
7465
7437
|
setRecordTimer(RECORD_SECONDS$1);
|
|
7466
7438
|
setFaceCaptured(false);
|
|
@@ -7469,8 +7441,15 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7469
7441
|
const handleCancel = () => {
|
|
7470
7442
|
cancelVideoRecording();
|
|
7471
7443
|
cancelAudioRecording();
|
|
7472
|
-
|
|
7473
|
-
|
|
7444
|
+
if (streamRef.current) {
|
|
7445
|
+
streamRef.current.getTracks().forEach(track => track.stop());
|
|
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);
|
|
7474
7453
|
setState('preparation');
|
|
7475
7454
|
setIsConfirming(false);
|
|
7476
7455
|
setVideoUrl(null);
|
|
@@ -7496,6 +7475,10 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7496
7475
|
setFaceCaptured(false);
|
|
7497
7476
|
setIsConfirming(false);
|
|
7498
7477
|
setState('preparation');
|
|
7478
|
+
setIsReinitializing(true);
|
|
7479
|
+
// Reinitialize streams after confirming
|
|
7480
|
+
requestPermissions();
|
|
7481
|
+
requestAudioPermissions();
|
|
7499
7482
|
}
|
|
7500
7483
|
};
|
|
7501
7484
|
const handleDecline = () => {
|
|
@@ -7544,7 +7527,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7544
7527
|
transform: 'translateX(-50%)',
|
|
7545
7528
|
width: '72%',
|
|
7546
7529
|
height: '68%',
|
|
7547
|
-
zIndex:
|
|
7530
|
+
zIndex: 3,
|
|
7548
7531
|
display: 'flex',
|
|
7549
7532
|
flexDirection: 'column',
|
|
7550
7533
|
alignItems: 'center',
|
|
@@ -7604,7 +7587,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7604
7587
|
fontWeight: 600,
|
|
7605
7588
|
borderRadius: 8,
|
|
7606
7589
|
padding: '4px 14px',
|
|
7607
|
-
zIndex:
|
|
7590
|
+
zIndex: 4,
|
|
7608
7591
|
transition: 'all 0.3s',
|
|
7609
7592
|
letterSpacing: 1.5,
|
|
7610
7593
|
};
|
|
@@ -7617,7 +7600,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7617
7600
|
fontSize: 64,
|
|
7618
7601
|
fontWeight: 700,
|
|
7619
7602
|
textShadow: '0 2px 12px rgba(0,0,0,0.25)',
|
|
7620
|
-
zIndex:
|
|
7603
|
+
zIndex: 4,
|
|
7621
7604
|
transition: 'all 0.3s',
|
|
7622
7605
|
pointerEvents: 'none',
|
|
7623
7606
|
};
|
|
@@ -7662,7 +7645,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7662
7645
|
transition: 'background 0.2s',
|
|
7663
7646
|
margin: '0 8px',
|
|
7664
7647
|
};
|
|
7665
|
-
if (isLoading ||
|
|
7648
|
+
if (isLoading || isReinitializing) {
|
|
7666
7649
|
return (jsxRuntime.jsx("div", { className: className, style: wrapperStyle, children: jsxRuntime.jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsxRuntime.jsx("div", { style: {
|
|
7667
7650
|
width: 48,
|
|
7668
7651
|
height: 48,
|
|
@@ -7671,7 +7654,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7671
7654
|
borderRadius: '50%',
|
|
7672
7655
|
animation: 'spin 1s linear infinite',
|
|
7673
7656
|
margin: '0 auto 16px auto',
|
|
7674
|
-
} }), jsxRuntime.jsx("h3", { children:
|
|
7657
|
+
} }), jsxRuntime.jsx("h3", { children: isReinitializing ? 'Reinitializing Camera & Microphone...' : 'Initializing Camera & Microphone...' }), jsxRuntime.jsx("p", { children: "Please wait while we set up your camera and microphone." })] }) }));
|
|
7675
7658
|
}
|
|
7676
7659
|
if (!permission || !audioPermission) {
|
|
7677
7660
|
return (jsxRuntime.jsx("div", { className: className, style: wrapperStyle, children: jsxRuntime.jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsxRuntime.jsx("h3", { children: "Camera & Microphone Permission Required" }), jsxRuntime.jsx("p", { children: "Please allow camera and microphone access to use this component." }), jsxRuntime.jsx("button", { type: "button", style: actionButton, onClick: () => {
|
|
@@ -7684,15 +7667,15 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7684
7667
|
height: rectHeight - 40,
|
|
7685
7668
|
objectFit: 'cover',
|
|
7686
7669
|
borderRadius: noShadow ? 0 : 8,
|
|
7687
|
-
zIndex:
|
|
7688
|
-
}, playsInline: true, muted: true, autoPlay: true }), jsxRuntime.jsx("div", { className: "facerecorder-dark-overlay", style: {
|
|
7670
|
+
zIndex: 1,
|
|
7671
|
+
}, playsInline: true, muted: true, autoPlay: true, onLoadStart: () => console.log('Video load started'), onLoadedData: () => console.log('Video loaded data'), onCanPlay: () => console.log('Video can play event'), onError: (e) => console.error('Video error:', e) }), jsxRuntime.jsx("div", { className: "facerecorder-dark-overlay", style: {
|
|
7689
7672
|
position: 'absolute',
|
|
7690
7673
|
top: 0,
|
|
7691
7674
|
left: 0,
|
|
7692
7675
|
width: '100%',
|
|
7693
7676
|
height: '100%',
|
|
7694
7677
|
background: 'rgba(0,0,0,0.4)',
|
|
7695
|
-
zIndex:
|
|
7678
|
+
zIndex: 2,
|
|
7696
7679
|
borderRadius: noShadow ? 0 : 8,
|
|
7697
7680
|
} }), 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: {
|
|
7698
7681
|
display: 'flex',
|
|
@@ -7715,6 +7698,77 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7715
7698
|
borderRadius: 8,
|
|
7716
7699
|
objectFit: 'cover'
|
|
7717
7700
|
}, 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" })] }) })] })] }))] }));
|
|
7701
|
+
};const useAudioPermissions = () => {
|
|
7702
|
+
const [permission, setPermission] = react.useState(false);
|
|
7703
|
+
const [stream, setStream] = react.useState(null);
|
|
7704
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
7705
|
+
const stopStreamTracks = () => {
|
|
7706
|
+
if (stream) {
|
|
7707
|
+
stream.getTracks().forEach(track => {
|
|
7708
|
+
track.stop();
|
|
7709
|
+
});
|
|
7710
|
+
setStream(null);
|
|
7711
|
+
}
|
|
7712
|
+
};
|
|
7713
|
+
const getAudioConstraints = () => {
|
|
7714
|
+
// Detect device capabilities and choose appropriate quality
|
|
7715
|
+
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7716
|
+
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7717
|
+
// High-end device settings
|
|
7718
|
+
if (!isMobile && !isLowEndDevice) {
|
|
7719
|
+
return {
|
|
7720
|
+
audio: {
|
|
7721
|
+
echoCancellation: true,
|
|
7722
|
+
noiseSuppression: true,
|
|
7723
|
+
autoGainControl: true,
|
|
7724
|
+
sampleRate: 48000,
|
|
7725
|
+
channelCount: 2
|
|
7726
|
+
}
|
|
7727
|
+
};
|
|
7728
|
+
}
|
|
7729
|
+
// Mobile device settings
|
|
7730
|
+
if (isMobile) {
|
|
7731
|
+
return {
|
|
7732
|
+
audio: {
|
|
7733
|
+
echoCancellation: true,
|
|
7734
|
+
noiseSuppression: true,
|
|
7735
|
+
autoGainControl: true,
|
|
7736
|
+
sampleRate: 22050, // Lower for mobile
|
|
7737
|
+
channelCount: 1
|
|
7738
|
+
}
|
|
7739
|
+
};
|
|
7740
|
+
}
|
|
7741
|
+
// Low-end device settings
|
|
7742
|
+
return {
|
|
7743
|
+
audio: {
|
|
7744
|
+
echoCancellation: true,
|
|
7745
|
+
noiseSuppression: true,
|
|
7746
|
+
autoGainControl: true,
|
|
7747
|
+
sampleRate: 22050,
|
|
7748
|
+
channelCount: 1
|
|
7749
|
+
}
|
|
7750
|
+
};
|
|
7751
|
+
};
|
|
7752
|
+
const requestPermissions = async () => {
|
|
7753
|
+
try {
|
|
7754
|
+
setIsLoading(true);
|
|
7755
|
+
const constraints = getAudioConstraints();
|
|
7756
|
+
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7757
|
+
setPermission(true);
|
|
7758
|
+
setStream(streamData);
|
|
7759
|
+
}
|
|
7760
|
+
catch (err) {
|
|
7761
|
+
console.error('Microphone permission denied:', err);
|
|
7762
|
+
setPermission(false);
|
|
7763
|
+
}
|
|
7764
|
+
finally {
|
|
7765
|
+
setIsLoading(false);
|
|
7766
|
+
}
|
|
7767
|
+
};
|
|
7768
|
+
react.useEffect(() => {
|
|
7769
|
+
void requestPermissions();
|
|
7770
|
+
}, []);
|
|
7771
|
+
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7718
7772
|
};// spinner animation
|
|
7719
7773
|
const spinnerStyle = `
|
|
7720
7774
|
@keyframes spin {
|
|
@@ -8071,4 +8125,97 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
|
|
|
8071
8125
|
maxWidth: '300px',
|
|
8072
8126
|
marginBottom: '16px',
|
|
8073
8127
|
} })), jsxRuntime.jsx("div", { className: "voicerecorder-confirm-text", style: confirmText, children: "Do you want to use this recording?" }), jsxRuntime.jsxs("div", { className: "voicerecorder-confirm-btns", style: { display: 'flex', justifyContent: 'center', gap: 32, marginTop: 12, width: '100%' }, children: [jsxRuntime.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: 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: "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: 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" })] }) })] })] }) }))] }));
|
|
8128
|
+
};const usePermissions = ({ rectWidth = 1920, rectHeight = 1080 } = {}) => {
|
|
8129
|
+
const [permission, setPermission] = react.useState(false);
|
|
8130
|
+
const [stream, setStream] = react.useState(null);
|
|
8131
|
+
const [isLoading, setIsLoading] = react.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
|
+
react.useEffect(() => {
|
|
8218
|
+
void requestPermissions();
|
|
8219
|
+
}, [rectWidth, rectHeight]);
|
|
8220
|
+
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
8074
8221
|
};exports.DocScan=DocScan;exports.FaceCapture=FaceCapture;exports.FaceRecorder=FaceRecorder;exports.VoiceRecorder=VoiceRecorder;exports.useAudioPermissions=useAudioPermissions;exports.usePermissions=usePermissions;exports.useRecorder=useRecorder;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "biometry-react-components",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
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",
|