biometry-react-components 1.2.5 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7156,6 +7156,99 @@ function numbersToPhrase(numbers) {
7156
7156
  }
7157
7157
  };
7158
7158
  return { isRecording, startRecording, stopRecording, cancelRecording };
7159
+ };const usePermissions = ({ rectWidth = 1920, rectHeight = 1080 } = {}) => {
7160
+ const [permission, setPermission] = 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
+ console.log('Media stream obtained, active:', streamData.active);
7237
+ setPermission(true);
7238
+ setStream(streamData);
7239
+ }
7240
+ catch (err) {
7241
+ console.error('Camera/mic permission denied:', err);
7242
+ setPermission(false);
7243
+ }
7244
+ finally {
7245
+ setIsLoading(false);
7246
+ }
7247
+ };
7248
+ react.useEffect(() => {
7249
+ void requestPermissions();
7250
+ }, [rectWidth, rectHeight]);
7251
+ return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
7159
7252
  };// spinner animation
7160
7253
  const spinnerStyle$1 = `
7161
7254
  @keyframes spin {
@@ -7176,7 +7269,6 @@ if (typeof window !== 'undefined' && typeof console !== 'undefined') {
7176
7269
  }
7177
7270
  const RECORD_SECONDS$1 = 10;
7178
7271
  const PREP_SECONDS$1 = 3;
7179
- const FACE_CAPTURE_SECOND = 5;
7180
7272
  function generateRandomDigits$1(count) {
7181
7273
  const digits = Array.from({ length: 10 }, (_, i) => i);
7182
7274
  for (let i = digits.length - 1; i > 0; i--) {
@@ -7190,86 +7282,29 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
7190
7282
  const [prepTimer, setPrepTimer] = react.useState(PREP_SECONDS$1);
7191
7283
  const [recordTimer, setRecordTimer] = react.useState(RECORD_SECONDS$1);
7192
7284
  const [digits, setDigits] = react.useState(generateRandomDigits$1(10));
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);
7285
+ const { permission, stream, stopStreamTracks, requestPermissions, isLoading } = usePermissions({ rectWidth, rectHeight });
7198
7286
  const [videoBlob, setVideoBlob] = react.useState(null);
7199
- const [videoUrl, setVideoUrl] = react.useState(null);
7200
7287
  const [audioBlob, setAudioBlob] = react.useState(null);
7201
- const [faceImageBlob, setFaceImageBlob] = react.useState(null);
7288
+ const [videoUrl, setVideoUrl] = react.useState(null);
7202
7289
  const [isConfirming, setIsConfirming] = react.useState(false);
7203
- const [faceCaptured, setFaceCaptured] = react.useState(false);
7204
- const [isReinitializing, setIsReinitializing] = react.useState(false);
7205
- const [streamAvailable, setStreamAvailable] = react.useState(false);
7206
7290
  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
- };
7245
7291
  const previewRef = react.useRef(null);
7246
- const canvasRef = react.useRef(null);
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
- }
7292
+ // Video recorder
7293
+ const { startRecording: startVideoRecording, cancelRecording: cancelVideoRecording } = useRecorder(stream, "video", (blob) => {
7252
7294
  if (blob && blob.size > 0) {
7253
7295
  setVideoBlob(blob);
7254
7296
  const url = URL.createObjectURL(blob);
7255
7297
  setVideoUrl(url);
7256
- setState('result');
7257
- setIsConfirming(true);
7258
7298
  }
7259
7299
  else {
7260
7300
  const dummyBlob = new Blob(['dummy video data'], { type: 'video/webm' });
7261
7301
  setVideoBlob(dummyBlob);
7262
7302
  const url = URL.createObjectURL(dummyBlob);
7263
7303
  setVideoUrl(url);
7264
- setState('result');
7265
- setIsConfirming(true);
7266
7304
  }
7267
7305
  });
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
- }
7306
+ // Audio recorder
7307
+ const { startRecording: startAudioRecording, cancelRecording: cancelAudioRecording } = useRecorder(stream, "audio", (blob) => {
7273
7308
  if (blob && blob.size > 0) {
7274
7309
  setAudioBlob(blob);
7275
7310
  }
@@ -7277,100 +7312,28 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
7277
7312
  const dummyBlob = new Blob(['dummy audio data'], { type: 'audio/webm' });
7278
7313
  setAudioBlob(dummyBlob);
7279
7314
  }
7315
+ // Only show result when both recordings are done
7316
+ // Video callback will be called first, then audio
7317
+ stopStreamTracks();
7318
+ setState('result');
7319
+ setIsConfirming(true);
7280
7320
  });
7281
- const captureFaceImage = () => {
7282
- if (videoRef.current && canvasRef.current && !faceCaptured) {
7283
- const video = videoRef.current;
7284
- const canvas = canvasRef.current;
7285
- const ctx = canvas.getContext('2d');
7286
- if (ctx) {
7287
- canvas.width = video.videoWidth;
7288
- canvas.height = video.videoHeight;
7289
- ctx.drawImage(video, 0, 0);
7290
- canvas.toBlob((blob) => {
7291
- if (blob) {
7292
- setFaceImageBlob(blob);
7293
- setFaceCaptured(true);
7294
- }
7295
- }, 'image/jpeg', 0.9);
7296
- }
7297
- }
7298
- };
7299
- // Initialize camera and audio streams
7300
7321
  react.useEffect(() => {
7301
7322
  let isMounted = true;
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;
7346
- }
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;
7323
+ console.log('Camera setup useEffect - state:', state, 'isConfirming:', isConfirming);
7324
+ if (!isConfirming && state !== 'result' && stream) {
7357
7325
  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);
7326
+ if (videoRef.current && isMounted) {
7327
+ videoRef.current.srcObject = stream;
7328
+ videoRef.current.onloadedmetadata = () => {
7329
+ var _a;
7330
+ console.log('Video metadata loaded, playing...');
7331
+ (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.play();
7332
+ };
7333
+ }
7334
+ console.log('Stream ref set successfully');
7372
7335
  }
7373
- }, [state, isConfirming, isReinitializing]);
7336
+ }, [isConfirming, state, stream]);
7374
7337
  // Preparation countdown
7375
7338
  react.useEffect(() => {
7376
7339
  console.log('Countdown useEffect - state:', state, 'prepTimer:', prepTimer);
@@ -7380,15 +7343,9 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
7380
7343
  return () => clearTimeout(t);
7381
7344
  }
7382
7345
  else {
7383
- // Ensure streams are available before starting recording
7384
- if (!streamRef.current || !audioStreamRef.current) {
7385
- console.error('Streams not available for recording, resetting to preparation');
7386
- setState('preparation');
7387
- setPrepTimer(PREP_SECONDS$1);
7388
- return;
7389
- }
7390
7346
  setState('recording');
7391
7347
  setPrepTimer(PREP_SECONDS$1);
7348
+ // Start both video and audio recording simultaneously
7392
7349
  startVideoRecording();
7393
7350
  startAudioRecording();
7394
7351
  }
@@ -7398,13 +7355,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
7398
7355
  react.useEffect(() => {
7399
7356
  if (state === 'recording') {
7400
7357
  if (recordTimer > 0) {
7401
- const t = setTimeout(() => {
7402
- const newTimer = recordTimer - 1;
7403
- setRecordTimer(newTimer);
7404
- if (newTimer === RECORD_SECONDS$1 - FACE_CAPTURE_SECOND) {
7405
- captureFaceImage();
7406
- }
7407
- }, 1000);
7358
+ const t = setTimeout(() => setRecordTimer(recordTimer - 1), 1000);
7408
7359
  return () => clearTimeout(t);
7409
7360
  }
7410
7361
  else {
@@ -7413,72 +7364,45 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
7413
7364
  }
7414
7365
  }, [state, recordTimer]);
7415
7366
  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
- }
7436
7367
  setDigits(generateRandomDigits$1(10));
7437
7368
  setRecordTimer(RECORD_SECONDS$1);
7438
- setFaceCaptured(false);
7439
7369
  setState('countdown');
7440
7370
  };
7441
7371
  const handleCancel = () => {
7372
+ // Cancel both recordings first
7442
7373
  cancelVideoRecording();
7443
7374
  cancelAudioRecording();
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);
7375
+ // Then stop stream and reset state
7376
+ stopStreamTracks();
7453
7377
  setState('preparation');
7454
7378
  setIsConfirming(false);
7455
7379
  setVideoUrl(null);
7456
7380
  setVideoBlob(null);
7457
7381
  setAudioBlob(null);
7458
- setFaceImageBlob(null);
7459
- setFaceCaptured(false);
7382
+ // Reset digits for next recording
7383
+ setDigits(generateRandomDigits$1(10));
7384
+ // Restart the stream for cancellation
7460
7385
  requestPermissions();
7461
- requestAudioPermissions();
7462
7386
  };
7463
7387
  const handleConfirm = () => {
7464
- if (videoBlob && audioBlob && faceImageBlob) {
7388
+ if (videoBlob && audioBlob) {
7389
+ // Create file objects
7465
7390
  const videoFile = new File([videoBlob], 'face-video.webm', { type: videoBlob.type });
7466
7391
  const audioFile = new File([audioBlob], 'face-audio.webm', { type: audioBlob.type });
7467
- const faceFile = new File([faceImageBlob], 'face-image.jpg', { type: 'image/jpeg' });
7468
- onCapture(videoFile, faceFile, audioFile, numbersToPhrase(digits));
7392
+ // Call onCapture immediately with both files
7393
+ onCapture(videoFile, audioFile, numbersToPhrase(digits));
7394
+ // Clean up and reset state
7469
7395
  if (videoUrl)
7470
7396
  URL.revokeObjectURL(videoUrl);
7471
7397
  setVideoUrl(null);
7472
7398
  setVideoBlob(null);
7473
7399
  setAudioBlob(null);
7474
- setFaceImageBlob(null);
7475
- setFaceCaptured(false);
7476
7400
  setIsConfirming(false);
7477
7401
  setState('preparation');
7478
- setIsReinitializing(true);
7479
- // Reinitialize streams after confirming
7402
+ // Reset digits for next recording
7403
+ setDigits(generateRandomDigits$1(10));
7404
+ // Restart stream for next recording
7480
7405
  requestPermissions();
7481
- requestAudioPermissions();
7482
7406
  }
7483
7407
  };
7484
7408
  const handleDecline = () => {
@@ -7487,12 +7411,12 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
7487
7411
  setVideoUrl(null);
7488
7412
  setVideoBlob(null);
7489
7413
  setAudioBlob(null);
7490
- setFaceImageBlob(null);
7491
- setFaceCaptured(false);
7492
7414
  setIsConfirming(false);
7493
7415
  setState('preparation');
7416
+ // Reset digits for next recording
7417
+ setDigits(generateRandomDigits$1(10));
7418
+ // Restart the stream for retake
7494
7419
  requestPermissions();
7495
- requestAudioPermissions();
7496
7420
  };
7497
7421
  const wrapperStyle = {
7498
7422
  background: '#fff',
@@ -7527,7 +7451,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
7527
7451
  transform: 'translateX(-50%)',
7528
7452
  width: '72%',
7529
7453
  height: '68%',
7530
- zIndex: 3,
7454
+ zIndex: 2,
7531
7455
  display: 'flex',
7532
7456
  flexDirection: 'column',
7533
7457
  alignItems: 'center',
@@ -7559,16 +7483,16 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
7559
7483
  justifyContent: 'center',
7560
7484
  gap: 4,
7561
7485
  margin: '16px 0 24px 0',
7562
- flexWrap: 'nowrap',
7486
+ width: '100%',
7563
7487
  maxWidth: rectWidth - 40,
7564
7488
  };
7565
7489
  const numberBox = {
7566
- minWidth: 22,
7567
- minHeight: 30,
7490
+ minWidth: 24,
7491
+ minHeight: 32,
7568
7492
  background: '#f5f5f5',
7569
7493
  border: '2px solid #333',
7570
7494
  borderRadius: 4,
7571
- fontSize: 14,
7495
+ fontSize: 16,
7572
7496
  fontWeight: 600,
7573
7497
  color: '#333',
7574
7498
  display: 'flex',
@@ -7576,6 +7500,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
7576
7500
  justifyContent: 'center',
7577
7501
  boxShadow: '0 1px 4px rgba(0,0,0,0.08)',
7578
7502
  transition: 'background 0.3s',
7503
+ flex: '1',
7504
+ maxWidth: '28px',
7579
7505
  };
7580
7506
  const timerStyle = {
7581
7507
  position: 'absolute',
@@ -7587,7 +7513,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
7587
7513
  fontWeight: 600,
7588
7514
  borderRadius: 8,
7589
7515
  padding: '4px 14px',
7590
- zIndex: 4,
7516
+ zIndex: 10,
7591
7517
  transition: 'all 0.3s',
7592
7518
  letterSpacing: 1.5,
7593
7519
  };
@@ -7600,7 +7526,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
7600
7526
  fontSize: 64,
7601
7527
  fontWeight: 700,
7602
7528
  textShadow: '0 2px 12px rgba(0,0,0,0.25)',
7603
- zIndex: 4,
7529
+ zIndex: 20,
7604
7530
  transition: 'all 0.3s',
7605
7531
  pointerEvents: 'none',
7606
7532
  };
@@ -7645,7 +7571,8 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
7645
7571
  transition: 'background 0.2s',
7646
7572
  margin: '0 8px',
7647
7573
  };
7648
- if (isLoading || isReinitializing) {
7574
+ // Show loading state while checking permissions
7575
+ if (isLoading) {
7649
7576
  return (jsxRuntime.jsx("div", { className: className, style: wrapperStyle, children: jsxRuntime.jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsxRuntime.jsx("div", { style: {
7650
7577
  width: 48,
7651
7578
  height: 48,
@@ -7654,28 +7581,26 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onCapture, className,
7654
7581
  borderRadius: '50%',
7655
7582
  animation: 'spin 1s linear infinite',
7656
7583
  margin: '0 auto 16px auto',
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." })] }) }));
7584
+ } }), jsxRuntime.jsx("h3", { children: "Initializing Camera..." }), jsxRuntime.jsx("p", { children: "Please wait while we set up your camera." })] }) }));
7658
7585
  }
7659
- if (!permission || !audioPermission) {
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: () => {
7661
- requestPermissions();
7662
- requestAudioPermissions();
7663
- }, children: "Grant Permissions" })] }) }));
7586
+ // Show permission request if no permission
7587
+ if (!permission) {
7588
+ return (jsxRuntime.jsx("div", { className: className, style: wrapperStyle, children: jsxRuntime.jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsxRuntime.jsx("h3", { children: "Camera Permission Required" }), jsxRuntime.jsx("p", { children: "Please allow camera and microphone access to use this component." }), jsxRuntime.jsx("button", { type: "button", style: actionButton, onClick: requestPermissions, children: "Grant Permissions" })] }) }));
7664
7589
  }
7665
- return (jsxRuntime.jsxs("div", { className: className, style: wrapperStyle, children: [jsxRuntime.jsx("canvas", { ref: canvasRef, style: { display: 'none' } }), state !== 'result' && state !== 'processing' && !isConfirming && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: "facerecorder-camera-area", style: cameraArea, children: [jsxRuntime.jsx("video", { ref: videoRef, width: rectWidth - 40, height: rectHeight - 40, className: "facerecorder-video", style: {
7590
+ return (jsxRuntime.jsxs("div", { className: className, style: wrapperStyle, children: [state !== 'result' && state !== 'processing' && !isConfirming && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: "facerecorder-camera-area", style: cameraArea, children: [jsxRuntime.jsx("video", { ref: videoRef, width: rectWidth - 40, height: rectHeight - 40, className: "facerecorder-video", style: {
7666
7591
  width: rectWidth - 40,
7667
7592
  height: rectHeight - 40,
7668
7593
  objectFit: 'cover',
7669
7594
  borderRadius: noShadow ? 0 : 8,
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: {
7595
+ zIndex: 0,
7596
+ }, playsInline: true, muted: true, autoPlay: true }), jsxRuntime.jsx("div", { className: "facerecorder-dark-overlay", style: {
7672
7597
  position: 'absolute',
7673
7598
  top: 0,
7674
7599
  left: 0,
7675
7600
  width: '100%',
7676
7601
  height: '100%',
7677
7602
  background: 'rgba(0,0,0,0.4)',
7678
- zIndex: 2,
7603
+ zIndex: 1,
7679
7604
  borderRadius: noShadow ? 0 : 8,
7680
7605
  } }), jsxRuntime.jsxs("div", { className: "facerecorder-oval-area", style: ovalArea, children: [jsxRuntime.jsx("span", { className: "facerecorder-guidance-text", style: guidanceText, children: "Place your face in the oval" }), jsxRuntime.jsx("div", { className: "facerecorder-oval-dashed", style: ovalDashed })] }), state === 'countdown' && (jsxRuntime.jsx("div", { style: prepTimerStyle, children: prepTimer })), state === 'recording' && (jsxRuntime.jsx("div", { style: timerStyle, children: recordTimer }))] }), jsxRuntime.jsx("div", { style: numberRow, children: (state === 'recording' ? digits : Array(10).fill('*')).map((num, i) => (jsxRuntime.jsx("div", { style: numberBox, children: num }, i))) }), state === 'preparation' && (jsxRuntime.jsx("button", { type: "button", style: actionButton, onClick: startRecording, children: "Start recording" })), state === 'recording' && (jsxRuntime.jsx("button", { type: "button", style: { ...actionButton, background: '#d32f2f' }, onClick: handleCancel, children: "Cancel" }))] })), state === 'processing' && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("div", { className: "facerecorder-processing", style: preview, children: jsxRuntime.jsxs("div", { style: {
7681
7606
  display: 'flex',
@@ -8125,97 +8050,4 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onCapture, className, styl
8125
8050
  maxWidth: '300px',
8126
8051
  marginBottom: '16px',
8127
8052
  } })), 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 };
8221
8053
  };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.5",
3
+ "version": "1.2.6",
4
4
  "type": "module",
5
5
  "description": "React UI component library for capturing high-quality biometric data (voice, face, documents, video) to facilitate integration with Biometry services",
6
6
  "main": "dist/index.js",