biometry-react-components 1.2.4 → 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 +297 -250
- package/dist/index.js +297 -250
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -7060,23 +7060,7 @@ function numberToWord(num) {
|
|
|
7060
7060
|
}
|
|
7061
7061
|
function numbersToPhrase(numbers) {
|
|
7062
7062
|
return numbers.map(numberToWord).join(' ');
|
|
7063
|
-
}
|
|
7064
|
-
const VIDEO_READY_STATES = {
|
|
7065
|
-
// 0 means the video element is not ready
|
|
7066
|
-
// 1 means the video element is ready
|
|
7067
|
-
// 2 means the video element is loading
|
|
7068
|
-
// 3 means the video element is ended
|
|
7069
|
-
// 4 means the video element is seeking
|
|
7070
|
-
// 5 means the video element is paused
|
|
7071
|
-
// 6 means the video element is playing
|
|
7072
|
-
0: 'not ready',
|
|
7073
|
-
1: 'ready',
|
|
7074
|
-
2: 'loading',
|
|
7075
|
-
3: 'ended',
|
|
7076
|
-
4: 'seeking',
|
|
7077
|
-
5: 'paused',
|
|
7078
|
-
6: 'playing'
|
|
7079
|
-
};const useRecorder = (stream, type, onStopRecording) => {
|
|
7063
|
+
}const useRecorder = (stream, type, onStopRecording) => {
|
|
7080
7064
|
const [isRecording, setIsRecording] = useState(false);
|
|
7081
7065
|
const recorderRef = useRef(null);
|
|
7082
7066
|
const timeoutRef = useRef(null);
|
|
@@ -7172,170 +7156,6 @@ const VIDEO_READY_STATES = {
|
|
|
7172
7156
|
}
|
|
7173
7157
|
};
|
|
7174
7158
|
return { isRecording, startRecording, stopRecording, cancelRecording };
|
|
7175
|
-
};const usePermissions = ({ rectWidth = 1920, rectHeight = 1080 } = {}) => {
|
|
7176
|
-
const [permission, setPermission] = useState(false);
|
|
7177
|
-
const [stream, setStream] = useState(null);
|
|
7178
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
7179
|
-
const stopStreamTracks = () => {
|
|
7180
|
-
if (stream) {
|
|
7181
|
-
stream.getTracks().forEach(track => {
|
|
7182
|
-
track.stop();
|
|
7183
|
-
});
|
|
7184
|
-
setStream(null);
|
|
7185
|
-
}
|
|
7186
|
-
};
|
|
7187
|
-
const getAdaptiveConstraints = () => {
|
|
7188
|
-
// Detect device capabilities and choose appropriate quality
|
|
7189
|
-
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7190
|
-
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7191
|
-
// High-end device settings
|
|
7192
|
-
if (!isMobile && !isLowEndDevice) {
|
|
7193
|
-
return {
|
|
7194
|
-
audio: {
|
|
7195
|
-
echoCancellation: true,
|
|
7196
|
-
noiseSuppression: true,
|
|
7197
|
-
autoGainControl: true,
|
|
7198
|
-
sampleRate: 48000,
|
|
7199
|
-
channelCount: 2
|
|
7200
|
-
},
|
|
7201
|
-
video: {
|
|
7202
|
-
width: { ideal: Math.min(rectWidth, 1920), min: 1280 },
|
|
7203
|
-
height: { ideal: Math.min(rectHeight, 1080), min: 720 },
|
|
7204
|
-
frameRate: { ideal: 30, min: 24 },
|
|
7205
|
-
facingMode: 'user',
|
|
7206
|
-
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
7207
|
-
}
|
|
7208
|
-
};
|
|
7209
|
-
}
|
|
7210
|
-
// Mobile device settings
|
|
7211
|
-
if (isMobile) {
|
|
7212
|
-
return {
|
|
7213
|
-
audio: {
|
|
7214
|
-
echoCancellation: true,
|
|
7215
|
-
noiseSuppression: true,
|
|
7216
|
-
autoGainControl: true,
|
|
7217
|
-
sampleRate: 22050, // Lower for mobile
|
|
7218
|
-
channelCount: 1
|
|
7219
|
-
},
|
|
7220
|
-
video: {
|
|
7221
|
-
width: { ideal: Math.min(rectWidth, 1280), min: 640 },
|
|
7222
|
-
height: { ideal: Math.min(rectHeight, 720), min: 480 },
|
|
7223
|
-
frameRate: { ideal: 24, min: 15 },
|
|
7224
|
-
facingMode: 'user',
|
|
7225
|
-
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
7226
|
-
}
|
|
7227
|
-
};
|
|
7228
|
-
}
|
|
7229
|
-
// Low-end device settings
|
|
7230
|
-
return {
|
|
7231
|
-
audio: {
|
|
7232
|
-
echoCancellation: true,
|
|
7233
|
-
noiseSuppression: true,
|
|
7234
|
-
autoGainControl: true,
|
|
7235
|
-
sampleRate: 22050,
|
|
7236
|
-
channelCount: 1
|
|
7237
|
-
},
|
|
7238
|
-
video: {
|
|
7239
|
-
width: { ideal: Math.min(rectWidth, 1280), min: 640 },
|
|
7240
|
-
height: { ideal: Math.min(rectHeight, 720), min: 480 },
|
|
7241
|
-
frameRate: { ideal: 20, min: 15 },
|
|
7242
|
-
facingMode: 'user',
|
|
7243
|
-
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
7244
|
-
}
|
|
7245
|
-
};
|
|
7246
|
-
};
|
|
7247
|
-
const requestPermissions = async () => {
|
|
7248
|
-
try {
|
|
7249
|
-
setIsLoading(true);
|
|
7250
|
-
const constraints = getAdaptiveConstraints();
|
|
7251
|
-
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7252
|
-
console.log('Media stream obtained, active:', streamData.active);
|
|
7253
|
-
setPermission(true);
|
|
7254
|
-
setStream(streamData);
|
|
7255
|
-
}
|
|
7256
|
-
catch (err) {
|
|
7257
|
-
console.error('Camera/mic permission denied:', err);
|
|
7258
|
-
setPermission(false);
|
|
7259
|
-
}
|
|
7260
|
-
finally {
|
|
7261
|
-
setIsLoading(false);
|
|
7262
|
-
}
|
|
7263
|
-
};
|
|
7264
|
-
useEffect(() => {
|
|
7265
|
-
void requestPermissions();
|
|
7266
|
-
}, [rectWidth, rectHeight]);
|
|
7267
|
-
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7268
|
-
};const useAudioPermissions = () => {
|
|
7269
|
-
const [permission, setPermission] = useState(false);
|
|
7270
|
-
const [stream, setStream] = useState(null);
|
|
7271
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
7272
|
-
const stopStreamTracks = () => {
|
|
7273
|
-
if (stream) {
|
|
7274
|
-
stream.getTracks().forEach(track => {
|
|
7275
|
-
track.stop();
|
|
7276
|
-
});
|
|
7277
|
-
setStream(null);
|
|
7278
|
-
}
|
|
7279
|
-
};
|
|
7280
|
-
const getAudioConstraints = () => {
|
|
7281
|
-
// Detect device capabilities and choose appropriate quality
|
|
7282
|
-
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7283
|
-
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7284
|
-
// High-end device settings
|
|
7285
|
-
if (!isMobile && !isLowEndDevice) {
|
|
7286
|
-
return {
|
|
7287
|
-
audio: {
|
|
7288
|
-
echoCancellation: true,
|
|
7289
|
-
noiseSuppression: true,
|
|
7290
|
-
autoGainControl: true,
|
|
7291
|
-
sampleRate: 48000,
|
|
7292
|
-
channelCount: 2
|
|
7293
|
-
}
|
|
7294
|
-
};
|
|
7295
|
-
}
|
|
7296
|
-
// Mobile device settings
|
|
7297
|
-
if (isMobile) {
|
|
7298
|
-
return {
|
|
7299
|
-
audio: {
|
|
7300
|
-
echoCancellation: true,
|
|
7301
|
-
noiseSuppression: true,
|
|
7302
|
-
autoGainControl: true,
|
|
7303
|
-
sampleRate: 22050, // Lower for mobile
|
|
7304
|
-
channelCount: 1
|
|
7305
|
-
}
|
|
7306
|
-
};
|
|
7307
|
-
}
|
|
7308
|
-
// Low-end device settings
|
|
7309
|
-
return {
|
|
7310
|
-
audio: {
|
|
7311
|
-
echoCancellation: true,
|
|
7312
|
-
noiseSuppression: true,
|
|
7313
|
-
autoGainControl: true,
|
|
7314
|
-
sampleRate: 22050,
|
|
7315
|
-
channelCount: 1
|
|
7316
|
-
}
|
|
7317
|
-
};
|
|
7318
|
-
};
|
|
7319
|
-
const requestPermissions = async () => {
|
|
7320
|
-
try {
|
|
7321
|
-
setIsLoading(true);
|
|
7322
|
-
const constraints = getAudioConstraints();
|
|
7323
|
-
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7324
|
-
setPermission(true);
|
|
7325
|
-
setStream(streamData);
|
|
7326
|
-
}
|
|
7327
|
-
catch (err) {
|
|
7328
|
-
console.error('Microphone permission denied:', err);
|
|
7329
|
-
setPermission(false);
|
|
7330
|
-
}
|
|
7331
|
-
finally {
|
|
7332
|
-
setIsLoading(false);
|
|
7333
|
-
}
|
|
7334
|
-
};
|
|
7335
|
-
useEffect(() => {
|
|
7336
|
-
void requestPermissions();
|
|
7337
|
-
}, []);
|
|
7338
|
-
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7339
7159
|
};// spinner animation
|
|
7340
7160
|
const spinnerStyle$1 = `
|
|
7341
7161
|
@keyframes spin {
|
|
@@ -7370,8 +7190,11 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7370
7190
|
const [prepTimer, setPrepTimer] = useState(PREP_SECONDS$1);
|
|
7371
7191
|
const [recordTimer, setRecordTimer] = useState(RECORD_SECONDS$1);
|
|
7372
7192
|
const [digits, setDigits] = useState(generateRandomDigits$1(10));
|
|
7373
|
-
const
|
|
7374
|
-
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);
|
|
7375
7198
|
const [videoBlob, setVideoBlob] = useState(null);
|
|
7376
7199
|
const [videoUrl, setVideoUrl] = useState(null);
|
|
7377
7200
|
const [audioBlob, setAudioBlob] = useState(null);
|
|
@@ -7379,11 +7202,53 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7379
7202
|
const [isConfirming, setIsConfirming] = useState(false);
|
|
7380
7203
|
const [faceCaptured, setFaceCaptured] = useState(false);
|
|
7381
7204
|
const [isReinitializing, setIsReinitializing] = useState(false);
|
|
7205
|
+
const [streamAvailable, setStreamAvailable] = useState(false);
|
|
7382
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
|
+
};
|
|
7383
7245
|
const previewRef = useRef(null);
|
|
7384
7246
|
const canvasRef = useRef(null);
|
|
7385
|
-
const { startRecording: startVideoRecording, cancelRecording: cancelVideoRecording } = useRecorder(
|
|
7386
|
-
|
|
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
|
+
}
|
|
7387
7252
|
if (blob && blob.size > 0) {
|
|
7388
7253
|
setVideoBlob(blob);
|
|
7389
7254
|
const url = URL.createObjectURL(blob);
|
|
@@ -7400,8 +7265,11 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7400
7265
|
setIsConfirming(true);
|
|
7401
7266
|
}
|
|
7402
7267
|
});
|
|
7403
|
-
const { startRecording: startAudioRecording, cancelRecording: cancelAudioRecording } = useRecorder(
|
|
7404
|
-
|
|
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
|
+
}
|
|
7405
7273
|
if (blob && blob.size > 0) {
|
|
7406
7274
|
setAudioBlob(blob);
|
|
7407
7275
|
}
|
|
@@ -7428,73 +7296,81 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7428
7296
|
}
|
|
7429
7297
|
}
|
|
7430
7298
|
};
|
|
7299
|
+
// Initialize camera and audio streams
|
|
7431
7300
|
useEffect(() => {
|
|
7432
7301
|
let isMounted = true;
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
|
|
7436
|
-
|
|
7437
|
-
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
|
|
7441
|
-
|
|
7442
|
-
|
|
7443
|
-
|
|
7444
|
-
|
|
7445
|
-
|
|
7446
|
-
|
|
7447
|
-
|
|
7448
|
-
|
|
7449
|
-
|
|
7450
|
-
|
|
7451
|
-
|
|
7452
|
-
|
|
7453
|
-
|
|
7454
|
-
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
|
|
7459
|
-
|
|
7460
|
-
console.log('Stream is active, attempting immediate play');
|
|
7461
|
-
// Ensure video element is ready
|
|
7462
|
-
if (videoElement.readyState >= 1) {
|
|
7463
|
-
videoElement.play().catch(err => {
|
|
7464
|
-
console.error('Failed to play video immediately:', err);
|
|
7465
|
-
});
|
|
7466
|
-
}
|
|
7467
|
-
else {
|
|
7468
|
-
console.log('Video element not ready yet, waiting for metadata');
|
|
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
|
|
7469
7329
|
}
|
|
7470
7330
|
}
|
|
7471
|
-
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
};
|
|
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;
|
|
7487
7346
|
}
|
|
7488
|
-
|
|
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
|
+
};
|
|
7489
7365
|
}
|
|
7490
|
-
}, [
|
|
7366
|
+
}, [streamAvailable, state, isConfirming]);
|
|
7491
7367
|
// Auto-start countdown when streams become available after reinitialization
|
|
7492
7368
|
useEffect(() => {
|
|
7493
|
-
if (state === 'preparation' &&
|
|
7369
|
+
if (state === 'preparation' && streamRef.current && audioStreamRef.current && !isConfirming && isReinitializing) {
|
|
7494
7370
|
console.log('Streams reinitialized, ready for next recording');
|
|
7495
7371
|
setIsReinitializing(false);
|
|
7496
7372
|
}
|
|
7497
|
-
}, [state,
|
|
7373
|
+
}, [state, isConfirming, isReinitializing]);
|
|
7498
7374
|
// Preparation countdown
|
|
7499
7375
|
useEffect(() => {
|
|
7500
7376
|
console.log('Countdown useEffect - state:', state, 'prepTimer:', prepTimer);
|
|
@@ -7505,7 +7381,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7505
7381
|
}
|
|
7506
7382
|
else {
|
|
7507
7383
|
// Ensure streams are available before starting recording
|
|
7508
|
-
if (!
|
|
7384
|
+
if (!streamRef.current || !audioStreamRef.current) {
|
|
7509
7385
|
console.error('Streams not available for recording, resetting to preparation');
|
|
7510
7386
|
setState('preparation');
|
|
7511
7387
|
setPrepTimer(PREP_SECONDS$1);
|
|
@@ -7517,7 +7393,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7517
7393
|
startAudioRecording();
|
|
7518
7394
|
}
|
|
7519
7395
|
}
|
|
7520
|
-
}, [state, prepTimer, startVideoRecording, startAudioRecording
|
|
7396
|
+
}, [state, prepTimer, startVideoRecording, startAudioRecording]);
|
|
7521
7397
|
// Recording timer
|
|
7522
7398
|
useEffect(() => {
|
|
7523
7399
|
if (state === 'recording') {
|
|
@@ -7543,7 +7419,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7543
7419
|
return;
|
|
7544
7420
|
}
|
|
7545
7421
|
// Ensure streams are available before starting
|
|
7546
|
-
if (!
|
|
7422
|
+
if (!streamRef.current || !audioStreamRef.current) {
|
|
7547
7423
|
console.log('Streams not available, requesting permissions...');
|
|
7548
7424
|
setIsReinitializing(true);
|
|
7549
7425
|
await requestPermissions();
|
|
@@ -7551,7 +7427,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7551
7427
|
// Wait a bit for streams to initialize
|
|
7552
7428
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
7553
7429
|
// Check again after waiting
|
|
7554
|
-
if (!
|
|
7430
|
+
if (!streamRef.current || !audioStreamRef.current) {
|
|
7555
7431
|
console.error('Streams still not available after requesting permissions');
|
|
7556
7432
|
setIsReinitializing(false);
|
|
7557
7433
|
return;
|
|
@@ -7565,8 +7441,15 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7565
7441
|
const handleCancel = () => {
|
|
7566
7442
|
cancelVideoRecording();
|
|
7567
7443
|
cancelAudioRecording();
|
|
7568
|
-
|
|
7569
|
-
|
|
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);
|
|
7570
7453
|
setState('preparation');
|
|
7571
7454
|
setIsConfirming(false);
|
|
7572
7455
|
setVideoUrl(null);
|
|
@@ -7762,7 +7645,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7762
7645
|
transition: 'background 0.2s',
|
|
7763
7646
|
margin: '0 8px',
|
|
7764
7647
|
};
|
|
7765
|
-
if (isLoading ||
|
|
7648
|
+
if (isLoading || isReinitializing) {
|
|
7766
7649
|
return (jsx("div", { className: className, style: wrapperStyle, children: jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsx("div", { style: {
|
|
7767
7650
|
width: 48,
|
|
7768
7651
|
height: 48,
|
|
@@ -7815,6 +7698,77 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7815
7698
|
borderRadius: 8,
|
|
7816
7699
|
objectFit: 'cover'
|
|
7817
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 };
|
|
7818
7772
|
};// spinner animation
|
|
7819
7773
|
const spinnerStyle = `
|
|
7820
7774
|
@keyframes spin {
|
|
@@ -8171,4 +8125,97 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
|
|
|
8171
8125
|
maxWidth: '300px',
|
|
8172
8126
|
marginBottom: '16px',
|
|
8173
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 };
|
|
8174
8221
|
};export{DocScan,FaceCapture,FaceRecorder,VoiceRecorder,useAudioPermissions,usePermissions,useRecorder};
|
package/dist/index.js
CHANGED
|
@@ -7060,23 +7060,7 @@ function numberToWord(num) {
|
|
|
7060
7060
|
}
|
|
7061
7061
|
function numbersToPhrase(numbers) {
|
|
7062
7062
|
return numbers.map(numberToWord).join(' ');
|
|
7063
|
-
}
|
|
7064
|
-
const VIDEO_READY_STATES = {
|
|
7065
|
-
// 0 means the video element is not ready
|
|
7066
|
-
// 1 means the video element is ready
|
|
7067
|
-
// 2 means the video element is loading
|
|
7068
|
-
// 3 means the video element is ended
|
|
7069
|
-
// 4 means the video element is seeking
|
|
7070
|
-
// 5 means the video element is paused
|
|
7071
|
-
// 6 means the video element is playing
|
|
7072
|
-
0: 'not ready',
|
|
7073
|
-
1: 'ready',
|
|
7074
|
-
2: 'loading',
|
|
7075
|
-
3: 'ended',
|
|
7076
|
-
4: 'seeking',
|
|
7077
|
-
5: 'paused',
|
|
7078
|
-
6: 'playing'
|
|
7079
|
-
};const useRecorder = (stream, type, onStopRecording) => {
|
|
7063
|
+
}const useRecorder = (stream, type, onStopRecording) => {
|
|
7080
7064
|
const [isRecording, setIsRecording] = react.useState(false);
|
|
7081
7065
|
const recorderRef = react.useRef(null);
|
|
7082
7066
|
const timeoutRef = react.useRef(null);
|
|
@@ -7172,170 +7156,6 @@ const VIDEO_READY_STATES = {
|
|
|
7172
7156
|
}
|
|
7173
7157
|
};
|
|
7174
7158
|
return { isRecording, startRecording, stopRecording, cancelRecording };
|
|
7175
|
-
};const usePermissions = ({ rectWidth = 1920, rectHeight = 1080 } = {}) => {
|
|
7176
|
-
const [permission, setPermission] = react.useState(false);
|
|
7177
|
-
const [stream, setStream] = react.useState(null);
|
|
7178
|
-
const [isLoading, setIsLoading] = react.useState(true);
|
|
7179
|
-
const stopStreamTracks = () => {
|
|
7180
|
-
if (stream) {
|
|
7181
|
-
stream.getTracks().forEach(track => {
|
|
7182
|
-
track.stop();
|
|
7183
|
-
});
|
|
7184
|
-
setStream(null);
|
|
7185
|
-
}
|
|
7186
|
-
};
|
|
7187
|
-
const getAdaptiveConstraints = () => {
|
|
7188
|
-
// Detect device capabilities and choose appropriate quality
|
|
7189
|
-
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7190
|
-
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7191
|
-
// High-end device settings
|
|
7192
|
-
if (!isMobile && !isLowEndDevice) {
|
|
7193
|
-
return {
|
|
7194
|
-
audio: {
|
|
7195
|
-
echoCancellation: true,
|
|
7196
|
-
noiseSuppression: true,
|
|
7197
|
-
autoGainControl: true,
|
|
7198
|
-
sampleRate: 48000,
|
|
7199
|
-
channelCount: 2
|
|
7200
|
-
},
|
|
7201
|
-
video: {
|
|
7202
|
-
width: { ideal: Math.min(rectWidth, 1920), min: 1280 },
|
|
7203
|
-
height: { ideal: Math.min(rectHeight, 1080), min: 720 },
|
|
7204
|
-
frameRate: { ideal: 30, min: 24 },
|
|
7205
|
-
facingMode: 'user',
|
|
7206
|
-
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
7207
|
-
}
|
|
7208
|
-
};
|
|
7209
|
-
}
|
|
7210
|
-
// Mobile device settings
|
|
7211
|
-
if (isMobile) {
|
|
7212
|
-
return {
|
|
7213
|
-
audio: {
|
|
7214
|
-
echoCancellation: true,
|
|
7215
|
-
noiseSuppression: true,
|
|
7216
|
-
autoGainControl: true,
|
|
7217
|
-
sampleRate: 22050, // Lower for mobile
|
|
7218
|
-
channelCount: 1
|
|
7219
|
-
},
|
|
7220
|
-
video: {
|
|
7221
|
-
width: { ideal: Math.min(rectWidth, 1280), min: 640 },
|
|
7222
|
-
height: { ideal: Math.min(rectHeight, 720), min: 480 },
|
|
7223
|
-
frameRate: { ideal: 24, min: 15 },
|
|
7224
|
-
facingMode: 'user',
|
|
7225
|
-
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
7226
|
-
}
|
|
7227
|
-
};
|
|
7228
|
-
}
|
|
7229
|
-
// Low-end device settings
|
|
7230
|
-
return {
|
|
7231
|
-
audio: {
|
|
7232
|
-
echoCancellation: true,
|
|
7233
|
-
noiseSuppression: true,
|
|
7234
|
-
autoGainControl: true,
|
|
7235
|
-
sampleRate: 22050,
|
|
7236
|
-
channelCount: 1
|
|
7237
|
-
},
|
|
7238
|
-
video: {
|
|
7239
|
-
width: { ideal: Math.min(rectWidth, 1280), min: 640 },
|
|
7240
|
-
height: { ideal: Math.min(rectHeight, 720), min: 480 },
|
|
7241
|
-
frameRate: { ideal: 20, min: 15 },
|
|
7242
|
-
facingMode: 'user',
|
|
7243
|
-
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
7244
|
-
}
|
|
7245
|
-
};
|
|
7246
|
-
};
|
|
7247
|
-
const requestPermissions = async () => {
|
|
7248
|
-
try {
|
|
7249
|
-
setIsLoading(true);
|
|
7250
|
-
const constraints = getAdaptiveConstraints();
|
|
7251
|
-
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7252
|
-
console.log('Media stream obtained, active:', streamData.active);
|
|
7253
|
-
setPermission(true);
|
|
7254
|
-
setStream(streamData);
|
|
7255
|
-
}
|
|
7256
|
-
catch (err) {
|
|
7257
|
-
console.error('Camera/mic permission denied:', err);
|
|
7258
|
-
setPermission(false);
|
|
7259
|
-
}
|
|
7260
|
-
finally {
|
|
7261
|
-
setIsLoading(false);
|
|
7262
|
-
}
|
|
7263
|
-
};
|
|
7264
|
-
react.useEffect(() => {
|
|
7265
|
-
void requestPermissions();
|
|
7266
|
-
}, [rectWidth, rectHeight]);
|
|
7267
|
-
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7268
|
-
};const useAudioPermissions = () => {
|
|
7269
|
-
const [permission, setPermission] = react.useState(false);
|
|
7270
|
-
const [stream, setStream] = react.useState(null);
|
|
7271
|
-
const [isLoading, setIsLoading] = react.useState(true);
|
|
7272
|
-
const stopStreamTracks = () => {
|
|
7273
|
-
if (stream) {
|
|
7274
|
-
stream.getTracks().forEach(track => {
|
|
7275
|
-
track.stop();
|
|
7276
|
-
});
|
|
7277
|
-
setStream(null);
|
|
7278
|
-
}
|
|
7279
|
-
};
|
|
7280
|
-
const getAudioConstraints = () => {
|
|
7281
|
-
// Detect device capabilities and choose appropriate quality
|
|
7282
|
-
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7283
|
-
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7284
|
-
// High-end device settings
|
|
7285
|
-
if (!isMobile && !isLowEndDevice) {
|
|
7286
|
-
return {
|
|
7287
|
-
audio: {
|
|
7288
|
-
echoCancellation: true,
|
|
7289
|
-
noiseSuppression: true,
|
|
7290
|
-
autoGainControl: true,
|
|
7291
|
-
sampleRate: 48000,
|
|
7292
|
-
channelCount: 2
|
|
7293
|
-
}
|
|
7294
|
-
};
|
|
7295
|
-
}
|
|
7296
|
-
// Mobile device settings
|
|
7297
|
-
if (isMobile) {
|
|
7298
|
-
return {
|
|
7299
|
-
audio: {
|
|
7300
|
-
echoCancellation: true,
|
|
7301
|
-
noiseSuppression: true,
|
|
7302
|
-
autoGainControl: true,
|
|
7303
|
-
sampleRate: 22050, // Lower for mobile
|
|
7304
|
-
channelCount: 1
|
|
7305
|
-
}
|
|
7306
|
-
};
|
|
7307
|
-
}
|
|
7308
|
-
// Low-end device settings
|
|
7309
|
-
return {
|
|
7310
|
-
audio: {
|
|
7311
|
-
echoCancellation: true,
|
|
7312
|
-
noiseSuppression: true,
|
|
7313
|
-
autoGainControl: true,
|
|
7314
|
-
sampleRate: 22050,
|
|
7315
|
-
channelCount: 1
|
|
7316
|
-
}
|
|
7317
|
-
};
|
|
7318
|
-
};
|
|
7319
|
-
const requestPermissions = async () => {
|
|
7320
|
-
try {
|
|
7321
|
-
setIsLoading(true);
|
|
7322
|
-
const constraints = getAudioConstraints();
|
|
7323
|
-
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7324
|
-
setPermission(true);
|
|
7325
|
-
setStream(streamData);
|
|
7326
|
-
}
|
|
7327
|
-
catch (err) {
|
|
7328
|
-
console.error('Microphone permission denied:', err);
|
|
7329
|
-
setPermission(false);
|
|
7330
|
-
}
|
|
7331
|
-
finally {
|
|
7332
|
-
setIsLoading(false);
|
|
7333
|
-
}
|
|
7334
|
-
};
|
|
7335
|
-
react.useEffect(() => {
|
|
7336
|
-
void requestPermissions();
|
|
7337
|
-
}, []);
|
|
7338
|
-
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7339
7159
|
};// spinner animation
|
|
7340
7160
|
const spinnerStyle$1 = `
|
|
7341
7161
|
@keyframes spin {
|
|
@@ -7370,8 +7190,11 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7370
7190
|
const [prepTimer, setPrepTimer] = react.useState(PREP_SECONDS$1);
|
|
7371
7191
|
const [recordTimer, setRecordTimer] = react.useState(RECORD_SECONDS$1);
|
|
7372
7192
|
const [digits, setDigits] = react.useState(generateRandomDigits$1(10));
|
|
7373
|
-
const
|
|
7374
|
-
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);
|
|
7375
7198
|
const [videoBlob, setVideoBlob] = react.useState(null);
|
|
7376
7199
|
const [videoUrl, setVideoUrl] = react.useState(null);
|
|
7377
7200
|
const [audioBlob, setAudioBlob] = react.useState(null);
|
|
@@ -7379,11 +7202,53 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7379
7202
|
const [isConfirming, setIsConfirming] = react.useState(false);
|
|
7380
7203
|
const [faceCaptured, setFaceCaptured] = react.useState(false);
|
|
7381
7204
|
const [isReinitializing, setIsReinitializing] = react.useState(false);
|
|
7205
|
+
const [streamAvailable, setStreamAvailable] = react.useState(false);
|
|
7382
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
|
+
};
|
|
7383
7245
|
const previewRef = react.useRef(null);
|
|
7384
7246
|
const canvasRef = react.useRef(null);
|
|
7385
|
-
const { startRecording: startVideoRecording, cancelRecording: cancelVideoRecording } = useRecorder(
|
|
7386
|
-
|
|
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
|
+
}
|
|
7387
7252
|
if (blob && blob.size > 0) {
|
|
7388
7253
|
setVideoBlob(blob);
|
|
7389
7254
|
const url = URL.createObjectURL(blob);
|
|
@@ -7400,8 +7265,11 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7400
7265
|
setIsConfirming(true);
|
|
7401
7266
|
}
|
|
7402
7267
|
});
|
|
7403
|
-
const { startRecording: startAudioRecording, cancelRecording: cancelAudioRecording } = useRecorder(
|
|
7404
|
-
|
|
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
|
+
}
|
|
7405
7273
|
if (blob && blob.size > 0) {
|
|
7406
7274
|
setAudioBlob(blob);
|
|
7407
7275
|
}
|
|
@@ -7428,73 +7296,81 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7428
7296
|
}
|
|
7429
7297
|
}
|
|
7430
7298
|
};
|
|
7299
|
+
// Initialize camera and audio streams
|
|
7431
7300
|
react.useEffect(() => {
|
|
7432
7301
|
let isMounted = true;
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
|
|
7436
|
-
|
|
7437
|
-
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
|
|
7441
|
-
|
|
7442
|
-
|
|
7443
|
-
|
|
7444
|
-
|
|
7445
|
-
|
|
7446
|
-
|
|
7447
|
-
|
|
7448
|
-
|
|
7449
|
-
|
|
7450
|
-
|
|
7451
|
-
|
|
7452
|
-
|
|
7453
|
-
|
|
7454
|
-
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
|
|
7459
|
-
|
|
7460
|
-
console.log('Stream is active, attempting immediate play');
|
|
7461
|
-
// Ensure video element is ready
|
|
7462
|
-
if (videoElement.readyState >= 1) {
|
|
7463
|
-
videoElement.play().catch(err => {
|
|
7464
|
-
console.error('Failed to play video immediately:', err);
|
|
7465
|
-
});
|
|
7466
|
-
}
|
|
7467
|
-
else {
|
|
7468
|
-
console.log('Video element not ready yet, waiting for metadata');
|
|
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
|
|
7469
7329
|
}
|
|
7470
7330
|
}
|
|
7471
|
-
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
};
|
|
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;
|
|
7487
7346
|
}
|
|
7488
|
-
|
|
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
|
+
};
|
|
7489
7365
|
}
|
|
7490
|
-
}, [
|
|
7366
|
+
}, [streamAvailable, state, isConfirming]);
|
|
7491
7367
|
// Auto-start countdown when streams become available after reinitialization
|
|
7492
7368
|
react.useEffect(() => {
|
|
7493
|
-
if (state === 'preparation' &&
|
|
7369
|
+
if (state === 'preparation' && streamRef.current && audioStreamRef.current && !isConfirming && isReinitializing) {
|
|
7494
7370
|
console.log('Streams reinitialized, ready for next recording');
|
|
7495
7371
|
setIsReinitializing(false);
|
|
7496
7372
|
}
|
|
7497
|
-
}, [state,
|
|
7373
|
+
}, [state, isConfirming, isReinitializing]);
|
|
7498
7374
|
// Preparation countdown
|
|
7499
7375
|
react.useEffect(() => {
|
|
7500
7376
|
console.log('Countdown useEffect - state:', state, 'prepTimer:', prepTimer);
|
|
@@ -7505,7 +7381,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7505
7381
|
}
|
|
7506
7382
|
else {
|
|
7507
7383
|
// Ensure streams are available before starting recording
|
|
7508
|
-
if (!
|
|
7384
|
+
if (!streamRef.current || !audioStreamRef.current) {
|
|
7509
7385
|
console.error('Streams not available for recording, resetting to preparation');
|
|
7510
7386
|
setState('preparation');
|
|
7511
7387
|
setPrepTimer(PREP_SECONDS$1);
|
|
@@ -7517,7 +7393,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7517
7393
|
startAudioRecording();
|
|
7518
7394
|
}
|
|
7519
7395
|
}
|
|
7520
|
-
}, [state, prepTimer, startVideoRecording, startAudioRecording
|
|
7396
|
+
}, [state, prepTimer, startVideoRecording, startAudioRecording]);
|
|
7521
7397
|
// Recording timer
|
|
7522
7398
|
react.useEffect(() => {
|
|
7523
7399
|
if (state === 'recording') {
|
|
@@ -7543,7 +7419,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7543
7419
|
return;
|
|
7544
7420
|
}
|
|
7545
7421
|
// Ensure streams are available before starting
|
|
7546
|
-
if (!
|
|
7422
|
+
if (!streamRef.current || !audioStreamRef.current) {
|
|
7547
7423
|
console.log('Streams not available, requesting permissions...');
|
|
7548
7424
|
setIsReinitializing(true);
|
|
7549
7425
|
await requestPermissions();
|
|
@@ -7551,7 +7427,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7551
7427
|
// Wait a bit for streams to initialize
|
|
7552
7428
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
7553
7429
|
// Check again after waiting
|
|
7554
|
-
if (!
|
|
7430
|
+
if (!streamRef.current || !audioStreamRef.current) {
|
|
7555
7431
|
console.error('Streams still not available after requesting permissions');
|
|
7556
7432
|
setIsReinitializing(false);
|
|
7557
7433
|
return;
|
|
@@ -7565,8 +7441,15 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7565
7441
|
const handleCancel = () => {
|
|
7566
7442
|
cancelVideoRecording();
|
|
7567
7443
|
cancelAudioRecording();
|
|
7568
|
-
|
|
7569
|
-
|
|
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);
|
|
7570
7453
|
setState('preparation');
|
|
7571
7454
|
setIsConfirming(false);
|
|
7572
7455
|
setVideoUrl(null);
|
|
@@ -7762,7 +7645,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7762
7645
|
transition: 'background 0.2s',
|
|
7763
7646
|
margin: '0 8px',
|
|
7764
7647
|
};
|
|
7765
|
-
if (isLoading ||
|
|
7648
|
+
if (isLoading || isReinitializing) {
|
|
7766
7649
|
return (jsxRuntime.jsx("div", { className: className, style: wrapperStyle, children: jsxRuntime.jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsxRuntime.jsx("div", { style: {
|
|
7767
7650
|
width: 48,
|
|
7768
7651
|
height: 48,
|
|
@@ -7815,6 +7698,77 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
|
|
|
7815
7698
|
borderRadius: 8,
|
|
7816
7699
|
objectFit: 'cover'
|
|
7817
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 };
|
|
7818
7772
|
};// spinner animation
|
|
7819
7773
|
const spinnerStyle = `
|
|
7820
7774
|
@keyframes spin {
|
|
@@ -8171,4 +8125,97 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
|
|
|
8171
8125
|
maxWidth: '300px',
|
|
8172
8126
|
marginBottom: '16px',
|
|
8173
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 };
|
|
8174
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",
|