biometry-react-components 2.0.1 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -13
- package/dist/index.d.ts +129 -62
- package/dist/index.esm.js +392 -231
- package/dist/index.js +391 -230
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
'use strict';var jsxRuntime=require('react/jsx-runtime'),React=require('react');const DocScan = ({ rectWidth = 640, rectHeight = 400, onConfirmCapture, onCapture, className, style, noShadow = false, }) => {
|
|
2
|
-
var _a;
|
|
3
2
|
const [isConfirming, setIsConfirming] = React.useState(false);
|
|
4
3
|
const [capturedUrl, setCapturedUrl] = React.useState(null);
|
|
5
4
|
const [capturedFile, setCapturedFile] = React.useState(null);
|
|
@@ -10,7 +9,6 @@
|
|
|
10
9
|
const [isFrontCamera, setIsFrontCamera] = React.useState(false);
|
|
11
10
|
const [capabilities, setCapabilities] = React.useState({});
|
|
12
11
|
const [torchOn, setTorchOn] = React.useState(false);
|
|
13
|
-
const QUALITY_MULTIPLIER = 3;
|
|
14
12
|
// Crop area (dashed area) as percentages
|
|
15
13
|
const cropTop = 0.075, cropLeft = 0.075, cropWidth = 0.85, cropHeight = 0.85;
|
|
16
14
|
const getDevices = async () => {
|
|
@@ -40,14 +38,14 @@
|
|
|
40
38
|
(async () => {
|
|
41
39
|
try {
|
|
42
40
|
const videoConstraints = {
|
|
43
|
-
width:
|
|
44
|
-
height:
|
|
41
|
+
width: { ideal: 1920 },
|
|
42
|
+
height: { ideal: 1080 },
|
|
45
43
|
};
|
|
46
44
|
if (selectedDeviceId) {
|
|
47
45
|
videoConstraints.deviceId = { exact: selectedDeviceId };
|
|
48
46
|
}
|
|
49
47
|
else {
|
|
50
|
-
videoConstraints.facingMode = "environment";
|
|
48
|
+
videoConstraints.facingMode = { ideal: "environment" };
|
|
51
49
|
}
|
|
52
50
|
const stream = await navigator.mediaDevices.getUserMedia({ video: videoConstraints });
|
|
53
51
|
if (!isMounted) {
|
|
@@ -64,8 +62,13 @@
|
|
|
64
62
|
streamRef.current = stream;
|
|
65
63
|
const track = stream.getVideoTracks()[0];
|
|
66
64
|
if (track) {
|
|
67
|
-
if (track.getCapabilities) {
|
|
68
|
-
|
|
65
|
+
if (typeof track.getCapabilities === "function") {
|
|
66
|
+
try {
|
|
67
|
+
setCapabilities(track.getCapabilities());
|
|
68
|
+
}
|
|
69
|
+
catch (_a) {
|
|
70
|
+
setCapabilities({});
|
|
71
|
+
}
|
|
69
72
|
}
|
|
70
73
|
const settings = track.getSettings();
|
|
71
74
|
let isFront = false;
|
|
@@ -109,28 +112,30 @@
|
|
|
109
112
|
streamRef.current = null;
|
|
110
113
|
}
|
|
111
114
|
};
|
|
112
|
-
}, [isConfirming,
|
|
115
|
+
}, [isConfirming, selectedDeviceId]);
|
|
113
116
|
const handleCapture = () => {
|
|
114
117
|
const video = videoRef.current;
|
|
115
118
|
if (!video)
|
|
116
119
|
return;
|
|
120
|
+
// Use native video stream dimensions for crisp, full-resolution capture
|
|
121
|
+
const vWidth = video.videoWidth || rectWidth;
|
|
122
|
+
const vHeight = video.videoHeight || rectHeight;
|
|
123
|
+
const targetAspect = rectWidth / rectHeight;
|
|
124
|
+
const videoAspect = vWidth / vHeight;
|
|
125
|
+
let sx = 0, sy = 0, sw = vWidth, sh = vHeight;
|
|
126
|
+
if (videoAspect > targetAspect) {
|
|
127
|
+
sw = vHeight * targetAspect;
|
|
128
|
+
sx = (vWidth - sw) / 2;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
sh = vWidth / targetAspect;
|
|
132
|
+
sy = (vHeight - sh) / 2;
|
|
133
|
+
}
|
|
117
134
|
const canvas = document.createElement("canvas");
|
|
118
|
-
canvas.width =
|
|
119
|
-
canvas.height =
|
|
135
|
+
canvas.width = Math.round(sw);
|
|
136
|
+
canvas.height = Math.round(sh);
|
|
120
137
|
const ctx = canvas.getContext("2d");
|
|
121
138
|
if (ctx) {
|
|
122
|
-
// Aspect-ratio crop to fill the output area
|
|
123
|
-
const videoAspect = video.videoWidth / video.videoHeight;
|
|
124
|
-
const targetAspect = rectWidth / rectHeight;
|
|
125
|
-
let sx = 0, sy = 0, sw = video.videoWidth, sh = video.videoHeight;
|
|
126
|
-
if (videoAspect > targetAspect) {
|
|
127
|
-
sw = video.videoHeight * targetAspect;
|
|
128
|
-
sx = (video.videoWidth - sw) / 2;
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
sh = video.videoWidth / targetAspect;
|
|
132
|
-
sy = (video.videoHeight - sh) / 2;
|
|
133
|
-
}
|
|
134
139
|
ctx.drawImage(video, sx, sy, sw, sh, 0, 0, canvas.width, canvas.height);
|
|
135
140
|
canvas.toBlob((blob) => {
|
|
136
141
|
if (blob) {
|
|
@@ -188,7 +193,7 @@
|
|
|
188
193
|
setTorchOn(nextTorch);
|
|
189
194
|
}
|
|
190
195
|
catch (err) {
|
|
191
|
-
console.
|
|
196
|
+
console.warn("Torch toggle failed:", err);
|
|
192
197
|
}
|
|
193
198
|
}
|
|
194
199
|
};
|
|
@@ -196,8 +201,12 @@
|
|
|
196
201
|
if (!streamRef.current)
|
|
197
202
|
return;
|
|
198
203
|
const track = streamRef.current.getVideoTracks()[0];
|
|
199
|
-
if (track && capabilities.focusMode) {
|
|
200
|
-
const focusType = capabilities.focusMode.includes("single-shot")
|
|
204
|
+
if (track && capabilities.focusMode && Array.isArray(capabilities.focusMode)) {
|
|
205
|
+
const focusType = capabilities.focusMode.includes("single-shot")
|
|
206
|
+
? "single-shot"
|
|
207
|
+
: capabilities.focusMode.includes("manual")
|
|
208
|
+
? "manual"
|
|
209
|
+
: null;
|
|
201
210
|
if (!focusType)
|
|
202
211
|
return;
|
|
203
212
|
const rect = e.currentTarget.getBoundingClientRect();
|
|
@@ -210,7 +219,7 @@
|
|
|
210
219
|
await track.applyConstraints({ advanced: [{ focusMode: focusType, pointsOfInterest: [{ x, y }] }] });
|
|
211
220
|
}
|
|
212
221
|
catch (err) {
|
|
213
|
-
console.
|
|
222
|
+
console.warn("Focus failed:", err);
|
|
214
223
|
}
|
|
215
224
|
}
|
|
216
225
|
};
|
|
@@ -236,7 +245,7 @@
|
|
|
236
245
|
display: 'flex',
|
|
237
246
|
alignItems: 'center',
|
|
238
247
|
justifyContent: 'center',
|
|
239
|
-
cursor: (
|
|
248
|
+
cursor: Array.isArray(capabilities.focusMode) && capabilities.focusMode.includes("manual") ? "crosshair" : "default"
|
|
240
249
|
};
|
|
241
250
|
const defaultDashedArea = {
|
|
242
251
|
position: 'absolute',
|
|
@@ -343,62 +352,192 @@
|
|
|
343
352
|
borderRadius: noShadow ? 0 : 8,
|
|
344
353
|
pointerEvents: 'none'
|
|
345
354
|
} }), jsxRuntime.jsx("div", { className: "docscan-dashed-area", style: defaultDashedArea, children: jsxRuntime.jsx("span", { className: "docscan-guidance-text", style: defaultGuidanceText, children: "Place your document here" }) })] }), jsxRuntime.jsx("button", { type: "button", className: "docscan-capture-btn", style: defaultCaptureButton, onClick: handleCapture, children: "Capture" })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: "docscan-preview", style: defaultPreview, children: capturedUrl && (jsxRuntime.jsx("img", { src: capturedUrl, alt: "Captured document", className: "docscan-preview-img", style: { maxWidth: '100%', maxHeight: '100%', borderRadius: 8 } })) }), jsxRuntime.jsx("div", { className: "docscan-confirm-text", style: defaultConfirmText, children: "Do you want to use this photo?" }), jsxRuntime.jsxs("div", { className: "docscan-confirm-btns", style: { display: 'flex', justifyContent: 'center', gap: 32, marginTop: 16, width: '100%' }, children: [jsxRuntime.jsx("button", { type: "button", "aria-label": "Retake", className: "docscan-icon-btn", style: defaultIconButton, 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: "docscan-icon-btn", style: defaultIconButton, 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" })] }) })] })] })) }));
|
|
355
|
+
};// Video constraints are IDEAL-ONLY - never `min` (BM-530).
|
|
356
|
+
//
|
|
357
|
+
// Without a deviceId, getUserMedia considers every camera and returns one that
|
|
358
|
+
// satisfies all required (min/max/exact) constraints. A hard `min` therefore
|
|
359
|
+
// filters cameras: with `width.min: 1280` a 640x480 laptop webcam is silently
|
|
360
|
+
// excluded and the browser falls back to whatever passes - typically a virtual
|
|
361
|
+
// camera (OBS) that accepts any resolution - or, with no such camera, throws
|
|
362
|
+
// OverconstrainedError, which used to surface as "Camera Permission Required".
|
|
363
|
+
// Chrome's camera picker for the site is narrowed the same way.
|
|
364
|
+
//
|
|
365
|
+
// The old minimums survive as floors on the ideal (`idealSize`): an HD camera
|
|
366
|
+
// is still steered to at least the same resolution as before, while a weaker
|
|
367
|
+
// camera is accepted at its best mode instead of being rejected.
|
|
368
|
+
const idealSize = (requested, floor, cap) => Math.max(floor, Math.min(requested, cap));
|
|
369
|
+
const usePermissions = ({ rectWidth = 1920, rectHeight = 1080, audio = true } = {}) => {
|
|
370
|
+
const [permission, setPermission] = React.useState(false);
|
|
371
|
+
const [stream, setStream] = React.useState(null);
|
|
372
|
+
const [isLoading, setIsLoading] = React.useState(true);
|
|
373
|
+
// The stream is mirrored in a ref so stopStreamTracks and the unmount
|
|
374
|
+
// cleanup act on the live stream rather than a stale closure, and so a
|
|
375
|
+
// getUserMedia that resolves after unmount can be stopped immediately
|
|
376
|
+
// (restored from 1.3.5, which 1.4.0 reverted).
|
|
377
|
+
const streamRef = React.useRef(null);
|
|
378
|
+
const isMountedRef = React.useRef(false);
|
|
379
|
+
const stopStreamTracks = () => {
|
|
380
|
+
const currentStream = streamRef.current;
|
|
381
|
+
if (currentStream) {
|
|
382
|
+
currentStream.getTracks().forEach(track => track.stop());
|
|
383
|
+
streamRef.current = null;
|
|
384
|
+
setStream(null);
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
const getAdaptiveConstraints = () => {
|
|
388
|
+
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
389
|
+
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
390
|
+
const baseAudio = audio ? {
|
|
391
|
+
echoCancellation: true,
|
|
392
|
+
noiseSuppression: true,
|
|
393
|
+
autoGainControl: true,
|
|
394
|
+
channelCount: 1 // Mono: the gateway downmixes with -ac 1 and the engine expects mono (BM-446)
|
|
395
|
+
} : false;
|
|
396
|
+
// High-end device settings
|
|
397
|
+
if (!isMobile && !isLowEndDevice) {
|
|
398
|
+
return {
|
|
399
|
+
audio: baseAudio ? {
|
|
400
|
+
...baseAudio,
|
|
401
|
+
sampleRate: 48000,
|
|
402
|
+
} : false,
|
|
403
|
+
video: {
|
|
404
|
+
width: { ideal: idealSize(rectWidth, 1280, 1920) },
|
|
405
|
+
height: { ideal: idealSize(rectHeight, 720, 1080) },
|
|
406
|
+
frameRate: { ideal: 30 },
|
|
407
|
+
facingMode: 'user',
|
|
408
|
+
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
// Mobile device settings
|
|
413
|
+
if (isMobile) {
|
|
414
|
+
return {
|
|
415
|
+
audio: baseAudio,
|
|
416
|
+
video: {
|
|
417
|
+
width: { ideal: idealSize(rectWidth, 640, 1280) },
|
|
418
|
+
height: { ideal: idealSize(rectHeight, 480, 720) },
|
|
419
|
+
frameRate: { ideal: 24 },
|
|
420
|
+
facingMode: 'user',
|
|
421
|
+
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
// Low-end device settings
|
|
426
|
+
return {
|
|
427
|
+
audio: baseAudio,
|
|
428
|
+
video: {
|
|
429
|
+
width: { ideal: idealSize(rectWidth, 640, 1280) },
|
|
430
|
+
height: { ideal: idealSize(rectHeight, 480, 720) },
|
|
431
|
+
frameRate: { ideal: 20 },
|
|
432
|
+
facingMode: 'user',
|
|
433
|
+
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
};
|
|
437
|
+
const requestPermissions = async () => {
|
|
438
|
+
var _a, _b;
|
|
439
|
+
try {
|
|
440
|
+
setIsLoading(true);
|
|
441
|
+
const constraints = getAdaptiveConstraints();
|
|
442
|
+
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
443
|
+
console.log('Media stream obtained, active:', streamData.active);
|
|
444
|
+
// Unmounted while getUserMedia was resolving: release the devices now,
|
|
445
|
+
// otherwise the camera/mic indicator stays on with nothing holding it.
|
|
446
|
+
if (!isMountedRef.current) {
|
|
447
|
+
streamData.getTracks().forEach(track => track.stop());
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
streamRef.current = streamData;
|
|
451
|
+
setPermission(true);
|
|
452
|
+
setStream(streamData);
|
|
453
|
+
}
|
|
454
|
+
catch (err) {
|
|
455
|
+
// Not every failure is a denied permission: OverconstrainedError names
|
|
456
|
+
// the failing rule, NotReadableError means the camera is busy.
|
|
457
|
+
const e = err;
|
|
458
|
+
console.error('biometry-react-components: getUserMedia failed:', e === null || e === void 0 ? void 0 : e.name, (_a = e === null || e === void 0 ? void 0 : e.constraint) !== null && _a !== void 0 ? _a : '', (_b = e === null || e === void 0 ? void 0 : e.message) !== null && _b !== void 0 ? _b : '');
|
|
459
|
+
if (isMountedRef.current)
|
|
460
|
+
setPermission(false);
|
|
461
|
+
}
|
|
462
|
+
finally {
|
|
463
|
+
if (isMountedRef.current)
|
|
464
|
+
setIsLoading(false);
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
React.useEffect(() => {
|
|
468
|
+
isMountedRef.current = true;
|
|
469
|
+
void requestPermissions();
|
|
470
|
+
return () => {
|
|
471
|
+
isMountedRef.current = false;
|
|
472
|
+
if (streamRef.current) {
|
|
473
|
+
streamRef.current.getTracks().forEach(track => track.stop());
|
|
474
|
+
streamRef.current = null;
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
}, [rectWidth, rectHeight, audio]);
|
|
478
|
+
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
346
479
|
};const FaceCapture = ({ rectWidth = 360, rectHeight = 576, onConfirmCapture, onCapture, className, style, noShadow = false, }) => {
|
|
347
480
|
const [isConfirming, setIsConfirming] = React.useState(false);
|
|
348
481
|
const [capturedUrl, setCapturedUrl] = React.useState(null);
|
|
349
482
|
const [capturedFile, setCapturedFile] = React.useState(null);
|
|
350
483
|
const videoRef = React.useRef(null);
|
|
351
|
-
const
|
|
352
|
-
|
|
484
|
+
const { stream, stopStreamTracks, requestPermissions} = usePermissions({
|
|
485
|
+
rectWidth,
|
|
486
|
+
rectHeight,
|
|
487
|
+
audio: false,
|
|
488
|
+
});
|
|
353
489
|
React.useEffect(() => {
|
|
354
490
|
let isMounted = true;
|
|
355
|
-
if (!isConfirming) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
if (videoRef.current) {
|
|
364
|
-
videoRef.current.srcObject = stream;
|
|
365
|
-
videoRef.current.onloadedmetadata = () => {
|
|
366
|
-
var _a;
|
|
367
|
-
(_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.play();
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
streamRef.current = stream;
|
|
371
|
-
}
|
|
372
|
-
catch (err) {
|
|
373
|
-
console.error(err);
|
|
374
|
-
}
|
|
375
|
-
})();
|
|
491
|
+
if (!isConfirming && stream && videoRef.current && isMounted) {
|
|
492
|
+
videoRef.current.srcObject = stream;
|
|
493
|
+
videoRef.current.onloadedmetadata = () => {
|
|
494
|
+
var _a;
|
|
495
|
+
(_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.play();
|
|
496
|
+
};
|
|
376
497
|
}
|
|
377
498
|
return () => {
|
|
378
499
|
isMounted = false;
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
500
|
+
};
|
|
501
|
+
}, [isConfirming, stream]);
|
|
502
|
+
React.useEffect(() => {
|
|
503
|
+
return () => {
|
|
504
|
+
if (capturedUrl) {
|
|
505
|
+
URL.revokeObjectURL(capturedUrl);
|
|
382
506
|
}
|
|
383
507
|
};
|
|
384
|
-
}, [
|
|
508
|
+
}, [capturedUrl]);
|
|
385
509
|
const handleCapture = () => {
|
|
386
510
|
const video = videoRef.current;
|
|
387
511
|
if (!video)
|
|
388
512
|
return;
|
|
389
513
|
const canvas = document.createElement("canvas");
|
|
390
|
-
|
|
391
|
-
|
|
514
|
+
const targetAspect = (rectWidth - 40) / (rectHeight - 40);
|
|
515
|
+
const vw = video.videoWidth || (rectWidth - 40);
|
|
516
|
+
const vh = video.videoHeight || (rectHeight - 40);
|
|
517
|
+
const videoAspect = vw / vh;
|
|
518
|
+
let sWidth, sHeight, sx, sy;
|
|
519
|
+
if (videoAspect > targetAspect) {
|
|
520
|
+
// Source is wider than target: crop the sides.
|
|
521
|
+
sHeight = vh;
|
|
522
|
+
sWidth = vh * targetAspect;
|
|
523
|
+
sx = (vw - sWidth) / 2;
|
|
524
|
+
sy = 0;
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
// Source is taller than target: crop top/bottom.
|
|
528
|
+
sWidth = vw;
|
|
529
|
+
sHeight = vw / targetAspect;
|
|
530
|
+
sx = 0;
|
|
531
|
+
sy = (vh - sHeight) / 2;
|
|
532
|
+
}
|
|
533
|
+
canvas.width = Math.round(sWidth);
|
|
534
|
+
canvas.height = Math.round(sHeight);
|
|
392
535
|
const ctx = canvas.getContext("2d");
|
|
393
536
|
if (ctx) {
|
|
394
|
-
ctx.drawImage(video,
|
|
537
|
+
ctx.drawImage(video, sx, sy, sWidth, sHeight, 0, 0, canvas.width, canvas.height);
|
|
395
538
|
canvas.toBlob((blob) => {
|
|
396
539
|
if (blob) {
|
|
397
|
-
|
|
398
|
-
if (streamRef.current) {
|
|
399
|
-
streamRef.current.getTracks().forEach((track) => track.stop());
|
|
400
|
-
streamRef.current = null;
|
|
401
|
-
}
|
|
540
|
+
stopStreamTracks();
|
|
402
541
|
const file = new File([blob], "face.jpg", { type: "image/jpeg" });
|
|
403
542
|
setCapturedFile(file);
|
|
404
543
|
setCapturedUrl(URL.createObjectURL(blob));
|
|
@@ -427,6 +566,7 @@
|
|
|
427
566
|
setCapturedUrl(null);
|
|
428
567
|
setCapturedFile(null);
|
|
429
568
|
setIsConfirming(false);
|
|
569
|
+
requestPermissions();
|
|
430
570
|
};
|
|
431
571
|
const wrapperStyle = {
|
|
432
572
|
background: '#fff',
|
|
@@ -450,6 +590,9 @@
|
|
|
450
590
|
display: 'flex',
|
|
451
591
|
alignItems: 'center',
|
|
452
592
|
justifyContent: 'center',
|
|
593
|
+
background: '#111',
|
|
594
|
+
borderRadius: noShadow ? 0 : 8,
|
|
595
|
+
overflow: 'hidden',
|
|
453
596
|
};
|
|
454
597
|
const ovalArea = {
|
|
455
598
|
position: 'absolute',
|
|
@@ -499,14 +642,16 @@
|
|
|
499
642
|
display: 'block',
|
|
500
643
|
};
|
|
501
644
|
const preview = {
|
|
502
|
-
|
|
503
|
-
|
|
645
|
+
position: 'relative',
|
|
646
|
+
width: rectWidth - 40,
|
|
647
|
+
height: rectHeight - 40,
|
|
504
648
|
display: 'flex',
|
|
505
649
|
alignItems: 'center',
|
|
506
650
|
justifyContent: 'center',
|
|
507
651
|
background: '#111',
|
|
508
|
-
borderRadius: 8,
|
|
652
|
+
borderRadius: noShadow ? 0 : 8,
|
|
509
653
|
margin: '0 auto',
|
|
654
|
+
overflow: 'hidden',
|
|
510
655
|
};
|
|
511
656
|
const confirmText = {
|
|
512
657
|
textAlign: 'center',
|
|
@@ -541,7 +686,12 @@
|
|
|
541
686
|
background: 'rgba(0,0,0,0.4)',
|
|
542
687
|
zIndex: 1,
|
|
543
688
|
borderRadius: noShadow ? 0 : 8,
|
|
544
|
-
} }), jsxRuntime.jsxs("div", { className: "facecapture-oval-area", style: ovalArea, children: [jsxRuntime.jsx("span", { className: "facecapture-guidance-text", style: guidanceText, children: "Place your face in the oval" }), jsxRuntime.jsx("div", { className: "facecapture-oval-dashed", style: ovalDashed })] })] }), jsxRuntime.jsx("button", { type: "button", className: "facecapture-capture-btn", style: captureButton, onClick: handleCapture, children: "Capture" })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: "facecapture-preview", style: preview, children: capturedUrl && (jsxRuntime.jsx("img", { src: capturedUrl, alt: "Captured face", className: "facecapture-preview-img", style: {
|
|
689
|
+
} }), jsxRuntime.jsxs("div", { className: "facecapture-oval-area", style: ovalArea, children: [jsxRuntime.jsx("span", { className: "facecapture-guidance-text", style: guidanceText, children: "Place your face in the oval" }), jsxRuntime.jsx("div", { className: "facecapture-oval-dashed", style: ovalDashed })] })] }), jsxRuntime.jsx("button", { type: "button", className: "facecapture-capture-btn", style: captureButton, onClick: handleCapture, children: "Capture" })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: "facecapture-preview", style: preview, children: capturedUrl && (jsxRuntime.jsx("img", { src: capturedUrl, alt: "Captured face", className: "facecapture-preview-img", style: {
|
|
690
|
+
width: '100%',
|
|
691
|
+
height: '100%',
|
|
692
|
+
objectFit: 'cover',
|
|
693
|
+
borderRadius: noShadow ? 0 : 8,
|
|
694
|
+
} })) }), jsxRuntime.jsx("div", { className: "facecapture-confirm-text", style: confirmText, children: "Do you want to use this photo?" }), jsxRuntime.jsxs("div", { className: "facecapture-confirm-btns", style: { display: 'flex', justifyContent: 'center', gap: 32, marginTop: 16, width: '100%' }, children: [jsxRuntime.jsx("button", { type: "button", "aria-label": "Retake", className: "facecapture-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: "facecapture-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" })] }) })] })] })) }));
|
|
545
695
|
};var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
546
696
|
|
|
547
697
|
function getDefaultExportFromCjs (x) {
|
|
@@ -7278,6 +7428,14 @@ function numbersToPhrase(digits) {
|
|
|
7278
7428
|
*
|
|
7279
7429
|
* Used for the face recorder's fallback challenge when the server issued none.
|
|
7280
7430
|
* Enrolment does not call this — see ENROLMENT_DIGIT_SEQUENCES.
|
|
7431
|
+
*
|
|
7432
|
+
* @deprecated as a source of liveness challenges: digits generated in the
|
|
7433
|
+
* browser don't stop replays, because whoever controls the browser can pair a
|
|
7434
|
+
* pre-recorded video with the digits it happens to say. Have your backend
|
|
7435
|
+
* generate the challenge, pass it to the face recorder as `challengeDigits`,
|
|
7436
|
+
* and send your backend's own stored copy as `phrase`. See the dev portal's
|
|
7437
|
+
* "Liveness challenge" guide. The face recorder still calls this for its
|
|
7438
|
+
* deprecated fallback when no challenge is given.
|
|
7281
7439
|
*/
|
|
7282
7440
|
function generateRandomDigits(count) {
|
|
7283
7441
|
const digits = [...CHALLENGE_DIGITS];
|
|
@@ -7286,9 +7444,65 @@ function generateRandomDigits(count) {
|
|
|
7286
7444
|
[digits[i], digits[j]] = [digits[j], digits[i]];
|
|
7287
7445
|
}
|
|
7288
7446
|
return digits.slice(0, count);
|
|
7447
|
+
}
|
|
7448
|
+
/**
|
|
7449
|
+
* Shortest liveness challenge accepted from your backend.
|
|
7450
|
+
*
|
|
7451
|
+
* The voice engine's quality check needs at least 7 recognised words, so a
|
|
7452
|
+
* shorter phrase can't be used for voice enrollment (voice auto-enrollment
|
|
7453
|
+
* skips it). We recommend issuing 8 distinct digits from 1-9.
|
|
7454
|
+
*/
|
|
7455
|
+
const MIN_CHALLENGE_DIGITS = 7;
|
|
7456
|
+
/**
|
|
7457
|
+
* Longest liveness challenge accepted from your backend. Longer phrases don't
|
|
7458
|
+
* fit a sensible recording window.
|
|
7459
|
+
*/
|
|
7460
|
+
const MAX_CHALLENGE_DIGITS = 12;
|
|
7461
|
+
/**
|
|
7462
|
+
* Validate a challenge issued by your backend and return its digits, in order
|
|
7463
|
+
* and unchanged.
|
|
7464
|
+
*
|
|
7465
|
+
* Returns `null` only when no challenge was given (`null` / `undefined`); the
|
|
7466
|
+
* face recorder then falls back to generating digits on the device, which is
|
|
7467
|
+
* deprecated. Anything else that isn't MIN_CHALLENGE_DIGITS to
|
|
7468
|
+
* MAX_CHALLENGE_DIGITS digits 0–9 throws, rather than being replaced by generated digits: a silently
|
|
7469
|
+
* swapped challenge would have the user speak digits your backend never issued.
|
|
7470
|
+
*
|
|
7471
|
+
* A string must contain only the ASCII digits `0`–`9`, with no spaces or
|
|
7472
|
+
* separators. An array must contain only integers 0–9.
|
|
7473
|
+
*/
|
|
7474
|
+
function parseChallenge(challenge) {
|
|
7475
|
+
if (challenge === null || challenge === undefined)
|
|
7476
|
+
return null;
|
|
7477
|
+
let digits;
|
|
7478
|
+
if (typeof challenge === 'string') {
|
|
7479
|
+
if (!/^[0-9]+$/.test(challenge)) {
|
|
7480
|
+
throw new Error(`Invalid liveness challenge ${JSON.stringify(challenge)}: use only the digits 0-9, with no spaces or separators.`);
|
|
7481
|
+
}
|
|
7482
|
+
digits = Array.from(challenge, c => c.charCodeAt(0) - 48);
|
|
7483
|
+
}
|
|
7484
|
+
else if (Array.isArray(challenge)) {
|
|
7485
|
+
if (!challenge.every(d => Number.isInteger(d) && d >= 0 && d <= 9)) {
|
|
7486
|
+
throw new Error(`Invalid liveness challenge ${JSON.stringify(challenge)}: every element must be an integer from 0 to 9.`);
|
|
7487
|
+
}
|
|
7488
|
+
digits = [...challenge];
|
|
7489
|
+
}
|
|
7490
|
+
else {
|
|
7491
|
+
throw new Error('Invalid liveness challenge: pass a digit string such as "48719352" or an array of digits.');
|
|
7492
|
+
}
|
|
7493
|
+
if (digits.length < MIN_CHALLENGE_DIGITS || digits.length > MAX_CHALLENGE_DIGITS) {
|
|
7494
|
+
throw new Error(`Invalid liveness challenge ${JSON.stringify(challenge)}: it has ${digits.length} digits, ${MIN_CHALLENGE_DIGITS} to ${MAX_CHALLENGE_DIGITS} are required.`);
|
|
7495
|
+
}
|
|
7496
|
+
return digits;
|
|
7289
7497
|
}function getSupportedMimeType() {
|
|
7290
|
-
if (MediaRecorder
|
|
7291
|
-
return 'video/webm
|
|
7498
|
+
if (typeof MediaRecorder === 'undefined') {
|
|
7499
|
+
return 'video/webm';
|
|
7500
|
+
}
|
|
7501
|
+
if (MediaRecorder.isTypeSupported('video/webm;codecs=vp8,opus')) {
|
|
7502
|
+
return 'video/webm;codecs=vp8,opus';
|
|
7503
|
+
}
|
|
7504
|
+
else if (MediaRecorder.isTypeSupported('video/webm;codecs=vp9,opus')) {
|
|
7505
|
+
return 'video/webm;codecs=vp9,opus';
|
|
7292
7506
|
}
|
|
7293
7507
|
else if (MediaRecorder.isTypeSupported('video/webm')) {
|
|
7294
7508
|
return 'video/webm';
|
|
@@ -7297,7 +7511,8 @@ function generateRandomDigits(count) {
|
|
|
7297
7511
|
return 'video/mp4';
|
|
7298
7512
|
}
|
|
7299
7513
|
else {
|
|
7300
|
-
console.
|
|
7514
|
+
console.warn("no suitable mimetype found for this device, defaulting to video/webm");
|
|
7515
|
+
return 'video/webm';
|
|
7301
7516
|
}
|
|
7302
7517
|
}const VIDEO_LENGTH_MS = 7000;
|
|
7303
7518
|
/**
|
|
@@ -7379,12 +7594,21 @@ const useRecorder = (stream, type, onStopRecording, lengthMs = VIDEO_LENGTH_MS)
|
|
|
7379
7594
|
}
|
|
7380
7595
|
recorderRef.current.stopRecording(() => {
|
|
7381
7596
|
const blob = recorderRef.current.getBlob();
|
|
7382
|
-
|
|
7597
|
+
const isWebm = !blob.type || blob.type.includes('webm');
|
|
7598
|
+
if (isWebm) {
|
|
7599
|
+
fixWebmDuration(blob, lengthMs, function (fixedBlob) {
|
|
7600
|
+
setIsRecording(false);
|
|
7601
|
+
recorderRef.current.destroy();
|
|
7602
|
+
recorderRef.current = null;
|
|
7603
|
+
onStopRecording(fixedBlob);
|
|
7604
|
+
}, { logger: false });
|
|
7605
|
+
}
|
|
7606
|
+
else {
|
|
7383
7607
|
setIsRecording(false);
|
|
7384
7608
|
recorderRef.current.destroy();
|
|
7385
7609
|
recorderRef.current = null;
|
|
7386
|
-
onStopRecording(
|
|
7387
|
-
}
|
|
7610
|
+
onStopRecording(blob);
|
|
7611
|
+
}
|
|
7388
7612
|
});
|
|
7389
7613
|
};
|
|
7390
7614
|
const cancelRecording = () => {
|
|
@@ -7401,140 +7625,6 @@ const useRecorder = (stream, type, onStopRecording, lengthMs = VIDEO_LENGTH_MS)
|
|
|
7401
7625
|
}
|
|
7402
7626
|
};
|
|
7403
7627
|
return { isRecording, startRecording, stopRecording, cancelRecording };
|
|
7404
|
-
};// Video constraints are IDEAL-ONLY - never `min` (BM-530).
|
|
7405
|
-
//
|
|
7406
|
-
// Without a deviceId, getUserMedia considers every camera and returns one that
|
|
7407
|
-
// satisfies all required (min/max/exact) constraints. A hard `min` therefore
|
|
7408
|
-
// filters cameras: with `width.min: 1280` a 640x480 laptop webcam is silently
|
|
7409
|
-
// excluded and the browser falls back to whatever passes - typically a virtual
|
|
7410
|
-
// camera (OBS) that accepts any resolution - or, with no such camera, throws
|
|
7411
|
-
// OverconstrainedError, which used to surface as "Camera Permission Required".
|
|
7412
|
-
// Chrome's camera picker for the site is narrowed the same way.
|
|
7413
|
-
//
|
|
7414
|
-
// The old minimums survive as floors on the ideal (`idealSize`): an HD camera
|
|
7415
|
-
// is still steered to at least the same resolution as before, while a weaker
|
|
7416
|
-
// camera is accepted at its best mode instead of being rejected.
|
|
7417
|
-
const idealSize = (requested, floor, cap) => Math.max(floor, Math.min(requested, cap));
|
|
7418
|
-
const usePermissions = ({ rectWidth = 1920, rectHeight = 1080 } = {}) => {
|
|
7419
|
-
const [permission, setPermission] = React.useState(false);
|
|
7420
|
-
const [stream, setStream] = React.useState(null);
|
|
7421
|
-
const [isLoading, setIsLoading] = React.useState(true);
|
|
7422
|
-
// The stream is mirrored in a ref so stopStreamTracks and the unmount
|
|
7423
|
-
// cleanup act on the live stream rather than a stale closure, and so a
|
|
7424
|
-
// getUserMedia that resolves after unmount can be stopped immediately
|
|
7425
|
-
// (restored from 1.3.5, which 1.4.0 reverted).
|
|
7426
|
-
const streamRef = React.useRef(null);
|
|
7427
|
-
const isMountedRef = React.useRef(false);
|
|
7428
|
-
const stopStreamTracks = () => {
|
|
7429
|
-
const currentStream = streamRef.current;
|
|
7430
|
-
if (currentStream) {
|
|
7431
|
-
currentStream.getTracks().forEach(track => track.stop());
|
|
7432
|
-
streamRef.current = null;
|
|
7433
|
-
setStream(null);
|
|
7434
|
-
}
|
|
7435
|
-
};
|
|
7436
|
-
const getAdaptiveConstraints = () => {
|
|
7437
|
-
// Detect device capabilities and choose appropriate quality
|
|
7438
|
-
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
7439
|
-
const isLowEndDevice = navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4;
|
|
7440
|
-
// High-end device settings
|
|
7441
|
-
if (!isMobile && !isLowEndDevice) {
|
|
7442
|
-
return {
|
|
7443
|
-
audio: {
|
|
7444
|
-
echoCancellation: true,
|
|
7445
|
-
noiseSuppression: true,
|
|
7446
|
-
autoGainControl: true,
|
|
7447
|
-
sampleRate: 48000,
|
|
7448
|
-
channelCount: 1 // Mono: the gateway downmixes with -ac 1 and the engine expects mono (BM-446)
|
|
7449
|
-
},
|
|
7450
|
-
video: {
|
|
7451
|
-
width: { ideal: idealSize(rectWidth, 1280, 1920) },
|
|
7452
|
-
height: { ideal: idealSize(rectHeight, 720, 1080) },
|
|
7453
|
-
frameRate: { ideal: 30 },
|
|
7454
|
-
facingMode: 'user',
|
|
7455
|
-
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
7456
|
-
}
|
|
7457
|
-
};
|
|
7458
|
-
}
|
|
7459
|
-
// Mobile device settings
|
|
7460
|
-
if (isMobile) {
|
|
7461
|
-
return {
|
|
7462
|
-
audio: {
|
|
7463
|
-
echoCancellation: true,
|
|
7464
|
-
noiseSuppression: true,
|
|
7465
|
-
autoGainControl: true,
|
|
7466
|
-
sampleRate: 22050, // Lower for mobile
|
|
7467
|
-
channelCount: 1
|
|
7468
|
-
},
|
|
7469
|
-
video: {
|
|
7470
|
-
width: { ideal: idealSize(rectWidth, 640, 1280) },
|
|
7471
|
-
height: { ideal: idealSize(rectHeight, 480, 720) },
|
|
7472
|
-
frameRate: { ideal: 24 },
|
|
7473
|
-
facingMode: 'user',
|
|
7474
|
-
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
7475
|
-
}
|
|
7476
|
-
};
|
|
7477
|
-
}
|
|
7478
|
-
// Low-end device settings
|
|
7479
|
-
return {
|
|
7480
|
-
audio: {
|
|
7481
|
-
echoCancellation: true,
|
|
7482
|
-
noiseSuppression: true,
|
|
7483
|
-
autoGainControl: true,
|
|
7484
|
-
sampleRate: 22050,
|
|
7485
|
-
channelCount: 1
|
|
7486
|
-
},
|
|
7487
|
-
video: {
|
|
7488
|
-
width: { ideal: idealSize(rectWidth, 640, 1280) },
|
|
7489
|
-
height: { ideal: idealSize(rectHeight, 480, 720) },
|
|
7490
|
-
frameRate: { ideal: 20 },
|
|
7491
|
-
facingMode: 'user',
|
|
7492
|
-
aspectRatio: { ideal: rectWidth / rectHeight }
|
|
7493
|
-
}
|
|
7494
|
-
};
|
|
7495
|
-
};
|
|
7496
|
-
const requestPermissions = async () => {
|
|
7497
|
-
var _a, _b;
|
|
7498
|
-
try {
|
|
7499
|
-
setIsLoading(true);
|
|
7500
|
-
const constraints = getAdaptiveConstraints();
|
|
7501
|
-
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7502
|
-
console.log('Media stream obtained, active:', streamData.active);
|
|
7503
|
-
// Unmounted while getUserMedia was resolving: release the devices now,
|
|
7504
|
-
// otherwise the camera/mic indicator stays on with nothing holding it.
|
|
7505
|
-
if (!isMountedRef.current) {
|
|
7506
|
-
streamData.getTracks().forEach(track => track.stop());
|
|
7507
|
-
return;
|
|
7508
|
-
}
|
|
7509
|
-
streamRef.current = streamData;
|
|
7510
|
-
setPermission(true);
|
|
7511
|
-
setStream(streamData);
|
|
7512
|
-
}
|
|
7513
|
-
catch (err) {
|
|
7514
|
-
// Not every failure is a denied permission: OverconstrainedError names
|
|
7515
|
-
// the failing rule, NotReadableError means the camera is busy.
|
|
7516
|
-
const e = err;
|
|
7517
|
-
console.error('biometry-react-components: getUserMedia failed:', e === null || e === void 0 ? void 0 : e.name, (_a = e === null || e === void 0 ? void 0 : e.constraint) !== null && _a !== void 0 ? _a : '', (_b = e === null || e === void 0 ? void 0 : e.message) !== null && _b !== void 0 ? _b : '');
|
|
7518
|
-
if (isMountedRef.current)
|
|
7519
|
-
setPermission(false);
|
|
7520
|
-
}
|
|
7521
|
-
finally {
|
|
7522
|
-
if (isMountedRef.current)
|
|
7523
|
-
setIsLoading(false);
|
|
7524
|
-
}
|
|
7525
|
-
};
|
|
7526
|
-
React.useEffect(() => {
|
|
7527
|
-
isMountedRef.current = true;
|
|
7528
|
-
void requestPermissions();
|
|
7529
|
-
return () => {
|
|
7530
|
-
isMountedRef.current = false;
|
|
7531
|
-
if (streamRef.current) {
|
|
7532
|
-
streamRef.current.getTracks().forEach(track => track.stop());
|
|
7533
|
-
streamRef.current = null;
|
|
7534
|
-
}
|
|
7535
|
-
};
|
|
7536
|
-
}, [rectWidth, rectHeight]);
|
|
7537
|
-
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7538
7628
|
};// spinner animation
|
|
7539
7629
|
const spinnerStyle$1 = `
|
|
7540
7630
|
@keyframes spin {
|
|
@@ -7556,11 +7646,41 @@ if (typeof window !== 'undefined' && typeof console !== 'undefined') {
|
|
|
7556
7646
|
const DEFAULT_RECORD_SECONDS = VIDEO_LENGTH_MS / 1000;
|
|
7557
7647
|
const DEFAULT_PREP_SECONDS = 3;
|
|
7558
7648
|
const DIGITS_NUMBER$1 = 7;
|
|
7649
|
+
/** Printed once per FaceRecorder instance when no challenge is given. */
|
|
7650
|
+
const DEVICE_CHALLENGE_WARNING = 'biometry-react-components FaceRecorder: no challengeDigits given, so the challenge was generated in the browser. ' +
|
|
7651
|
+
'This is deprecated: device-generated challenges give no replay protection. ' +
|
|
7652
|
+
'Pass a challenge issued by your backend as challengeDigits. ' +
|
|
7653
|
+
'See https://developer.biometrysolutions.com/concepts/liveness-challenge/';
|
|
7654
|
+
/**
|
|
7655
|
+
* A stable memo key for a challenge: the string itself, or the JSON of an
|
|
7656
|
+
* array (prefixed so a string and an array never share a key).
|
|
7657
|
+
*/
|
|
7658
|
+
const challengeKeyOf = (challenge) => {
|
|
7659
|
+
if (challenge === null || challenge === undefined)
|
|
7660
|
+
return null;
|
|
7661
|
+
if (typeof challenge === 'string')
|
|
7662
|
+
return `s:${challenge}`;
|
|
7663
|
+
try {
|
|
7664
|
+
return `a:${JSON.stringify(challenge)}`;
|
|
7665
|
+
}
|
|
7666
|
+
catch (_a) {
|
|
7667
|
+
// Not serialisable, so certainly invalid: let parseChallenge reject it.
|
|
7668
|
+
return `x:${String(challenge)}`;
|
|
7669
|
+
}
|
|
7670
|
+
};
|
|
7559
7671
|
const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, challengeDigits, recordingSeconds = DEFAULT_RECORD_SECONDS, countdownSeconds = DEFAULT_PREP_SECONDS, emitAudio = false, onConfirmRecording, onRecorded, className, style, noShadow = false, }) => {
|
|
7560
7672
|
const [state, setState] = React.useState('preparation');
|
|
7561
7673
|
const [prepTimer, setPrepTimer] = React.useState(countdownSeconds);
|
|
7562
7674
|
const [recordTimer, setRecordTimer] = React.useState(recordingSeconds);
|
|
7563
|
-
|
|
7675
|
+
// Keyed on the challenge's value, not its identity, so an inline array
|
|
7676
|
+
// literal (a new array every parent render) doesn't re-run the effects below.
|
|
7677
|
+
const challengeKey = challengeKeyOf(challengeDigits);
|
|
7678
|
+
// Validated whenever the value changes, so an invalid challenge throws here,
|
|
7679
|
+
// visibly, instead of quietly falling back to generated digits.
|
|
7680
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
7681
|
+
const issuedDigits = React.useMemo(() => parseChallenge(challengeDigits), [challengeKey]);
|
|
7682
|
+
const warnedDeviceChallengeRef = React.useRef(false);
|
|
7683
|
+
const [digits, setDigits] = React.useState(() => issuedDigits !== null && issuedDigits !== void 0 ? issuedDigits : generateRandomDigits(DIGITS_NUMBER$1));
|
|
7564
7684
|
const { permission, stream, stopStreamTracks, requestPermissions, isLoading } = usePermissions({ rectWidth, rectHeight });
|
|
7565
7685
|
const [videoBlob, setVideoBlob] = React.useState(null);
|
|
7566
7686
|
const [audioBlob, setAudioBlob] = React.useState(null);
|
|
@@ -7654,10 +7774,10 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, challengeDigits, reco
|
|
|
7654
7774
|
startAudioVisualization(stream);
|
|
7655
7775
|
}
|
|
7656
7776
|
else {
|
|
7657
|
-
|
|
7777
|
+
pauseAudioVisualization();
|
|
7658
7778
|
}
|
|
7659
7779
|
return () => {
|
|
7660
|
-
|
|
7780
|
+
pauseAudioVisualization();
|
|
7661
7781
|
};
|
|
7662
7782
|
}, [stream, state]);
|
|
7663
7783
|
// Recording timer
|
|
@@ -7673,19 +7793,19 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, challengeDigits, reco
|
|
|
7673
7793
|
}
|
|
7674
7794
|
}, [state, recordTimer]);
|
|
7675
7795
|
/**
|
|
7676
|
-
*
|
|
7677
|
-
* one place so every reset path applies
|
|
7796
|
+
* Use the challenge your backend issued; without one, fall back to the
|
|
7797
|
+
* deprecated generated digits. Kept in one place so every reset path applies
|
|
7798
|
+
* the same rule.
|
|
7678
7799
|
*/
|
|
7679
7800
|
const applyChallenge = () => {
|
|
7680
|
-
|
|
7681
|
-
const issued = (_a = challengeDigits === null || challengeDigits === void 0 ? void 0 : challengeDigits.filter(d => Number.isInteger(d) && d >= 0 && d <= 9)) !== null && _a !== void 0 ? _a : [];
|
|
7682
|
-
setDigits(issued.length > 0 ? issued : generateRandomDigits(DIGITS_NUMBER$1));
|
|
7801
|
+
setDigits(issuedDigits ? [...issuedDigits] : generateRandomDigits(DIGITS_NUMBER$1));
|
|
7683
7802
|
};
|
|
7684
7803
|
/** Build the emitted payload; `audio` is omitted unless a blob exists. */
|
|
7685
7804
|
const buildRecording = (video, audio, challenge) => ({
|
|
7686
7805
|
file: new File([video], 'face-video.webm', { type: video.type }),
|
|
7687
7806
|
...(audio ? { audio: new File([audio], 'face-audio.webm', { type: audio.type }) } : {}),
|
|
7688
7807
|
phrase: numbersToPhrase(challenge),
|
|
7808
|
+
challenge: challenge.join(''),
|
|
7689
7809
|
});
|
|
7690
7810
|
/** Return to the start after a capture that produced no usable video. */
|
|
7691
7811
|
const resetAfterFailedCapture = () => {
|
|
@@ -7700,10 +7820,14 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, challengeDigits, reco
|
|
|
7700
7820
|
};
|
|
7701
7821
|
// Adopt a challenge that arrives (or changes) while idle; never mid-capture.
|
|
7702
7822
|
React.useEffect(() => {
|
|
7823
|
+
if (issuedDigits === null && !warnedDeviceChallengeRef.current) {
|
|
7824
|
+
warnedDeviceChallengeRef.current = true;
|
|
7825
|
+
console.warn(DEVICE_CHALLENGE_WARNING);
|
|
7826
|
+
}
|
|
7703
7827
|
if (state === 'preparation')
|
|
7704
7828
|
applyChallenge();
|
|
7705
7829
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
7706
|
-
}, [
|
|
7830
|
+
}, [issuedDigits]);
|
|
7707
7831
|
const startRecording = async () => {
|
|
7708
7832
|
applyChallenge();
|
|
7709
7833
|
setRecordTimer(recordingSeconds);
|
|
@@ -7763,15 +7887,34 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, challengeDigits, reco
|
|
|
7763
7887
|
requestPermissions();
|
|
7764
7888
|
};
|
|
7765
7889
|
function startAudioVisualization(stream) {
|
|
7766
|
-
|
|
7767
|
-
|
|
7768
|
-
|
|
7769
|
-
|
|
7770
|
-
|
|
7771
|
-
|
|
7772
|
-
|
|
7890
|
+
if (!audioCtxRef.current) {
|
|
7891
|
+
const AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
7892
|
+
if (!AudioCtx)
|
|
7893
|
+
return;
|
|
7894
|
+
audioCtxRef.current = new AudioCtx();
|
|
7895
|
+
}
|
|
7896
|
+
const audioCtx = audioCtxRef.current;
|
|
7897
|
+
if (audioCtx.state === 'suspended') {
|
|
7898
|
+
audioCtx.resume().catch(() => { });
|
|
7899
|
+
}
|
|
7900
|
+
if (!analyserRef.current) {
|
|
7901
|
+
try {
|
|
7902
|
+
const source = audioCtx.createMediaStreamSource(stream);
|
|
7903
|
+
const analyser = audioCtx.createAnalyser();
|
|
7904
|
+
analyser.fftSize = 256;
|
|
7905
|
+
source.connect(analyser);
|
|
7906
|
+
analyserRef.current = analyser;
|
|
7907
|
+
}
|
|
7908
|
+
catch (err) {
|
|
7909
|
+
console.warn('Audio visualization setup failed:', err);
|
|
7910
|
+
return;
|
|
7911
|
+
}
|
|
7912
|
+
}
|
|
7913
|
+
const analyser = analyserRef.current;
|
|
7773
7914
|
const bufferLength = analyser.frequencyBinCount;
|
|
7774
7915
|
const dataArray = new Uint8Array(bufferLength);
|
|
7916
|
+
if (rafRef.current)
|
|
7917
|
+
cancelAnimationFrame(rafRef.current);
|
|
7775
7918
|
function update() {
|
|
7776
7919
|
analyser.getByteFrequencyData(dataArray);
|
|
7777
7920
|
// Calculate average volume (0–1)
|
|
@@ -7781,16 +7924,24 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, challengeDigits, reco
|
|
|
7781
7924
|
}
|
|
7782
7925
|
update();
|
|
7783
7926
|
}
|
|
7784
|
-
function
|
|
7785
|
-
var _a, _b;
|
|
7927
|
+
function pauseAudioVisualization() {
|
|
7786
7928
|
if (rafRef.current)
|
|
7787
7929
|
cancelAnimationFrame(rafRef.current);
|
|
7788
7930
|
rafRef.current = null;
|
|
7789
|
-
(
|
|
7790
|
-
|
|
7931
|
+
setMicLevel(0);
|
|
7932
|
+
}
|
|
7933
|
+
function stopAudioVisualization() {
|
|
7934
|
+
var _a, _b;
|
|
7935
|
+
pauseAudioVisualization();
|
|
7936
|
+
try {
|
|
7937
|
+
(_a = analyserRef.current) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
7938
|
+
(_b = audioCtxRef.current) === null || _b === void 0 ? void 0 : _b.close();
|
|
7939
|
+
}
|
|
7940
|
+
catch (_c) {
|
|
7941
|
+
// ignore
|
|
7942
|
+
}
|
|
7791
7943
|
audioCtxRef.current = null;
|
|
7792
7944
|
analyserRef.current = null;
|
|
7793
|
-
setMicLevel(0);
|
|
7794
7945
|
}
|
|
7795
7946
|
const wrapperStyle = {
|
|
7796
7947
|
background: '#fff',
|
|
@@ -7992,7 +8143,7 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, challengeDigits, reco
|
|
|
7992
8143
|
background: 'rgba(0,0,0,0.4)',
|
|
7993
8144
|
zIndex: 1,
|
|
7994
8145
|
borderRadius: noShadow ? 0 : 8,
|
|
7995
|
-
} }), 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 })), (state === 'recording' || state === 'preparation') && (jsxRuntime.jsxs("div", { style: soundwaveStyle, children: [jsxRuntime.jsx("div", { style: { ...barBase, height: `${8 + micLevel * 30}px` } }), jsxRuntime.jsx("div", { style: { ...barBase, height: `${4 + micLevel * 40}px` } }), jsxRuntime.jsx("div", { style: { ...barBase, height: `${10 + micLevel * 20}px` } })] }))] }), jsxRuntime.jsx("div", { style: numberRow, children: (state === 'recording' ? digits : Array(
|
|
8146
|
+
} }), 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 })), (state === 'recording' || state === 'preparation') && (jsxRuntime.jsxs("div", { style: soundwaveStyle, children: [jsxRuntime.jsx("div", { style: { ...barBase, height: `${8 + micLevel * 30}px` } }), jsxRuntime.jsx("div", { style: { ...barBase, height: `${4 + micLevel * 40}px` } }), jsxRuntime.jsx("div", { style: { ...barBase, height: `${10 + micLevel * 20}px` } })] }))] }), jsxRuntime.jsx("div", { style: numberRow, children: (state === 'recording' ? digits : Array(digits.length).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: {
|
|
7996
8147
|
display: 'flex',
|
|
7997
8148
|
flexDirection: 'column',
|
|
7998
8149
|
alignItems: 'center',
|
|
@@ -8007,11 +8158,21 @@ const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, challengeDigits, reco
|
|
|
8007
8158
|
borderRadius: '50%',
|
|
8008
8159
|
animation: 'spin 1s linear infinite',
|
|
8009
8160
|
marginBottom: 16,
|
|
8010
|
-
} }), jsxRuntime.jsx("div", { style: { fontSize: 18, fontWeight: 500, marginBottom: 8 }, children: "Processing video..." }), jsxRuntime.jsx("div", { style: { fontSize: 14, opacity: 0.8 }, children: "Please wait while we prepare your recording" })] }) }) })), state === 'result' && isConfirming && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: "facerecorder-preview", style: preview, children: videoUrl && (jsxRuntime.jsx("video", { ref: previewRef, src: videoUrl, controls: true, style: {
|
|
8161
|
+
} }), jsxRuntime.jsx("div", { style: { fontSize: 18, fontWeight: 500, marginBottom: 8 }, children: "Processing video..." }), jsxRuntime.jsx("div", { style: { fontSize: 14, opacity: 0.8 }, children: "Please wait while we prepare your recording" })] }) }) })), state === 'result' && isConfirming && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: "facerecorder-preview", style: preview, children: videoUrl && (jsxRuntime.jsx("video", { ref: previewRef, src: videoUrl, controls: true, playsInline: true, style: {
|
|
8011
8162
|
width: '100%',
|
|
8012
8163
|
height: '100%',
|
|
8013
8164
|
borderRadius: 8,
|
|
8014
8165
|
objectFit: 'cover'
|
|
8166
|
+
}, onLoadedMetadata: (e) => {
|
|
8167
|
+
const video = e.currentTarget;
|
|
8168
|
+
if (video && (!isFinite(video.duration) || video.duration > 86400)) {
|
|
8169
|
+
video.currentTime = 1e101;
|
|
8170
|
+
const onTimeUpdate = () => {
|
|
8171
|
+
video.removeEventListener('timeupdate', onTimeUpdate);
|
|
8172
|
+
video.currentTime = 0;
|
|
8173
|
+
};
|
|
8174
|
+
video.addEventListener('timeupdate', onTimeUpdate);
|
|
8175
|
+
}
|
|
8015
8176
|
}, 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" })] }) })] })] }))] }));
|
|
8016
8177
|
};const useAudioPermissions = () => {
|
|
8017
8178
|
const [permission, setPermission] = React.useState(false);
|
|
@@ -8513,4 +8674,4 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, takes = DEFAULT_TAKES, onC
|
|
|
8513
8674
|
maxWidth: '300px',
|
|
8514
8675
|
marginBottom: '16px',
|
|
8515
8676
|
} })), 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" })] }) })] })] }) }))] }));
|
|
8516
|
-
};exports.CHALLENGE_DIGITS=CHALLENGE_DIGITS;exports.DocScan=DocScan;exports.ENROLMENT_DIGIT_SEQUENCES=ENROLMENT_DIGIT_SEQUENCES;exports.FaceCapture=FaceCapture;exports.FaceRecorder=FaceRecorder;exports.VoiceRecorder=VoiceRecorder;exports.generateRandomDigits=generateRandomDigits;exports.numbersToPhrase=numbersToPhrase;exports.useAudioPermissions=useAudioPermissions;exports.usePermissions=usePermissions;exports.useRecorder=useRecorder;
|
|
8677
|
+
};exports.CHALLENGE_DIGITS=CHALLENGE_DIGITS;exports.DocScan=DocScan;exports.ENROLMENT_DIGIT_SEQUENCES=ENROLMENT_DIGIT_SEQUENCES;exports.FaceCapture=FaceCapture;exports.FaceRecorder=FaceRecorder;exports.MAX_CHALLENGE_DIGITS=MAX_CHALLENGE_DIGITS;exports.MIN_CHALLENGE_DIGITS=MIN_CHALLENGE_DIGITS;exports.VoiceRecorder=VoiceRecorder;exports.generateRandomDigits=generateRandomDigits;exports.numbersToPhrase=numbersToPhrase;exports.parseChallenge=parseChallenge;exports.useAudioPermissions=useAudioPermissions;exports.usePermissions=usePermissions;exports.useRecorder=useRecorder;
|