biometry-react-components 1.3.5 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +48 -231
- package/dist/index.js +48 -231
- package/package.json +14 -7
package/README.md
CHANGED
|
@@ -121,6 +121,10 @@ function FaceRecorder() {
|
|
|
121
121
|
|
|
122
122
|
Records audio with real-time waveform visualization and adaptive quality settings. Use this for [Voice Enrollment](https://developer.biometrysolutions.com/api/voice-enrollment/)
|
|
123
123
|
|
|
124
|
+
The user is prompted with all ten digits (`0-9`) in random order and gets a 10-second recording window. Both are enrollment requirements: the engine builds a text-prompted digit voiceprint, and verification later prompts a random subset, so the enrollment sample has to cover every digit.
|
|
125
|
+
|
|
126
|
+
> **Note:** the engine builds its voiceprint from **several** recordings. A print built from a single take carries one recording's worth of acoustic variation and scores close enough to the engine's threshold that genuine users can be rejected at login. Call the component more than once and post every take in the same enrollment request (repeated `voice` parts, one `phrase` part each).
|
|
127
|
+
|
|
124
128
|
```tsx
|
|
125
129
|
import { VoiceRecorder } from 'biometry-react-components';
|
|
126
130
|
|
package/dist/index.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ interface VoiceRecorderProps {
|
|
|
45
45
|
declare const VoiceRecorder: React.FC<VoiceRecorderProps>;
|
|
46
46
|
|
|
47
47
|
type OnStopRecordingFunc = (blob: Blob) => void;
|
|
48
|
-
declare const useRecorder: (stream: MediaStream | null, type: "audio" | "video", onStopRecording: OnStopRecordingFunc) => {
|
|
48
|
+
declare const useRecorder: (stream: MediaStream | null, type: "audio" | "video", onStopRecording: OnStopRecordingFunc, lengthMs?: number) => {
|
|
49
49
|
isRecording: boolean;
|
|
50
50
|
startRecording: () => void;
|
|
51
51
|
stopRecording: () => void;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,60 +1,19 @@
|
|
|
1
1
|
import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,useEffect}from'react';const DocScan = ({ rectWidth = 640, rectHeight = 400, onConfirmCapture, onCapture, className, style, noShadow = false, }) => {
|
|
2
|
-
var _a;
|
|
3
2
|
const [isConfirming, setIsConfirming] = useState(false);
|
|
4
3
|
const [capturedUrl, setCapturedUrl] = useState(null);
|
|
5
4
|
const [capturedFile, setCapturedFile] = useState(null);
|
|
6
5
|
const videoRef = useRef(null);
|
|
7
6
|
const streamRef = useRef(null);
|
|
8
|
-
const [devices, setDevices] = useState([]);
|
|
9
|
-
const [selectedDeviceId, setSelectedDeviceId] = useState(null);
|
|
10
|
-
const [isFrontCamera, setIsFrontCamera] = useState(false);
|
|
11
|
-
const [capabilities, setCapabilities] = useState({});
|
|
12
|
-
const [torchOn, setTorchOn] = useState(false);
|
|
13
7
|
const QUALITY_MULTIPLIER = 3;
|
|
14
8
|
// Crop area (dashed area) as percentages
|
|
15
9
|
const cropTop = 0.075, cropLeft = 0.075, cropWidth = 0.85, cropHeight = 0.85;
|
|
16
|
-
const getDevices = async () => {
|
|
17
|
-
try {
|
|
18
|
-
const all = await navigator.mediaDevices.enumerateDevices();
|
|
19
|
-
return all.filter((d) => d.kind === "videoinput");
|
|
20
|
-
}
|
|
21
|
-
catch (_a) {
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
const handleDeviceChange = async () => {
|
|
27
|
-
const vids = await getDevices();
|
|
28
|
-
setDevices(vids);
|
|
29
|
-
if (selectedDeviceId && !vids.find((d) => d.deviceId === selectedDeviceId)) {
|
|
30
|
-
// Active device disconnected, clear it to fallback to default
|
|
31
|
-
setSelectedDeviceId(null);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
navigator.mediaDevices.addEventListener("devicechange", handleDeviceChange);
|
|
35
|
-
return () => navigator.mediaDevices.removeEventListener("devicechange", handleDeviceChange);
|
|
36
|
-
}, [selectedDeviceId]);
|
|
37
10
|
useEffect(() => {
|
|
38
11
|
let isMounted = true;
|
|
39
12
|
if (!isConfirming) {
|
|
40
13
|
(async () => {
|
|
41
14
|
try {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
height: rectHeight,
|
|
45
|
-
};
|
|
46
|
-
if (selectedDeviceId) {
|
|
47
|
-
videoConstraints.deviceId = { exact: selectedDeviceId };
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
videoConstraints.facingMode = "environment";
|
|
51
|
-
}
|
|
52
|
-
const stream = await navigator.mediaDevices.getUserMedia({ video: videoConstraints });
|
|
53
|
-
if (!isMounted) {
|
|
54
|
-
stream.getTracks().forEach((track) => track.stop());
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (videoRef.current) {
|
|
15
|
+
const stream = await navigator.mediaDevices.getUserMedia({ video: { width: rectWidth, height: rectHeight } });
|
|
16
|
+
if (videoRef.current && isMounted) {
|
|
58
17
|
videoRef.current.srcObject = stream;
|
|
59
18
|
videoRef.current.onloadedmetadata = () => {
|
|
60
19
|
var _a;
|
|
@@ -62,40 +21,6 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
|
|
|
62
21
|
};
|
|
63
22
|
}
|
|
64
23
|
streamRef.current = stream;
|
|
65
|
-
const track = stream.getVideoTracks()[0];
|
|
66
|
-
if (track) {
|
|
67
|
-
if (track.getCapabilities) {
|
|
68
|
-
setCapabilities(track.getCapabilities());
|
|
69
|
-
}
|
|
70
|
-
const settings = track.getSettings();
|
|
71
|
-
let isFront = false;
|
|
72
|
-
if (settings.facingMode) {
|
|
73
|
-
isFront = settings.facingMode === "user";
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
const allVids = await getDevices();
|
|
77
|
-
const currDev = allVids.find(d => d.deviceId === settings.deviceId);
|
|
78
|
-
if (currDev)
|
|
79
|
-
isFront = currDev.label.toLowerCase().includes("front");
|
|
80
|
-
}
|
|
81
|
-
if (isMounted)
|
|
82
|
-
setIsFrontCamera(isFront);
|
|
83
|
-
if (!selectedDeviceId) {
|
|
84
|
-
const currentId = track.getSettings().deviceId;
|
|
85
|
-
if (currentId && isMounted)
|
|
86
|
-
setSelectedDeviceId(currentId);
|
|
87
|
-
}
|
|
88
|
-
track.onended = async () => {
|
|
89
|
-
if (!isMounted)
|
|
90
|
-
return;
|
|
91
|
-
const vids = await getDevices();
|
|
92
|
-
setDevices(vids);
|
|
93
|
-
setSelectedDeviceId(null);
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
const vids = await getDevices();
|
|
97
|
-
if (isMounted)
|
|
98
|
-
setDevices(vids);
|
|
99
24
|
}
|
|
100
25
|
catch (err) {
|
|
101
26
|
console.error(err);
|
|
@@ -109,7 +34,7 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
|
|
|
109
34
|
streamRef.current = null;
|
|
110
35
|
}
|
|
111
36
|
};
|
|
112
|
-
}, [isConfirming, rectWidth, rectHeight
|
|
37
|
+
}, [isConfirming, rectWidth, rectHeight]);
|
|
113
38
|
const handleCapture = () => {
|
|
114
39
|
const video = videoRef.current;
|
|
115
40
|
if (!video)
|
|
@@ -124,20 +49,18 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
|
|
|
124
49
|
const targetAspect = rectWidth / rectHeight;
|
|
125
50
|
let sx = 0, sy = 0, sw = video.videoWidth, sh = video.videoHeight;
|
|
126
51
|
if (videoAspect > targetAspect) {
|
|
52
|
+
// Video is wider than target: crop sides
|
|
127
53
|
sw = video.videoHeight * targetAspect;
|
|
128
54
|
sx = (video.videoWidth - sw) / 2;
|
|
129
55
|
}
|
|
130
56
|
else {
|
|
57
|
+
// Video is taller than target: crop top/bottom
|
|
131
58
|
sh = video.videoWidth / targetAspect;
|
|
132
59
|
sy = (video.videoHeight - sh) / 2;
|
|
133
60
|
}
|
|
134
61
|
ctx.drawImage(video, sx, sy, sw, sh, 0, 0, canvas.width, canvas.height);
|
|
135
62
|
canvas.toBlob((blob) => {
|
|
136
63
|
if (blob) {
|
|
137
|
-
if (streamRef.current) {
|
|
138
|
-
streamRef.current.getTracks().forEach((track) => track.stop());
|
|
139
|
-
streamRef.current = null;
|
|
140
|
-
}
|
|
141
64
|
const file = new File([blob], "document.jpg", { type: "image/jpeg" });
|
|
142
65
|
setCapturedFile(file);
|
|
143
66
|
setCapturedUrl(URL.createObjectURL(blob));
|
|
@@ -147,7 +70,7 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
|
|
|
147
70
|
onCapture(file);
|
|
148
71
|
}
|
|
149
72
|
catch (err) {
|
|
150
|
-
console.error(err);
|
|
73
|
+
console.error('onCapture callback threw:', err);
|
|
151
74
|
}
|
|
152
75
|
}
|
|
153
76
|
}
|
|
@@ -167,53 +90,6 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
|
|
|
167
90
|
setCapturedFile(null);
|
|
168
91
|
setIsConfirming(false);
|
|
169
92
|
};
|
|
170
|
-
const cycleCamera = (e) => {
|
|
171
|
-
e.stopPropagation();
|
|
172
|
-
if (devices.length <= 1)
|
|
173
|
-
return;
|
|
174
|
-
const currentIndex = devices.findIndex((d) => d.deviceId === selectedDeviceId);
|
|
175
|
-
const nextIndex = (currentIndex + 1) % devices.length;
|
|
176
|
-
setSelectedDeviceId(devices[nextIndex].deviceId);
|
|
177
|
-
setTorchOn(false);
|
|
178
|
-
};
|
|
179
|
-
const toggleTorch = async (e) => {
|
|
180
|
-
e.stopPropagation();
|
|
181
|
-
if (!streamRef.current)
|
|
182
|
-
return;
|
|
183
|
-
const track = streamRef.current.getVideoTracks()[0];
|
|
184
|
-
if (track && capabilities.torch) {
|
|
185
|
-
try {
|
|
186
|
-
const nextTorch = !torchOn;
|
|
187
|
-
await track.applyConstraints({ advanced: [{ torch: nextTorch }] });
|
|
188
|
-
setTorchOn(nextTorch);
|
|
189
|
-
}
|
|
190
|
-
catch (err) {
|
|
191
|
-
console.error("Torch toggle failed:", err);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
const handleCameraAreaClick = async (e) => {
|
|
196
|
-
if (!streamRef.current)
|
|
197
|
-
return;
|
|
198
|
-
const track = streamRef.current.getVideoTracks()[0];
|
|
199
|
-
if (track && capabilities.focusMode) {
|
|
200
|
-
const focusType = capabilities.focusMode.includes("single-shot") ? "single-shot" : capabilities.focusMode.includes("manual") ? "manual" : null;
|
|
201
|
-
if (!focusType)
|
|
202
|
-
return;
|
|
203
|
-
const rect = e.currentTarget.getBoundingClientRect();
|
|
204
|
-
let x = (e.clientX - rect.left) / rect.width;
|
|
205
|
-
const y = (e.clientY - rect.top) / rect.height;
|
|
206
|
-
if (isFrontCamera) {
|
|
207
|
-
x = 1 - x;
|
|
208
|
-
}
|
|
209
|
-
try {
|
|
210
|
-
await track.applyConstraints({ advanced: [{ focusMode: focusType, pointsOfInterest: [{ x, y }] }] });
|
|
211
|
-
}
|
|
212
|
-
catch (err) {
|
|
213
|
-
console.error("Focus failed:", err);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
93
|
const wrapperStyle = {
|
|
218
94
|
background: '#fff',
|
|
219
95
|
borderRadius: noShadow ? 0 : 10,
|
|
@@ -236,7 +112,6 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
|
|
|
236
112
|
display: 'flex',
|
|
237
113
|
alignItems: 'center',
|
|
238
114
|
justifyContent: 'center',
|
|
239
|
-
cursor: ((_a = capabilities.focusMode) === null || _a === void 0 ? void 0 : _a.includes("manual")) ? "crosshair" : "default"
|
|
240
115
|
};
|
|
241
116
|
const defaultDashedArea = {
|
|
242
117
|
position: 'absolute',
|
|
@@ -252,7 +127,6 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
|
|
|
252
127
|
display: 'flex',
|
|
253
128
|
flexDirection: 'column',
|
|
254
129
|
alignItems: 'center',
|
|
255
|
-
pointerEvents: 'none'
|
|
256
130
|
};
|
|
257
131
|
const defaultGuidanceText = {
|
|
258
132
|
color: '#fff',
|
|
@@ -304,34 +178,13 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
|
|
|
304
178
|
transition: 'background 0.2s',
|
|
305
179
|
margin: '0 8px',
|
|
306
180
|
};
|
|
307
|
-
|
|
308
|
-
position: 'absolute',
|
|
309
|
-
top: 8,
|
|
310
|
-
right: 8,
|
|
311
|
-
zIndex: 3,
|
|
312
|
-
display: 'flex',
|
|
313
|
-
flexDirection: 'column',
|
|
314
|
-
gap: 12,
|
|
315
|
-
};
|
|
316
|
-
const overlayBtnStyle = {
|
|
317
|
-
background: 'rgba(0,0,0,0.5)',
|
|
318
|
-
border: 'none',
|
|
319
|
-
borderRadius: '50%',
|
|
320
|
-
width: 36,
|
|
321
|
-
height: 36,
|
|
322
|
-
display: 'flex',
|
|
323
|
-
alignItems: 'center',
|
|
324
|
-
justifyContent: 'center',
|
|
325
|
-
cursor: 'pointer',
|
|
326
|
-
color: '#fff',
|
|
327
|
-
};
|
|
328
|
-
return (jsx("div", { className: className, style: wrapperStyle, children: !isConfirming ? (jsxs(Fragment, { children: [jsxs("div", { className: "docscan-camera-area", style: defaultCameraArea, onClick: handleCameraAreaClick, children: [jsxs("div", { style: controlsOverlayStyle, children: [devices.length > 1 && (jsx("button", { type: "button", onClick: cycleCamera, style: overlayBtnStyle, title: "Switch Camera", children: jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [jsx("path", { d: "M21 12A9 9 0 0 0 6 5.3L3 8" }), jsx("path", { d: "M21 3v5h-5" }), jsx("path", { d: "M3 12a9 9 0 0 0 15 6.7l3-2.7" }), jsx("path", { d: "M3 21v-5h5" })] }) })), capabilities.torch && (jsx("button", { type: "button", onClick: toggleTorch, style: { ...overlayBtnStyle, color: torchOn ? '#ffd700' : '#fff' }, title: "Toggle Flash", children: jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: jsx("polygon", { points: "13 2 3 14 12 14 11 22 21 10 12 10 13 2" }) }) }))] }), jsx("video", { ref: videoRef, width: rectWidth - 40, height: rectHeight - 40, className: "docscan-video", style: {
|
|
181
|
+
return (jsx("div", { className: className, style: wrapperStyle, children: !isConfirming ? (jsxs(Fragment, { children: [jsxs("div", { className: "docscan-camera-area", style: defaultCameraArea, children: [jsx("video", { ref: videoRef, width: rectWidth - 40, height: rectHeight - 40, className: "docscan-video", style: {
|
|
329
182
|
width: rectWidth - 40,
|
|
330
183
|
height: rectHeight - 40,
|
|
331
184
|
objectFit: 'cover',
|
|
332
185
|
borderRadius: noShadow ? 0 : 8,
|
|
333
186
|
zIndex: 0,
|
|
334
|
-
transform:
|
|
187
|
+
transform: 'scaleX(-1)'
|
|
335
188
|
}, playsInline: true, muted: true, autoPlay: true }), jsx("div", { className: "docscan-dark-overlay", style: {
|
|
336
189
|
position: 'absolute',
|
|
337
190
|
top: 0,
|
|
@@ -341,7 +194,6 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
|
|
|
341
194
|
background: 'rgba(0,0,0,0.4)',
|
|
342
195
|
zIndex: 1,
|
|
343
196
|
borderRadius: noShadow ? 0 : 8,
|
|
344
|
-
pointerEvents: 'none'
|
|
345
197
|
} }), jsx("div", { className: "docscan-dashed-area", style: defaultDashedArea, children: jsx("span", { className: "docscan-guidance-text", style: defaultGuidanceText, children: "Place your document here" }) })] }), jsx("button", { type: "button", className: "docscan-capture-btn", style: defaultCaptureButton, onClick: handleCapture, children: "Capture" })] })) : (jsxs(Fragment, { children: [jsx("div", { className: "docscan-preview", style: defaultPreview, children: capturedUrl && (jsx("img", { src: capturedUrl, alt: "Captured document", className: "docscan-preview-img", style: { maxWidth: '100%', maxHeight: '100%', borderRadius: 8 } })) }), jsx("div", { className: "docscan-confirm-text", style: defaultConfirmText, children: "Do you want to use this photo?" }), jsxs("div", { className: "docscan-confirm-btns", style: { display: 'flex', justifyContent: 'center', gap: 32, marginTop: 16, width: '100%' }, children: [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: 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: "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: 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" })] }) })] })] })) }));
|
|
346
198
|
};const FaceCapture = ({ rectWidth = 360, rectHeight = 576, onConfirmCapture, onCapture, className, style, noShadow = false, }) => {
|
|
347
199
|
const [isConfirming, setIsConfirming] = useState(false);
|
|
@@ -356,11 +208,7 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
|
|
|
356
208
|
(async () => {
|
|
357
209
|
try {
|
|
358
210
|
const stream = await navigator.mediaDevices.getUserMedia({ video: { width: rectWidth, height: rectHeight } });
|
|
359
|
-
if (
|
|
360
|
-
stream.getTracks().forEach((track) => track.stop());
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
if (videoRef.current) {
|
|
211
|
+
if (videoRef.current && isMounted) {
|
|
364
212
|
videoRef.current.srcObject = stream;
|
|
365
213
|
videoRef.current.onloadedmetadata = () => {
|
|
366
214
|
var _a;
|
|
@@ -394,11 +242,6 @@ import {jsx,jsxs,Fragment}from'react/jsx-runtime';import React,{useState,useRef,
|
|
|
394
242
|
ctx.drawImage(video, 0, 0, rectWidth, rectHeight, 0, 0, rectWidth * QUALITY_MULTIPLIER, rectHeight * QUALITY_MULTIPLIER);
|
|
395
243
|
canvas.toBlob((blob) => {
|
|
396
244
|
if (blob) {
|
|
397
|
-
// Stop the stream immediately — don't wait for useEffect cleanup
|
|
398
|
-
if (streamRef.current) {
|
|
399
|
-
streamRef.current.getTracks().forEach((track) => track.stop());
|
|
400
|
-
streamRef.current = null;
|
|
401
|
-
}
|
|
402
245
|
const file = new File([blob], "face.jpg", { type: "image/jpeg" });
|
|
403
246
|
setCapturedFile(file);
|
|
404
247
|
setCapturedUrl(URL.createObjectURL(blob));
|
|
@@ -7236,7 +7079,12 @@ function numberToWord(num) {
|
|
|
7236
7079
|
function numbersToPhrase(numbers) {
|
|
7237
7080
|
return numbers.map(numberToWord).join(' ');
|
|
7238
7081
|
}const VIDEO_LENGTH_MS = 7000;
|
|
7239
|
-
|
|
7082
|
+
/**
|
|
7083
|
+
* Voice *enrollment* reads all ten digits aloud, which does not fit in the
|
|
7084
|
+
* 7s video length unhurried. Verification keeps the shorter window (BM-407).
|
|
7085
|
+
*/
|
|
7086
|
+
const VOICE_ENROLL_LENGTH_MS = 10000;
|
|
7087
|
+
const useRecorder = (stream, type, onStopRecording, lengthMs = VIDEO_LENGTH_MS) => {
|
|
7240
7088
|
const [isRecording, setIsRecording] = useState(false);
|
|
7241
7089
|
const recorderRef = useRef(null);
|
|
7242
7090
|
const timeoutRef = useRef(null);
|
|
@@ -7294,7 +7142,7 @@ const useRecorder = (stream, type, onStopRecording) => {
|
|
|
7294
7142
|
// Set timeout to auto-stop recording
|
|
7295
7143
|
timeoutRef.current = window.setTimeout(() => {
|
|
7296
7144
|
stopRecording();
|
|
7297
|
-
},
|
|
7145
|
+
}, lengthMs);
|
|
7298
7146
|
}
|
|
7299
7147
|
catch (error) {
|
|
7300
7148
|
console.error(error);
|
|
@@ -7310,7 +7158,7 @@ const useRecorder = (stream, type, onStopRecording) => {
|
|
|
7310
7158
|
}
|
|
7311
7159
|
recorderRef.current.stopRecording(() => {
|
|
7312
7160
|
const blob = recorderRef.current.getBlob();
|
|
7313
|
-
fixWebmDuration(blob,
|
|
7161
|
+
fixWebmDuration(blob, lengthMs, function (fixedBlob) {
|
|
7314
7162
|
setIsRecording(false);
|
|
7315
7163
|
recorderRef.current.destroy();
|
|
7316
7164
|
recorderRef.current = null;
|
|
@@ -7336,13 +7184,11 @@ const useRecorder = (stream, type, onStopRecording) => {
|
|
|
7336
7184
|
const [permission, setPermission] = useState(false);
|
|
7337
7185
|
const [stream, setStream] = useState(null);
|
|
7338
7186
|
const [isLoading, setIsLoading] = useState(true);
|
|
7339
|
-
const streamRef = useRef(null);
|
|
7340
|
-
const isMountedRef = useRef(false);
|
|
7341
7187
|
const stopStreamTracks = () => {
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7188
|
+
if (stream) {
|
|
7189
|
+
stream.getTracks().forEach(track => {
|
|
7190
|
+
track.stop();
|
|
7191
|
+
});
|
|
7346
7192
|
setStream(null);
|
|
7347
7193
|
}
|
|
7348
7194
|
};
|
|
@@ -7412,35 +7258,19 @@ const useRecorder = (stream, type, onStopRecording) => {
|
|
|
7412
7258
|
const constraints = getAdaptiveConstraints();
|
|
7413
7259
|
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7414
7260
|
console.log('Media stream obtained, active:', streamData.active);
|
|
7415
|
-
// If the component unmounted while getUserMedia was resolving, stop immediately
|
|
7416
|
-
if (!isMountedRef.current) {
|
|
7417
|
-
streamData.getTracks().forEach(track => track.stop());
|
|
7418
|
-
return;
|
|
7419
|
-
}
|
|
7420
|
-
streamRef.current = streamData;
|
|
7421
7261
|
setPermission(true);
|
|
7422
7262
|
setStream(streamData);
|
|
7423
7263
|
}
|
|
7424
7264
|
catch (err) {
|
|
7425
7265
|
console.error('Camera/mic permission denied:', err);
|
|
7426
|
-
|
|
7427
|
-
setPermission(false);
|
|
7266
|
+
setPermission(false);
|
|
7428
7267
|
}
|
|
7429
7268
|
finally {
|
|
7430
|
-
|
|
7431
|
-
setIsLoading(false);
|
|
7269
|
+
setIsLoading(false);
|
|
7432
7270
|
}
|
|
7433
7271
|
};
|
|
7434
7272
|
useEffect(() => {
|
|
7435
|
-
isMountedRef.current = true;
|
|
7436
7273
|
void requestPermissions();
|
|
7437
|
-
return () => {
|
|
7438
|
-
isMountedRef.current = false;
|
|
7439
|
-
if (streamRef.current) {
|
|
7440
|
-
streamRef.current.getTracks().forEach(track => track.stop());
|
|
7441
|
-
streamRef.current = null;
|
|
7442
|
-
}
|
|
7443
|
-
};
|
|
7444
7274
|
}, [rectWidth, rectHeight]);
|
|
7445
7275
|
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7446
7276
|
};// spinner animation
|
|
@@ -7472,7 +7302,7 @@ function generateRandomDigits$1(count) {
|
|
|
7472
7302
|
}
|
|
7473
7303
|
return digits.slice(0, count);
|
|
7474
7304
|
}
|
|
7475
|
-
const FaceRecorder = ({ rectWidth =
|
|
7305
|
+
const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onConfirmRecording, onRecorded, className, style, noShadow = false, }) => {
|
|
7476
7306
|
const [state, setState] = useState('preparation');
|
|
7477
7307
|
const [prepTimer, setPrepTimer] = useState(PREP_SECONDS$1);
|
|
7478
7308
|
const [recordTimer, setRecordTimer] = useState(RECORD_SECONDS$1);
|
|
@@ -7697,7 +7527,7 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
|
|
|
7697
7527
|
alignItems: 'center',
|
|
7698
7528
|
justifyContent: 'center',
|
|
7699
7529
|
width: rectWidth,
|
|
7700
|
-
height: rectHeight +
|
|
7530
|
+
height: rectHeight + 120,
|
|
7701
7531
|
margin: '0 auto',
|
|
7702
7532
|
...style,
|
|
7703
7533
|
};
|
|
@@ -7715,11 +7545,11 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
|
|
|
7715
7545
|
};
|
|
7716
7546
|
const ovalArea = {
|
|
7717
7547
|
position: 'absolute',
|
|
7718
|
-
top: '
|
|
7719
|
-
left: '
|
|
7720
|
-
|
|
7721
|
-
width: '
|
|
7722
|
-
height: '
|
|
7548
|
+
top: '15%',
|
|
7549
|
+
left: '50%',
|
|
7550
|
+
transform: 'translateX(-50%)',
|
|
7551
|
+
width: '75%',
|
|
7552
|
+
height: '70%',
|
|
7723
7553
|
zIndex: 2,
|
|
7724
7554
|
display: 'flex',
|
|
7725
7555
|
flexDirection: 'column',
|
|
@@ -7750,8 +7580,8 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
|
|
|
7750
7580
|
const numberRow = {
|
|
7751
7581
|
display: 'flex',
|
|
7752
7582
|
justifyContent: 'center',
|
|
7753
|
-
gap:
|
|
7754
|
-
|
|
7583
|
+
gap: 4,
|
|
7584
|
+
margin: '16px 0 24px 0',
|
|
7755
7585
|
width: '100%',
|
|
7756
7586
|
maxWidth: rectWidth - 40,
|
|
7757
7587
|
};
|
|
@@ -7871,7 +7701,7 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
|
|
|
7871
7701
|
if (!permission) {
|
|
7872
7702
|
return (jsx("div", { className: className, style: wrapperStyle, children: jsxs("div", { style: { textAlign: 'center', padding: '20px' }, children: [jsx("h3", { children: "Camera Permission Required" }), jsx("p", { children: "Please allow camera and microphone access to use this component." }), jsx("button", { type: "button", style: actionButton, onClick: requestPermissions, children: "Grant Permissions" })] }) }));
|
|
7873
7703
|
}
|
|
7874
|
-
return (jsxs("div", { className: className, style: wrapperStyle, children: [state !== 'result' && state !== 'processing' && !isConfirming && (jsxs(Fragment, { children: [
|
|
7704
|
+
return (jsxs("div", { className: className, style: wrapperStyle, children: [state !== 'result' && state !== 'processing' && !isConfirming && (jsxs(Fragment, { children: [jsxs("div", { className: "facerecorder-camera-area", style: cameraArea, children: [jsx("video", { ref: videoRef, width: rectWidth - 40, height: rectHeight - 40, className: "facerecorder-video", style: {
|
|
7875
7705
|
width: rectWidth - 40,
|
|
7876
7706
|
height: rectHeight - 40,
|
|
7877
7707
|
objectFit: 'cover',
|
|
@@ -7887,7 +7717,7 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
|
|
|
7887
7717
|
background: 'rgba(0,0,0,0.4)',
|
|
7888
7718
|
zIndex: 1,
|
|
7889
7719
|
borderRadius: noShadow ? 0 : 8,
|
|
7890
|
-
} }), jsxs("div", { className: "facerecorder-oval-area", style: ovalArea, children: [jsx("span", { className: "facerecorder-guidance-text", style: guidanceText, children: "Place your face in the oval" }), jsx("div", { className: "facerecorder-oval-dashed", style: ovalDashed })] }), state === 'countdown' && (jsx("div", { style: prepTimerStyle, children: prepTimer })), state === 'recording' && (jsx("div", { style: timerStyle, children: recordTimer })), (state === 'recording' || state === 'preparation') && (jsxs("div", { style: soundwaveStyle, children: [jsx("div", { style: { ...barBase, height: `${8 + micLevel * 30}px` } }), jsx("div", { style: { ...barBase, height: `${4 + micLevel * 40}px` } }), jsx("div", { style: { ...barBase, height: `${10 + micLevel * 20}px` } })] }))] }), state === 'preparation' && (jsx("button", { type: "button", style: actionButton, onClick: startRecording, children: "Start recording" })), state === 'recording' && (jsx("button", { type: "button", style: { ...actionButton, background: '#d32f2f' }, onClick: handleCancel, children: "Cancel" }))] })), state === 'processing' && (jsx(Fragment, { children: jsx("div", { className: "facerecorder-processing", style: preview, children: jsxs("div", { style: {
|
|
7720
|
+
} }), jsxs("div", { className: "facerecorder-oval-area", style: ovalArea, children: [jsx("span", { className: "facerecorder-guidance-text", style: guidanceText, children: "Place your face in the oval" }), jsx("div", { className: "facerecorder-oval-dashed", style: ovalDashed })] }), state === 'countdown' && (jsx("div", { style: prepTimerStyle, children: prepTimer })), state === 'recording' && (jsx("div", { style: timerStyle, children: recordTimer })), (state === 'recording' || state === 'preparation') && (jsxs("div", { style: soundwaveStyle, children: [jsx("div", { style: { ...barBase, height: `${8 + micLevel * 30}px` } }), jsx("div", { style: { ...barBase, height: `${4 + micLevel * 40}px` } }), jsx("div", { style: { ...barBase, height: `${10 + micLevel * 20}px` } })] }))] }), jsx("div", { style: numberRow, children: (state === 'recording' ? digits : Array(DIGITS_NUMBER$1).fill('*')).map((num, i) => (jsx("div", { style: numberBox, children: num }, i))) }), state === 'preparation' && (jsx("button", { type: "button", style: actionButton, onClick: startRecording, children: "Start recording" })), state === 'recording' && (jsx("button", { type: "button", style: { ...actionButton, background: '#d32f2f' }, onClick: handleCancel, children: "Cancel" }))] })), state === 'processing' && (jsx(Fragment, { children: jsx("div", { className: "facerecorder-processing", style: preview, children: jsxs("div", { style: {
|
|
7891
7721
|
display: 'flex',
|
|
7892
7722
|
flexDirection: 'column',
|
|
7893
7723
|
alignItems: 'center',
|
|
@@ -7912,13 +7742,11 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
|
|
|
7912
7742
|
const [permission, setPermission] = useState(false);
|
|
7913
7743
|
const [stream, setStream] = useState(null);
|
|
7914
7744
|
const [isLoading, setIsLoading] = useState(true);
|
|
7915
|
-
const streamRef = useRef(null);
|
|
7916
|
-
const isMountedRef = useRef(false);
|
|
7917
7745
|
const stopStreamTracks = () => {
|
|
7918
|
-
|
|
7919
|
-
|
|
7920
|
-
|
|
7921
|
-
|
|
7746
|
+
if (stream) {
|
|
7747
|
+
stream.getTracks().forEach(track => {
|
|
7748
|
+
track.stop();
|
|
7749
|
+
});
|
|
7922
7750
|
setStream(null);
|
|
7923
7751
|
}
|
|
7924
7752
|
};
|
|
@@ -7966,35 +7794,19 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
|
|
|
7966
7794
|
setIsLoading(true);
|
|
7967
7795
|
const constraints = getAudioConstraints();
|
|
7968
7796
|
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7969
|
-
// If the component unmounted while getUserMedia was resolving, stop immediately
|
|
7970
|
-
if (!isMountedRef.current) {
|
|
7971
|
-
streamData.getTracks().forEach(track => track.stop());
|
|
7972
|
-
return;
|
|
7973
|
-
}
|
|
7974
|
-
streamRef.current = streamData;
|
|
7975
7797
|
setPermission(true);
|
|
7976
7798
|
setStream(streamData);
|
|
7977
7799
|
}
|
|
7978
7800
|
catch (err) {
|
|
7979
7801
|
console.error('Microphone permission denied:', err);
|
|
7980
|
-
|
|
7981
|
-
setPermission(false);
|
|
7802
|
+
setPermission(false);
|
|
7982
7803
|
}
|
|
7983
7804
|
finally {
|
|
7984
|
-
|
|
7985
|
-
setIsLoading(false);
|
|
7805
|
+
setIsLoading(false);
|
|
7986
7806
|
}
|
|
7987
7807
|
};
|
|
7988
7808
|
useEffect(() => {
|
|
7989
|
-
isMountedRef.current = true;
|
|
7990
7809
|
void requestPermissions();
|
|
7991
|
-
return () => {
|
|
7992
|
-
isMountedRef.current = false;
|
|
7993
|
-
if (streamRef.current) {
|
|
7994
|
-
streamRef.current.getTracks().forEach(track => track.stop());
|
|
7995
|
-
streamRef.current = null;
|
|
7996
|
-
}
|
|
7997
|
-
};
|
|
7998
7810
|
}, []);
|
|
7999
7811
|
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
8000
7812
|
};// spinner animation
|
|
@@ -8010,9 +7822,14 @@ if (typeof document !== 'undefined') {
|
|
|
8010
7822
|
style.textContent = spinnerStyle;
|
|
8011
7823
|
document.head.appendChild(style);
|
|
8012
7824
|
}
|
|
8013
|
-
const RECORD_SECONDS =
|
|
7825
|
+
const RECORD_SECONDS = VOICE_ENROLL_LENGTH_MS / 1000;
|
|
8014
7826
|
const PREP_SECONDS = 3;
|
|
8015
|
-
|
|
7827
|
+
// All ten digits. Voice enrollment builds a text-prompted digit voiceprint and
|
|
7828
|
+
// the enrollment sample is expected to cover 0-9; verification later prompts a
|
|
7829
|
+
// random subset. This was 10 until 1.2.7 shortened the recording to 7s and cut
|
|
7830
|
+
// the prompt to match, which silently dropped three digits from every print
|
|
7831
|
+
// while the README kept documenting ten (BM-407).
|
|
7832
|
+
const DIGITS_NUMBER = 10;
|
|
8016
7833
|
function generateRandomDigits(count) {
|
|
8017
7834
|
const digits = Array.from({ length: 10 }, (_, i) => i);
|
|
8018
7835
|
for (let i = digits.length - 1; i > 0; i--) {
|
|
@@ -8061,7 +7878,7 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onConfirmRecording, onReco
|
|
|
8061
7878
|
setState('result');
|
|
8062
7879
|
setIsConfirming(true);
|
|
8063
7880
|
}
|
|
8064
|
-
});
|
|
7881
|
+
}, VOICE_ENROLL_LENGTH_MS);
|
|
8065
7882
|
// Audio visualization setup
|
|
8066
7883
|
useEffect(() => {
|
|
8067
7884
|
if (stream && state === 'recording') {
|
package/dist/index.js
CHANGED
|
@@ -1,60 +1,19 @@
|
|
|
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);
|
|
6
5
|
const videoRef = React.useRef(null);
|
|
7
6
|
const streamRef = React.useRef(null);
|
|
8
|
-
const [devices, setDevices] = React.useState([]);
|
|
9
|
-
const [selectedDeviceId, setSelectedDeviceId] = React.useState(null);
|
|
10
|
-
const [isFrontCamera, setIsFrontCamera] = React.useState(false);
|
|
11
|
-
const [capabilities, setCapabilities] = React.useState({});
|
|
12
|
-
const [torchOn, setTorchOn] = React.useState(false);
|
|
13
7
|
const QUALITY_MULTIPLIER = 3;
|
|
14
8
|
// Crop area (dashed area) as percentages
|
|
15
9
|
const cropTop = 0.075, cropLeft = 0.075, cropWidth = 0.85, cropHeight = 0.85;
|
|
16
|
-
const getDevices = async () => {
|
|
17
|
-
try {
|
|
18
|
-
const all = await navigator.mediaDevices.enumerateDevices();
|
|
19
|
-
return all.filter((d) => d.kind === "videoinput");
|
|
20
|
-
}
|
|
21
|
-
catch (_a) {
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
React.useEffect(() => {
|
|
26
|
-
const handleDeviceChange = async () => {
|
|
27
|
-
const vids = await getDevices();
|
|
28
|
-
setDevices(vids);
|
|
29
|
-
if (selectedDeviceId && !vids.find((d) => d.deviceId === selectedDeviceId)) {
|
|
30
|
-
// Active device disconnected, clear it to fallback to default
|
|
31
|
-
setSelectedDeviceId(null);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
navigator.mediaDevices.addEventListener("devicechange", handleDeviceChange);
|
|
35
|
-
return () => navigator.mediaDevices.removeEventListener("devicechange", handleDeviceChange);
|
|
36
|
-
}, [selectedDeviceId]);
|
|
37
10
|
React.useEffect(() => {
|
|
38
11
|
let isMounted = true;
|
|
39
12
|
if (!isConfirming) {
|
|
40
13
|
(async () => {
|
|
41
14
|
try {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
height: rectHeight,
|
|
45
|
-
};
|
|
46
|
-
if (selectedDeviceId) {
|
|
47
|
-
videoConstraints.deviceId = { exact: selectedDeviceId };
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
videoConstraints.facingMode = "environment";
|
|
51
|
-
}
|
|
52
|
-
const stream = await navigator.mediaDevices.getUserMedia({ video: videoConstraints });
|
|
53
|
-
if (!isMounted) {
|
|
54
|
-
stream.getTracks().forEach((track) => track.stop());
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (videoRef.current) {
|
|
15
|
+
const stream = await navigator.mediaDevices.getUserMedia({ video: { width: rectWidth, height: rectHeight } });
|
|
16
|
+
if (videoRef.current && isMounted) {
|
|
58
17
|
videoRef.current.srcObject = stream;
|
|
59
18
|
videoRef.current.onloadedmetadata = () => {
|
|
60
19
|
var _a;
|
|
@@ -62,40 +21,6 @@
|
|
|
62
21
|
};
|
|
63
22
|
}
|
|
64
23
|
streamRef.current = stream;
|
|
65
|
-
const track = stream.getVideoTracks()[0];
|
|
66
|
-
if (track) {
|
|
67
|
-
if (track.getCapabilities) {
|
|
68
|
-
setCapabilities(track.getCapabilities());
|
|
69
|
-
}
|
|
70
|
-
const settings = track.getSettings();
|
|
71
|
-
let isFront = false;
|
|
72
|
-
if (settings.facingMode) {
|
|
73
|
-
isFront = settings.facingMode === "user";
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
const allVids = await getDevices();
|
|
77
|
-
const currDev = allVids.find(d => d.deviceId === settings.deviceId);
|
|
78
|
-
if (currDev)
|
|
79
|
-
isFront = currDev.label.toLowerCase().includes("front");
|
|
80
|
-
}
|
|
81
|
-
if (isMounted)
|
|
82
|
-
setIsFrontCamera(isFront);
|
|
83
|
-
if (!selectedDeviceId) {
|
|
84
|
-
const currentId = track.getSettings().deviceId;
|
|
85
|
-
if (currentId && isMounted)
|
|
86
|
-
setSelectedDeviceId(currentId);
|
|
87
|
-
}
|
|
88
|
-
track.onended = async () => {
|
|
89
|
-
if (!isMounted)
|
|
90
|
-
return;
|
|
91
|
-
const vids = await getDevices();
|
|
92
|
-
setDevices(vids);
|
|
93
|
-
setSelectedDeviceId(null);
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
const vids = await getDevices();
|
|
97
|
-
if (isMounted)
|
|
98
|
-
setDevices(vids);
|
|
99
24
|
}
|
|
100
25
|
catch (err) {
|
|
101
26
|
console.error(err);
|
|
@@ -109,7 +34,7 @@
|
|
|
109
34
|
streamRef.current = null;
|
|
110
35
|
}
|
|
111
36
|
};
|
|
112
|
-
}, [isConfirming, rectWidth, rectHeight
|
|
37
|
+
}, [isConfirming, rectWidth, rectHeight]);
|
|
113
38
|
const handleCapture = () => {
|
|
114
39
|
const video = videoRef.current;
|
|
115
40
|
if (!video)
|
|
@@ -124,20 +49,18 @@
|
|
|
124
49
|
const targetAspect = rectWidth / rectHeight;
|
|
125
50
|
let sx = 0, sy = 0, sw = video.videoWidth, sh = video.videoHeight;
|
|
126
51
|
if (videoAspect > targetAspect) {
|
|
52
|
+
// Video is wider than target: crop sides
|
|
127
53
|
sw = video.videoHeight * targetAspect;
|
|
128
54
|
sx = (video.videoWidth - sw) / 2;
|
|
129
55
|
}
|
|
130
56
|
else {
|
|
57
|
+
// Video is taller than target: crop top/bottom
|
|
131
58
|
sh = video.videoWidth / targetAspect;
|
|
132
59
|
sy = (video.videoHeight - sh) / 2;
|
|
133
60
|
}
|
|
134
61
|
ctx.drawImage(video, sx, sy, sw, sh, 0, 0, canvas.width, canvas.height);
|
|
135
62
|
canvas.toBlob((blob) => {
|
|
136
63
|
if (blob) {
|
|
137
|
-
if (streamRef.current) {
|
|
138
|
-
streamRef.current.getTracks().forEach((track) => track.stop());
|
|
139
|
-
streamRef.current = null;
|
|
140
|
-
}
|
|
141
64
|
const file = new File([blob], "document.jpg", { type: "image/jpeg" });
|
|
142
65
|
setCapturedFile(file);
|
|
143
66
|
setCapturedUrl(URL.createObjectURL(blob));
|
|
@@ -147,7 +70,7 @@
|
|
|
147
70
|
onCapture(file);
|
|
148
71
|
}
|
|
149
72
|
catch (err) {
|
|
150
|
-
console.error(err);
|
|
73
|
+
console.error('onCapture callback threw:', err);
|
|
151
74
|
}
|
|
152
75
|
}
|
|
153
76
|
}
|
|
@@ -167,53 +90,6 @@
|
|
|
167
90
|
setCapturedFile(null);
|
|
168
91
|
setIsConfirming(false);
|
|
169
92
|
};
|
|
170
|
-
const cycleCamera = (e) => {
|
|
171
|
-
e.stopPropagation();
|
|
172
|
-
if (devices.length <= 1)
|
|
173
|
-
return;
|
|
174
|
-
const currentIndex = devices.findIndex((d) => d.deviceId === selectedDeviceId);
|
|
175
|
-
const nextIndex = (currentIndex + 1) % devices.length;
|
|
176
|
-
setSelectedDeviceId(devices[nextIndex].deviceId);
|
|
177
|
-
setTorchOn(false);
|
|
178
|
-
};
|
|
179
|
-
const toggleTorch = async (e) => {
|
|
180
|
-
e.stopPropagation();
|
|
181
|
-
if (!streamRef.current)
|
|
182
|
-
return;
|
|
183
|
-
const track = streamRef.current.getVideoTracks()[0];
|
|
184
|
-
if (track && capabilities.torch) {
|
|
185
|
-
try {
|
|
186
|
-
const nextTorch = !torchOn;
|
|
187
|
-
await track.applyConstraints({ advanced: [{ torch: nextTorch }] });
|
|
188
|
-
setTorchOn(nextTorch);
|
|
189
|
-
}
|
|
190
|
-
catch (err) {
|
|
191
|
-
console.error("Torch toggle failed:", err);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
const handleCameraAreaClick = async (e) => {
|
|
196
|
-
if (!streamRef.current)
|
|
197
|
-
return;
|
|
198
|
-
const track = streamRef.current.getVideoTracks()[0];
|
|
199
|
-
if (track && capabilities.focusMode) {
|
|
200
|
-
const focusType = capabilities.focusMode.includes("single-shot") ? "single-shot" : capabilities.focusMode.includes("manual") ? "manual" : null;
|
|
201
|
-
if (!focusType)
|
|
202
|
-
return;
|
|
203
|
-
const rect = e.currentTarget.getBoundingClientRect();
|
|
204
|
-
let x = (e.clientX - rect.left) / rect.width;
|
|
205
|
-
const y = (e.clientY - rect.top) / rect.height;
|
|
206
|
-
if (isFrontCamera) {
|
|
207
|
-
x = 1 - x;
|
|
208
|
-
}
|
|
209
|
-
try {
|
|
210
|
-
await track.applyConstraints({ advanced: [{ focusMode: focusType, pointsOfInterest: [{ x, y }] }] });
|
|
211
|
-
}
|
|
212
|
-
catch (err) {
|
|
213
|
-
console.error("Focus failed:", err);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
93
|
const wrapperStyle = {
|
|
218
94
|
background: '#fff',
|
|
219
95
|
borderRadius: noShadow ? 0 : 10,
|
|
@@ -236,7 +112,6 @@
|
|
|
236
112
|
display: 'flex',
|
|
237
113
|
alignItems: 'center',
|
|
238
114
|
justifyContent: 'center',
|
|
239
|
-
cursor: ((_a = capabilities.focusMode) === null || _a === void 0 ? void 0 : _a.includes("manual")) ? "crosshair" : "default"
|
|
240
115
|
};
|
|
241
116
|
const defaultDashedArea = {
|
|
242
117
|
position: 'absolute',
|
|
@@ -252,7 +127,6 @@
|
|
|
252
127
|
display: 'flex',
|
|
253
128
|
flexDirection: 'column',
|
|
254
129
|
alignItems: 'center',
|
|
255
|
-
pointerEvents: 'none'
|
|
256
130
|
};
|
|
257
131
|
const defaultGuidanceText = {
|
|
258
132
|
color: '#fff',
|
|
@@ -304,34 +178,13 @@
|
|
|
304
178
|
transition: 'background 0.2s',
|
|
305
179
|
margin: '0 8px',
|
|
306
180
|
};
|
|
307
|
-
|
|
308
|
-
position: 'absolute',
|
|
309
|
-
top: 8,
|
|
310
|
-
right: 8,
|
|
311
|
-
zIndex: 3,
|
|
312
|
-
display: 'flex',
|
|
313
|
-
flexDirection: 'column',
|
|
314
|
-
gap: 12,
|
|
315
|
-
};
|
|
316
|
-
const overlayBtnStyle = {
|
|
317
|
-
background: 'rgba(0,0,0,0.5)',
|
|
318
|
-
border: 'none',
|
|
319
|
-
borderRadius: '50%',
|
|
320
|
-
width: 36,
|
|
321
|
-
height: 36,
|
|
322
|
-
display: 'flex',
|
|
323
|
-
alignItems: 'center',
|
|
324
|
-
justifyContent: 'center',
|
|
325
|
-
cursor: 'pointer',
|
|
326
|
-
color: '#fff',
|
|
327
|
-
};
|
|
328
|
-
return (jsxRuntime.jsx("div", { className: className, style: wrapperStyle, children: !isConfirming ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: "docscan-camera-area", style: defaultCameraArea, onClick: handleCameraAreaClick, children: [jsxRuntime.jsxs("div", { style: controlsOverlayStyle, children: [devices.length > 1 && (jsxRuntime.jsx("button", { type: "button", onClick: cycleCamera, style: overlayBtnStyle, title: "Switch Camera", children: jsxRuntime.jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [jsxRuntime.jsx("path", { d: "M21 12A9 9 0 0 0 6 5.3L3 8" }), jsxRuntime.jsx("path", { d: "M21 3v5h-5" }), jsxRuntime.jsx("path", { d: "M3 12a9 9 0 0 0 15 6.7l3-2.7" }), jsxRuntime.jsx("path", { d: "M3 21v-5h5" })] }) })), capabilities.torch && (jsxRuntime.jsx("button", { type: "button", onClick: toggleTorch, style: { ...overlayBtnStyle, color: torchOn ? '#ffd700' : '#fff' }, title: "Toggle Flash", children: jsxRuntime.jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: jsxRuntime.jsx("polygon", { points: "13 2 3 14 12 14 11 22 21 10 12 10 13 2" }) }) }))] }), jsxRuntime.jsx("video", { ref: videoRef, width: rectWidth - 40, height: rectHeight - 40, className: "docscan-video", style: {
|
|
181
|
+
return (jsxRuntime.jsx("div", { className: className, style: wrapperStyle, children: !isConfirming ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: "docscan-camera-area", style: defaultCameraArea, children: [jsxRuntime.jsx("video", { ref: videoRef, width: rectWidth - 40, height: rectHeight - 40, className: "docscan-video", style: {
|
|
329
182
|
width: rectWidth - 40,
|
|
330
183
|
height: rectHeight - 40,
|
|
331
184
|
objectFit: 'cover',
|
|
332
185
|
borderRadius: noShadow ? 0 : 8,
|
|
333
186
|
zIndex: 0,
|
|
334
|
-
transform:
|
|
187
|
+
transform: 'scaleX(-1)'
|
|
335
188
|
}, playsInline: true, muted: true, autoPlay: true }), jsxRuntime.jsx("div", { className: "docscan-dark-overlay", style: {
|
|
336
189
|
position: 'absolute',
|
|
337
190
|
top: 0,
|
|
@@ -341,7 +194,6 @@
|
|
|
341
194
|
background: 'rgba(0,0,0,0.4)',
|
|
342
195
|
zIndex: 1,
|
|
343
196
|
borderRadius: noShadow ? 0 : 8,
|
|
344
|
-
pointerEvents: 'none'
|
|
345
197
|
} }), 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" })] }) })] })] })) }));
|
|
346
198
|
};const FaceCapture = ({ rectWidth = 360, rectHeight = 576, onConfirmCapture, onCapture, className, style, noShadow = false, }) => {
|
|
347
199
|
const [isConfirming, setIsConfirming] = React.useState(false);
|
|
@@ -356,11 +208,7 @@
|
|
|
356
208
|
(async () => {
|
|
357
209
|
try {
|
|
358
210
|
const stream = await navigator.mediaDevices.getUserMedia({ video: { width: rectWidth, height: rectHeight } });
|
|
359
|
-
if (
|
|
360
|
-
stream.getTracks().forEach((track) => track.stop());
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
if (videoRef.current) {
|
|
211
|
+
if (videoRef.current && isMounted) {
|
|
364
212
|
videoRef.current.srcObject = stream;
|
|
365
213
|
videoRef.current.onloadedmetadata = () => {
|
|
366
214
|
var _a;
|
|
@@ -394,11 +242,6 @@
|
|
|
394
242
|
ctx.drawImage(video, 0, 0, rectWidth, rectHeight, 0, 0, rectWidth * QUALITY_MULTIPLIER, rectHeight * QUALITY_MULTIPLIER);
|
|
395
243
|
canvas.toBlob((blob) => {
|
|
396
244
|
if (blob) {
|
|
397
|
-
// Stop the stream immediately — don't wait for useEffect cleanup
|
|
398
|
-
if (streamRef.current) {
|
|
399
|
-
streamRef.current.getTracks().forEach((track) => track.stop());
|
|
400
|
-
streamRef.current = null;
|
|
401
|
-
}
|
|
402
245
|
const file = new File([blob], "face.jpg", { type: "image/jpeg" });
|
|
403
246
|
setCapturedFile(file);
|
|
404
247
|
setCapturedUrl(URL.createObjectURL(blob));
|
|
@@ -7236,7 +7079,12 @@ function numberToWord(num) {
|
|
|
7236
7079
|
function numbersToPhrase(numbers) {
|
|
7237
7080
|
return numbers.map(numberToWord).join(' ');
|
|
7238
7081
|
}const VIDEO_LENGTH_MS = 7000;
|
|
7239
|
-
|
|
7082
|
+
/**
|
|
7083
|
+
* Voice *enrollment* reads all ten digits aloud, which does not fit in the
|
|
7084
|
+
* 7s video length unhurried. Verification keeps the shorter window (BM-407).
|
|
7085
|
+
*/
|
|
7086
|
+
const VOICE_ENROLL_LENGTH_MS = 10000;
|
|
7087
|
+
const useRecorder = (stream, type, onStopRecording, lengthMs = VIDEO_LENGTH_MS) => {
|
|
7240
7088
|
const [isRecording, setIsRecording] = React.useState(false);
|
|
7241
7089
|
const recorderRef = React.useRef(null);
|
|
7242
7090
|
const timeoutRef = React.useRef(null);
|
|
@@ -7294,7 +7142,7 @@ const useRecorder = (stream, type, onStopRecording) => {
|
|
|
7294
7142
|
// Set timeout to auto-stop recording
|
|
7295
7143
|
timeoutRef.current = window.setTimeout(() => {
|
|
7296
7144
|
stopRecording();
|
|
7297
|
-
},
|
|
7145
|
+
}, lengthMs);
|
|
7298
7146
|
}
|
|
7299
7147
|
catch (error) {
|
|
7300
7148
|
console.error(error);
|
|
@@ -7310,7 +7158,7 @@ const useRecorder = (stream, type, onStopRecording) => {
|
|
|
7310
7158
|
}
|
|
7311
7159
|
recorderRef.current.stopRecording(() => {
|
|
7312
7160
|
const blob = recorderRef.current.getBlob();
|
|
7313
|
-
fixWebmDuration(blob,
|
|
7161
|
+
fixWebmDuration(blob, lengthMs, function (fixedBlob) {
|
|
7314
7162
|
setIsRecording(false);
|
|
7315
7163
|
recorderRef.current.destroy();
|
|
7316
7164
|
recorderRef.current = null;
|
|
@@ -7336,13 +7184,11 @@ const useRecorder = (stream, type, onStopRecording) => {
|
|
|
7336
7184
|
const [permission, setPermission] = React.useState(false);
|
|
7337
7185
|
const [stream, setStream] = React.useState(null);
|
|
7338
7186
|
const [isLoading, setIsLoading] = React.useState(true);
|
|
7339
|
-
const streamRef = React.useRef(null);
|
|
7340
|
-
const isMountedRef = React.useRef(false);
|
|
7341
7187
|
const stopStreamTracks = () => {
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7188
|
+
if (stream) {
|
|
7189
|
+
stream.getTracks().forEach(track => {
|
|
7190
|
+
track.stop();
|
|
7191
|
+
});
|
|
7346
7192
|
setStream(null);
|
|
7347
7193
|
}
|
|
7348
7194
|
};
|
|
@@ -7412,35 +7258,19 @@ const useRecorder = (stream, type, onStopRecording) => {
|
|
|
7412
7258
|
const constraints = getAdaptiveConstraints();
|
|
7413
7259
|
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7414
7260
|
console.log('Media stream obtained, active:', streamData.active);
|
|
7415
|
-
// If the component unmounted while getUserMedia was resolving, stop immediately
|
|
7416
|
-
if (!isMountedRef.current) {
|
|
7417
|
-
streamData.getTracks().forEach(track => track.stop());
|
|
7418
|
-
return;
|
|
7419
|
-
}
|
|
7420
|
-
streamRef.current = streamData;
|
|
7421
7261
|
setPermission(true);
|
|
7422
7262
|
setStream(streamData);
|
|
7423
7263
|
}
|
|
7424
7264
|
catch (err) {
|
|
7425
7265
|
console.error('Camera/mic permission denied:', err);
|
|
7426
|
-
|
|
7427
|
-
setPermission(false);
|
|
7266
|
+
setPermission(false);
|
|
7428
7267
|
}
|
|
7429
7268
|
finally {
|
|
7430
|
-
|
|
7431
|
-
setIsLoading(false);
|
|
7269
|
+
setIsLoading(false);
|
|
7432
7270
|
}
|
|
7433
7271
|
};
|
|
7434
7272
|
React.useEffect(() => {
|
|
7435
|
-
isMountedRef.current = true;
|
|
7436
7273
|
void requestPermissions();
|
|
7437
|
-
return () => {
|
|
7438
|
-
isMountedRef.current = false;
|
|
7439
|
-
if (streamRef.current) {
|
|
7440
|
-
streamRef.current.getTracks().forEach(track => track.stop());
|
|
7441
|
-
streamRef.current = null;
|
|
7442
|
-
}
|
|
7443
|
-
};
|
|
7444
7274
|
}, [rectWidth, rectHeight]);
|
|
7445
7275
|
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
7446
7276
|
};// spinner animation
|
|
@@ -7472,7 +7302,7 @@ function generateRandomDigits$1(count) {
|
|
|
7472
7302
|
}
|
|
7473
7303
|
return digits.slice(0, count);
|
|
7474
7304
|
}
|
|
7475
|
-
const FaceRecorder = ({ rectWidth =
|
|
7305
|
+
const FaceRecorder = ({ rectWidth = 360, rectHeight = 576, onConfirmRecording, onRecorded, className, style, noShadow = false, }) => {
|
|
7476
7306
|
const [state, setState] = React.useState('preparation');
|
|
7477
7307
|
const [prepTimer, setPrepTimer] = React.useState(PREP_SECONDS$1);
|
|
7478
7308
|
const [recordTimer, setRecordTimer] = React.useState(RECORD_SECONDS$1);
|
|
@@ -7697,7 +7527,7 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
|
|
|
7697
7527
|
alignItems: 'center',
|
|
7698
7528
|
justifyContent: 'center',
|
|
7699
7529
|
width: rectWidth,
|
|
7700
|
-
height: rectHeight +
|
|
7530
|
+
height: rectHeight + 120,
|
|
7701
7531
|
margin: '0 auto',
|
|
7702
7532
|
...style,
|
|
7703
7533
|
};
|
|
@@ -7715,11 +7545,11 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
|
|
|
7715
7545
|
};
|
|
7716
7546
|
const ovalArea = {
|
|
7717
7547
|
position: 'absolute',
|
|
7718
|
-
top: '
|
|
7719
|
-
left: '
|
|
7720
|
-
|
|
7721
|
-
width: '
|
|
7722
|
-
height: '
|
|
7548
|
+
top: '15%',
|
|
7549
|
+
left: '50%',
|
|
7550
|
+
transform: 'translateX(-50%)',
|
|
7551
|
+
width: '75%',
|
|
7552
|
+
height: '70%',
|
|
7723
7553
|
zIndex: 2,
|
|
7724
7554
|
display: 'flex',
|
|
7725
7555
|
flexDirection: 'column',
|
|
@@ -7750,8 +7580,8 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
|
|
|
7750
7580
|
const numberRow = {
|
|
7751
7581
|
display: 'flex',
|
|
7752
7582
|
justifyContent: 'center',
|
|
7753
|
-
gap:
|
|
7754
|
-
|
|
7583
|
+
gap: 4,
|
|
7584
|
+
margin: '16px 0 24px 0',
|
|
7755
7585
|
width: '100%',
|
|
7756
7586
|
maxWidth: rectWidth - 40,
|
|
7757
7587
|
};
|
|
@@ -7871,7 +7701,7 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
|
|
|
7871
7701
|
if (!permission) {
|
|
7872
7702
|
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" })] }) }));
|
|
7873
7703
|
}
|
|
7874
|
-
return (jsxRuntime.jsxs("div", { className: className, style: wrapperStyle, children: [state !== 'result' && state !== 'processing' && !isConfirming && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.
|
|
7704
|
+
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: {
|
|
7875
7705
|
width: rectWidth - 40,
|
|
7876
7706
|
height: rectHeight - 40,
|
|
7877
7707
|
objectFit: 'cover',
|
|
@@ -7887,7 +7717,7 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
|
|
|
7887
7717
|
background: 'rgba(0,0,0,0.4)',
|
|
7888
7718
|
zIndex: 1,
|
|
7889
7719
|
borderRadius: noShadow ? 0 : 8,
|
|
7890
|
-
} }), 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` } })] }))] }), 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: {
|
|
7720
|
+
} }), 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_NUMBER$1).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: {
|
|
7891
7721
|
display: 'flex',
|
|
7892
7722
|
flexDirection: 'column',
|
|
7893
7723
|
alignItems: 'center',
|
|
@@ -7912,13 +7742,11 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
|
|
|
7912
7742
|
const [permission, setPermission] = React.useState(false);
|
|
7913
7743
|
const [stream, setStream] = React.useState(null);
|
|
7914
7744
|
const [isLoading, setIsLoading] = React.useState(true);
|
|
7915
|
-
const streamRef = React.useRef(null);
|
|
7916
|
-
const isMountedRef = React.useRef(false);
|
|
7917
7745
|
const stopStreamTracks = () => {
|
|
7918
|
-
|
|
7919
|
-
|
|
7920
|
-
|
|
7921
|
-
|
|
7746
|
+
if (stream) {
|
|
7747
|
+
stream.getTracks().forEach(track => {
|
|
7748
|
+
track.stop();
|
|
7749
|
+
});
|
|
7922
7750
|
setStream(null);
|
|
7923
7751
|
}
|
|
7924
7752
|
};
|
|
@@ -7966,35 +7794,19 @@ const FaceRecorder = ({ rectWidth = 320, rectHeight = 512, onConfirmRecording, o
|
|
|
7966
7794
|
setIsLoading(true);
|
|
7967
7795
|
const constraints = getAudioConstraints();
|
|
7968
7796
|
const streamData = await navigator.mediaDevices.getUserMedia(constraints);
|
|
7969
|
-
// If the component unmounted while getUserMedia was resolving, stop immediately
|
|
7970
|
-
if (!isMountedRef.current) {
|
|
7971
|
-
streamData.getTracks().forEach(track => track.stop());
|
|
7972
|
-
return;
|
|
7973
|
-
}
|
|
7974
|
-
streamRef.current = streamData;
|
|
7975
7797
|
setPermission(true);
|
|
7976
7798
|
setStream(streamData);
|
|
7977
7799
|
}
|
|
7978
7800
|
catch (err) {
|
|
7979
7801
|
console.error('Microphone permission denied:', err);
|
|
7980
|
-
|
|
7981
|
-
setPermission(false);
|
|
7802
|
+
setPermission(false);
|
|
7982
7803
|
}
|
|
7983
7804
|
finally {
|
|
7984
|
-
|
|
7985
|
-
setIsLoading(false);
|
|
7805
|
+
setIsLoading(false);
|
|
7986
7806
|
}
|
|
7987
7807
|
};
|
|
7988
7808
|
React.useEffect(() => {
|
|
7989
|
-
isMountedRef.current = true;
|
|
7990
7809
|
void requestPermissions();
|
|
7991
|
-
return () => {
|
|
7992
|
-
isMountedRef.current = false;
|
|
7993
|
-
if (streamRef.current) {
|
|
7994
|
-
streamRef.current.getTracks().forEach(track => track.stop());
|
|
7995
|
-
streamRef.current = null;
|
|
7996
|
-
}
|
|
7997
|
-
};
|
|
7998
7810
|
}, []);
|
|
7999
7811
|
return { permission, stream, stopStreamTracks, requestPermissions, isLoading };
|
|
8000
7812
|
};// spinner animation
|
|
@@ -8010,9 +7822,14 @@ if (typeof document !== 'undefined') {
|
|
|
8010
7822
|
style.textContent = spinnerStyle;
|
|
8011
7823
|
document.head.appendChild(style);
|
|
8012
7824
|
}
|
|
8013
|
-
const RECORD_SECONDS =
|
|
7825
|
+
const RECORD_SECONDS = VOICE_ENROLL_LENGTH_MS / 1000;
|
|
8014
7826
|
const PREP_SECONDS = 3;
|
|
8015
|
-
|
|
7827
|
+
// All ten digits. Voice enrollment builds a text-prompted digit voiceprint and
|
|
7828
|
+
// the enrollment sample is expected to cover 0-9; verification later prompts a
|
|
7829
|
+
// random subset. This was 10 until 1.2.7 shortened the recording to 7s and cut
|
|
7830
|
+
// the prompt to match, which silently dropped three digits from every print
|
|
7831
|
+
// while the README kept documenting ten (BM-407).
|
|
7832
|
+
const DIGITS_NUMBER = 10;
|
|
8016
7833
|
function generateRandomDigits(count) {
|
|
8017
7834
|
const digits = Array.from({ length: 10 }, (_, i) => i);
|
|
8018
7835
|
for (let i = digits.length - 1; i > 0; i--) {
|
|
@@ -8061,7 +7878,7 @@ const VoiceRecorder = ({ rectWidth = 360, rectHeight, onConfirmRecording, onReco
|
|
|
8061
7878
|
setState('result');
|
|
8062
7879
|
setIsConfirming(true);
|
|
8063
7880
|
}
|
|
8064
|
-
});
|
|
7881
|
+
}, VOICE_ENROLL_LENGTH_MS);
|
|
8065
7882
|
// Audio visualization setup
|
|
8066
7883
|
React.useEffect(() => {
|
|
8067
7884
|
if (stream && state === 'recording') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "biometry-react-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
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",
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"build": "rollup -c",
|
|
14
14
|
"build:types": "rollup -c rollup.config.dts.js",
|
|
15
15
|
"build:clean": "rm -rf dist && npm run build && npm run build:types",
|
|
16
|
-
"watch": "rollup -c --watch",
|
|
17
16
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
18
17
|
"prepublishOnly": "npm run build:clean"
|
|
19
18
|
},
|
|
@@ -31,15 +30,23 @@
|
|
|
31
30
|
],
|
|
32
31
|
"author": "Biometry Team",
|
|
33
32
|
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/your-username/biometry-react-components.git"
|
|
36
|
+
},
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/your-username/biometry-react-components/issues"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/your-username/biometry-react-components#readme",
|
|
34
41
|
"devDependencies": {
|
|
35
42
|
"@rollup/plugin-commonjs": "^28.0.6",
|
|
36
43
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
37
44
|
"@rollup/plugin-typescript": "^12.1.4",
|
|
38
|
-
"@types/react": "^
|
|
39
|
-
"@types/react-dom": "^
|
|
45
|
+
"@types/react": "^19.1.8",
|
|
46
|
+
"@types/react-dom": "^19.1.6",
|
|
40
47
|
"@types/recordrtc": "^5.6.14",
|
|
41
|
-
"react": "^
|
|
42
|
-
"react-dom": "^
|
|
48
|
+
"react": "^19.1.0",
|
|
49
|
+
"react-dom": "^19.1.0",
|
|
43
50
|
"rollup": "^4.45.1",
|
|
44
51
|
"rollup-plugin-dts": "^6.2.1",
|
|
45
52
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
@@ -55,4 +62,4 @@
|
|
|
55
62
|
"recordrtc": "^5.6.2",
|
|
56
63
|
"tslib": "^2.8.1"
|
|
57
64
|
}
|
|
58
|
-
}
|
|
65
|
+
}
|