@velion-la/onboarding-sdk-react-native 1.2.0-beta.1 → 1.2.0-beta.11
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 +47 -17
- package/lib/commonjs/camera/DocumentCapture.js +57 -35
- package/lib/commonjs/camera/DocumentCapture.js.map +1 -1
- package/lib/commonjs/camera/LivenessCamera.js +240 -87
- package/lib/commonjs/camera/LivenessCamera.js.map +1 -1
- package/lib/commonjs/camera/MapAddressPicker.js +1 -1
- package/lib/commonjs/camera/MapAddressPicker.js.map +1 -1
- package/lib/commonjs/i18n/strings/en.js +1 -0
- package/lib/commonjs/i18n/strings/en.js.map +1 -1
- package/lib/commonjs/i18n/strings/es.js +1 -0
- package/lib/commonjs/i18n/strings/es.js.map +1 -1
- package/lib/commonjs/steps/DocumentsOcrStep.js +140 -20
- package/lib/commonjs/steps/DocumentsOcrStep.js.map +1 -1
- package/lib/commonjs/steps/LivenessMatchStep.js +361 -63
- package/lib/commonjs/steps/LivenessMatchStep.js.map +1 -1
- package/lib/commonjs/transport/irisWebSocket.js +38 -3
- package/lib/commonjs/transport/irisWebSocket.js.map +1 -1
- package/lib/commonjs/ui/icons/StepIcon.js +8 -3
- package/lib/commonjs/ui/icons/StepIcon.js.map +1 -1
- package/lib/commonjs/ui/overlays/LoadingOverlay.js +1 -1
- package/lib/commonjs/ui/overlays/LoadingOverlay.js.map +1 -1
- package/lib/commonjs/ui/overlays/RetryDialog.js +1 -1
- package/lib/commonjs/ui/overlays/RetryDialog.js.map +1 -1
- package/lib/commonjs/utils/jpegFromUri.js +54 -14
- package/lib/commonjs/utils/jpegFromUri.js.map +1 -1
- package/lib/module/camera/DocumentCapture.js +58 -36
- package/lib/module/camera/DocumentCapture.js.map +1 -1
- package/lib/module/camera/LivenessCamera.js +242 -89
- package/lib/module/camera/LivenessCamera.js.map +1 -1
- package/lib/module/camera/MapAddressPicker.js +1 -1
- package/lib/module/camera/MapAddressPicker.js.map +1 -1
- package/lib/module/i18n/strings/en.js +1 -0
- package/lib/module/i18n/strings/en.js.map +1 -1
- package/lib/module/i18n/strings/es.js +1 -0
- package/lib/module/i18n/strings/es.js.map +1 -1
- package/lib/module/steps/DocumentsOcrStep.js +140 -20
- package/lib/module/steps/DocumentsOcrStep.js.map +1 -1
- package/lib/module/steps/LivenessMatchStep.js +364 -66
- package/lib/module/steps/LivenessMatchStep.js.map +1 -1
- package/lib/module/transport/irisWebSocket.js +38 -3
- package/lib/module/transport/irisWebSocket.js.map +1 -1
- package/lib/module/ui/icons/StepIcon.js +8 -3
- package/lib/module/ui/icons/StepIcon.js.map +1 -1
- package/lib/module/ui/overlays/LoadingOverlay.js +1 -1
- package/lib/module/ui/overlays/LoadingOverlay.js.map +1 -1
- package/lib/module/ui/overlays/RetryDialog.js +1 -1
- package/lib/module/ui/overlays/RetryDialog.js.map +1 -1
- package/lib/module/utils/jpegFromUri.js +52 -14
- package/lib/module/utils/jpegFromUri.js.map +1 -1
- package/lib/typescript/camera/DocumentCapture.d.ts +15 -3
- package/lib/typescript/camera/DocumentCapture.d.ts.map +1 -1
- package/lib/typescript/camera/LivenessCamera.d.ts +101 -10
- package/lib/typescript/camera/LivenessCamera.d.ts.map +1 -1
- package/lib/typescript/i18n/strings/en.d.ts.map +1 -1
- package/lib/typescript/i18n/strings/es.d.ts +1 -0
- package/lib/typescript/i18n/strings/es.d.ts.map +1 -1
- package/lib/typescript/steps/DocumentsOcrStep.d.ts.map +1 -1
- package/lib/typescript/steps/LivenessMatchStep.d.ts.map +1 -1
- package/lib/typescript/transport/irisWebSocket.d.ts.map +1 -1
- package/lib/typescript/ui/icons/StepIcon.d.ts +7 -2
- package/lib/typescript/ui/icons/StepIcon.d.ts.map +1 -1
- package/lib/typescript/utils/jpegFromUri.d.ts +31 -10
- package/lib/typescript/utils/jpegFromUri.d.ts.map +1 -1
- package/package.json +20 -14
- package/src/camera/DocumentCapture.tsx +59 -41
- package/src/camera/LivenessCamera.tsx +283 -89
- package/src/camera/MapAddressPicker.tsx +1 -1
- package/src/i18n/strings/en.ts +2 -0
- package/src/i18n/strings/es.ts +2 -0
- package/src/steps/DocumentsOcrStep.tsx +160 -18
- package/src/steps/LivenessMatchStep.tsx +416 -89
- package/src/transport/irisWebSocket.ts +32 -2
- package/src/ui/icons/StepIcon.tsx +9 -3
- package/src/ui/overlays/LoadingOverlay.tsx +1 -1
- package/src/ui/overlays/RetryDialog.tsx +1 -1
- package/src/utils/jpegFromUri.ts +54 -16
|
@@ -2,12 +2,23 @@
|
|
|
2
2
|
* @fileoverview Liveness camera surface — front-facing vision-camera with an
|
|
3
3
|
* oval mask, status pill, and capture loop driven by the parent step.
|
|
4
4
|
*
|
|
5
|
-
* Capture strategy:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* `
|
|
10
|
-
*
|
|
5
|
+
* Capture strategy: the web SDK grabs JPEG frames from the live video
|
|
6
|
+
* element. We do the Android equivalent: `takeSnapshot()` of the preview
|
|
7
|
+
* (the same pixels the user framed in the oval). Still-photo capture on
|
|
8
|
+
* the same session as the evidence recorder produced blurry JPEGs that
|
|
9
|
+
* Iris rejected as `LOW_SHARPNESS` and MiniFAS scored as a screen replay.
|
|
10
|
+
*
|
|
11
|
+
* `takeSnapshot()` is Android-only. iOS falls back to a photo output with
|
|
12
|
+
* `qualityPrioritization: 'quality'` (not `'speed'` — that is ZSL and
|
|
13
|
+
* starves when video is running).
|
|
14
|
+
*
|
|
15
|
+
* Preview snapshots are selfie-mirrored. We un-mirror before encoding so
|
|
16
|
+
* Iris sees real-world yaw (OSDKR-23). The on-screen preview stays mirrored.
|
|
17
|
+
*
|
|
18
|
+
* NOTE: the preview is deliberately NOT in `<Camera outputs={...}>`.
|
|
19
|
+
* `<Camera>` creates its own and prepends it (`outputs: [previewOutput,
|
|
20
|
+
* ...outputs]`); passing one explicitly adds a duplicate preview connection
|
|
21
|
+
* that the session refuses (OSDKR-20).
|
|
11
22
|
*
|
|
12
23
|
* The parent owns the loop and the WebSocket — this component just exposes a
|
|
13
24
|
* `captureFrame` ref so the step can drive the timing while the camera stays
|
|
@@ -26,6 +37,7 @@ import {
|
|
|
26
37
|
ActivityIndicator,
|
|
27
38
|
Animated,
|
|
28
39
|
Easing,
|
|
40
|
+
Platform,
|
|
29
41
|
StyleSheet,
|
|
30
42
|
Text,
|
|
31
43
|
useWindowDimensions,
|
|
@@ -34,18 +46,138 @@ import {
|
|
|
34
46
|
import Svg, { Defs, Ellipse, Mask, Rect } from 'react-native-svg';
|
|
35
47
|
import {
|
|
36
48
|
Camera,
|
|
49
|
+
CommonResolutions,
|
|
37
50
|
useCameraDevice,
|
|
38
|
-
useCameraFormat,
|
|
39
51
|
useCameraPermission,
|
|
40
|
-
|
|
41
|
-
|
|
52
|
+
usePhotoOutput,
|
|
53
|
+
useVideoOutput,
|
|
54
|
+
type CameraRef,
|
|
55
|
+
type Photo,
|
|
56
|
+
type Recorder,
|
|
42
57
|
} from 'react-native-vision-camera';
|
|
43
58
|
import { Button } from '../ui/primitives/Button';
|
|
44
59
|
import { useTheme, withAlpha } from '../ui/theme';
|
|
60
|
+
import { log } from '../utils/log';
|
|
45
61
|
import { useSafeAreaInsets } from '../utils/useSafeAreaInsets';
|
|
46
62
|
|
|
63
|
+
/**
|
|
64
|
+
* DIAGNOSTIC (OSDKR-24): which stream combination the liveness session binds.
|
|
65
|
+
*
|
|
66
|
+
* On a Motorola Edge 30 Neo and a Moto G51 every frame stays under Iris's
|
|
67
|
+
* sharpness floor, while a Moto G75 and a Galaxy A04 pass with the same code.
|
|
68
|
+
* v5 no longer lets us pick a photo size from the device's list: CameraX
|
|
69
|
+
* negotiates preview + photo + video (+ the fps cap) as one `SessionConfig`
|
|
70
|
+
* and may silently shrink the JPEG to make the combination fit. These
|
|
71
|
+
* variants isolate which part of the combination costs us the resolution:
|
|
72
|
+
*
|
|
73
|
+
* - `'full'` — preview + photo + video, 30 fps cap. Production behaviour.
|
|
74
|
+
* - `'no-video'` — preview + photo, 30 fps cap. The evidence video is skipped
|
|
75
|
+
* (best-effort path: `liveness-verify` goes without a body).
|
|
76
|
+
* - `'no-fps'` — preview + photo + video, no fps constraint.
|
|
77
|
+
* - `'v4-equivalent'` — the photo capture vision-camera 4.7.3 did before the
|
|
78
|
+
* migration: `'balanced'` (MINIMIZE_LATENCY, what v4 called
|
|
79
|
+
* `'speed'`) at UHD_4_3 (the sensor's largest 4:3 size), with
|
|
80
|
+
* video and no fps constraint — v4 never applied fps to the
|
|
81
|
+
* photo stream, while v5 applies it to the whole session.
|
|
82
|
+
* - `'v4-equivalent-30fps'` — the same photo capture plus the 30 fps cap v4
|
|
83
|
+
* put on preview and video. v5 cannot cap only those two: the
|
|
84
|
+
* constraint covers the whole session, photo included, so
|
|
85
|
+
* check the diagnostic log for the capture size it lands on.
|
|
86
|
+
*
|
|
87
|
+
* Android only: iOS always binds `'full'`, the configuration it passes Iris
|
|
88
|
+
* with (see ACTIVE_LIVENESS_CAMERA_VARIANT).
|
|
89
|
+
*
|
|
90
|
+
* Defaults to `'v4-equivalent'`: on the Edge 30 Neo it doubled the measured
|
|
91
|
+
* sharpness against `'full'` at the same face size. `'v4-equivalent-30fps'`
|
|
92
|
+
* was ruled out on the same device: to hold 30 fps CameraX moved the photo to
|
|
93
|
+
* a 16:9 3264x1836 stream, sharpness fell back to `'full'` levels, and the
|
|
94
|
+
* narrower field of view enlarged the face enough to trip `TOO_CLOSE`.
|
|
95
|
+
* Flip it by hand for a test build.
|
|
96
|
+
*/
|
|
97
|
+
export type LivenessCameraVariant =
|
|
98
|
+
| 'full'
|
|
99
|
+
| 'no-video'
|
|
100
|
+
| 'no-fps'
|
|
101
|
+
| 'v4-equivalent'
|
|
102
|
+
| 'v4-equivalent-30fps';
|
|
103
|
+
|
|
104
|
+
export const LIVENESS_CAMERA_VARIANT =
|
|
105
|
+
'v4-equivalent' as LivenessCameraVariant;
|
|
106
|
+
|
|
107
|
+
/** The variant this platform actually binds. */
|
|
108
|
+
export const ACTIVE_LIVENESS_CAMERA_VARIANT: LivenessCameraVariant =
|
|
109
|
+
Platform.OS === 'android' ? LIVENESS_CAMERA_VARIANT : 'full';
|
|
110
|
+
|
|
111
|
+
const IS_V4_EQUIVALENT =
|
|
112
|
+
ACTIVE_LIVENESS_CAMERA_VARIANT === 'v4-equivalent' ||
|
|
113
|
+
ACTIVE_LIVENESS_CAMERA_VARIANT === 'v4-equivalent-30fps';
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Android keeps each liveness frame in memory instead of round-tripping it
|
|
117
|
+
* through files (OSDKR-24). With the 8 MP v4-equivalent capture on an Edge 30
|
|
118
|
+
* Neo, the file path cost ~380 ms per frame on top of the camera's ~330 ms —
|
|
119
|
+
* write the JPEG, load it back through the image loader, write the resized
|
|
120
|
+
* copy, read that back — and held the loop at ~1.4 fps. Scaling and encoding
|
|
121
|
+
* are the same on both paths (bilinear scale, `Bitmap.compress`).
|
|
122
|
+
* `Photo.toImage()` applies the photo's rotation but also mirrors
|
|
123
|
+
* front-camera photos, which the file path does not; `encodeFrame` in the
|
|
124
|
+
* liveness step undoes that mirror, or TURN_LEFT / TURN_RIGHT invert.
|
|
125
|
+
*
|
|
126
|
+
* iOS stays on the file path it passes Iris with. Set to `false` to put
|
|
127
|
+
* Android back on it for an A/B run.
|
|
128
|
+
*/
|
|
129
|
+
export const ANDROID_IN_MEMORY_FRAMES = true;
|
|
130
|
+
const IN_MEMORY_FRAMES = Platform.OS === 'android' && ANDROID_IN_MEMORY_FRAMES;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* A liveness frame as the camera handed it over, before it is scaled and
|
|
134
|
+
* encoded for Iris. A `'memory'` frame holds a camera buffer until its photo
|
|
135
|
+
* is disposed, so whoever ends up with it must release it.
|
|
136
|
+
*/
|
|
137
|
+
export type CapturedFrame =
|
|
138
|
+
| { kind: 'file'; filePath: string }
|
|
139
|
+
| { kind: 'memory'; photo: Photo };
|
|
140
|
+
|
|
141
|
+
// Module-level so `<Camera>` gets stable references across re-renders.
|
|
142
|
+
const FPS_CONSTRAINTS = [{ fps: 30 }];
|
|
143
|
+
const NO_CONSTRAINTS: never[] = [];
|
|
144
|
+
const SESSION_CONSTRAINTS =
|
|
145
|
+
ACTIVE_LIVENESS_CAMERA_VARIANT === 'no-fps' ||
|
|
146
|
+
ACTIVE_LIVENESS_CAMERA_VARIANT === 'v4-equivalent'
|
|
147
|
+
? NO_CONSTRAINTS
|
|
148
|
+
: FPS_CONSTRAINTS;
|
|
149
|
+
|
|
150
|
+
const PHOTO_OUTPUT_OPTIONS =
|
|
151
|
+
IS_V4_EQUIVALENT
|
|
152
|
+
? {
|
|
153
|
+
qualityPrioritization: 'balanced' as const,
|
|
154
|
+
targetResolution: CommonResolutions.UHD_4_3,
|
|
155
|
+
quality: 0.9,
|
|
156
|
+
}
|
|
157
|
+
: {
|
|
158
|
+
qualityPrioritization: 'quality' as const,
|
|
159
|
+
targetResolution: CommonResolutions.FHD_4_3,
|
|
160
|
+
quality: 0.9,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The recorded liveness video, as this component reports it upwards.
|
|
165
|
+
*
|
|
166
|
+
* vision-camera v5 hands `onRecordingFinished` a bare file path, while the
|
|
167
|
+
* upload pipeline also wants the duration for the `liveness-verify` metadata.
|
|
168
|
+
* We read the duration off the `Recorder` before finalising and re-assemble
|
|
169
|
+
* both here, so the step keeps consuming one object instead of two loose
|
|
170
|
+
* values.
|
|
171
|
+
*/
|
|
172
|
+
export interface LivenessVideoFile {
|
|
173
|
+
/** Filesystem path, not a `file://` URL. */
|
|
174
|
+
path: string;
|
|
175
|
+
/** Recorded duration in seconds, or `undefined` when it could not be read. */
|
|
176
|
+
duration?: number | undefined;
|
|
177
|
+
}
|
|
178
|
+
|
|
47
179
|
export interface LivenessCameraHandle {
|
|
48
|
-
takeFrame: () => Promise<
|
|
180
|
+
takeFrame: () => Promise<CapturedFrame | null>;
|
|
49
181
|
/**
|
|
50
182
|
* Start an mp4/h264 video recording on the same `<Camera>` that feeds the
|
|
51
183
|
* frame loop. Audio is disabled. Errors during recording are delivered
|
|
@@ -54,9 +186,9 @@ export interface LivenessCameraHandle {
|
|
|
54
186
|
* even when this fails.
|
|
55
187
|
*/
|
|
56
188
|
startVideoRecording(opts: {
|
|
57
|
-
onRecordingFinished: (video:
|
|
189
|
+
onRecordingFinished: (video: LivenessVideoFile) => void;
|
|
58
190
|
onRecordingError: (err: unknown) => void;
|
|
59
|
-
}): void
|
|
191
|
+
}): Promise<void>;
|
|
60
192
|
/**
|
|
61
193
|
* Stop the active recording. Resolves once `onRecordingFinished` has been
|
|
62
194
|
* scheduled by vision-camera; the file path arrives there, not here.
|
|
@@ -97,18 +229,48 @@ export const LivenessCamera = forwardRef<LivenessCameraHandle, LivenessCameraPro
|
|
|
97
229
|
function LivenessCamera(props, ref) {
|
|
98
230
|
const theme = useTheme();
|
|
99
231
|
const insets = useSafeAreaInsets();
|
|
100
|
-
const cameraRef = useRef<
|
|
232
|
+
const cameraRef = useRef<CameraRef>(null);
|
|
101
233
|
const device = useCameraDevice('front');
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
234
|
+
// Stills at MAXIMIZE_QUALITY, used on iOS and on Android unless the switch
|
|
235
|
+
// above selects the preview snapshot.
|
|
236
|
+
// Capture WELL ABOVE the wire size on purpose (OSDKR-23).
|
|
237
|
+
//
|
|
238
|
+
// Iris scores sharpness as the Laplacian variance of the face region in
|
|
239
|
+
// the frame we send, and that number depends on how much we downscaled to
|
|
240
|
+
// get there. Downsampling concentrates detail and averages out sensor
|
|
241
|
+
// noise, so a 720 px frame derived from a large capture is measurably
|
|
242
|
+
// sharper than one captured at ~720 px natively.
|
|
243
|
+
//
|
|
244
|
+
// The spike had this at HD_4_3 (768x1024), reasoning that the frame gets
|
|
245
|
+
// resized to 720 anyway. It does — but that is a 0.94x scale, which keeps
|
|
246
|
+
// all of the lens softness and noise reduction of the native capture. On a
|
|
247
|
+
// Motorola Edge 30 Neo it measured `sharpness_quality` 0.16 average and
|
|
248
|
+
// 0.216 peak against a 0.35 threshold, with good lighting and a 312x470 px
|
|
249
|
+
// face: not a framing problem, a resolution one.
|
|
250
|
+
//
|
|
251
|
+
// FHD_4_3 gives a 2x linear downscale to the 720 px wire size at a
|
|
252
|
+
// fraction of the cost of the 12 MP default. Escalate to
|
|
253
|
+
// `CommonResolutions.UHD_4_3` — what iOS used when it passed the gate — if
|
|
254
|
+
// the measured sharpness is still short.
|
|
255
|
+
// Options live in PHOTO_OUTPUT_OPTIONS so the active variant can swap
|
|
256
|
+
// them; iOS stays on `'quality'` at FHD_4_3.
|
|
257
|
+
const photoOutput = usePhotoOutput(PHOTO_OUTPUT_OPTIONS);
|
|
258
|
+
// Pin the recording to 720p so the mp4 stays a few MB instead of the
|
|
259
|
+
// device-default 1080p–4K bitrate (a 30 s session can otherwise produce a
|
|
260
|
+
// 50–80 MB file that times out on mobile uplinks). Face visibility for
|
|
261
|
+
// liveness evidence is fine at 720p. Audio off — the backend never uses it
|
|
262
|
+
// and recording it would demand the microphone permission.
|
|
263
|
+
const videoOutput = useVideoOutput({
|
|
264
|
+
targetResolution: CommonResolutions.HD_16_9,
|
|
265
|
+
// ~2 Mbps. NOTE the unit: v5 takes bits per second, where v4's
|
|
266
|
+
// `videoBitRate` prop took megabits — passing `2` here would ask for
|
|
267
|
+
// 2 bps and produce an unusable file. The device default (~8 Mbps at
|
|
268
|
+
// 720p) yields a 38 MB file for a 30 s session; ~2 Mbps is plenty for
|
|
269
|
+
// face visibility as compliance evidence and lands around 7–8 MB.
|
|
270
|
+
targetBitRate: 2_000_000,
|
|
271
|
+
enableAudio: false,
|
|
272
|
+
fileType: 'mp4',
|
|
273
|
+
});
|
|
112
274
|
const { hasPermission, requestPermission } = useCameraPermission();
|
|
113
275
|
const requestedRef = useRef(false);
|
|
114
276
|
const inFlightRef = useRef(false);
|
|
@@ -116,6 +278,14 @@ export const LivenessCamera = forwardRef<LivenessCameraHandle, LivenessCameraPro
|
|
|
116
278
|
// infinite spinner after 4s without a device.
|
|
117
279
|
const [deviceTimeout, setDeviceTimeout] = useState(false);
|
|
118
280
|
|
|
281
|
+
useEffect(() => {
|
|
282
|
+
log.warn('[Liveness][diag] camera variant', {
|
|
283
|
+
variant: ACTIVE_LIVENESS_CAMERA_VARIANT,
|
|
284
|
+
configured: LIVENESS_CAMERA_VARIANT,
|
|
285
|
+
platform: Platform.OS,
|
|
286
|
+
});
|
|
287
|
+
}, []);
|
|
288
|
+
|
|
119
289
|
useEffect(() => {
|
|
120
290
|
if (!hasPermission && !requestedRef.current) {
|
|
121
291
|
requestedRef.current = true;
|
|
@@ -132,16 +302,17 @@ export const LivenessCamera = forwardRef<LivenessCameraHandle, LivenessCameraPro
|
|
|
132
302
|
return () => clearTimeout(t);
|
|
133
303
|
}, [device, hasPermission]);
|
|
134
304
|
|
|
135
|
-
const takeFrame = useCallback(async (): Promise<
|
|
305
|
+
const takeFrame = useCallback(async (): Promise<CapturedFrame | null> => {
|
|
136
306
|
if (inFlightRef.current) return null;
|
|
137
|
-
const camera = cameraRef.current;
|
|
138
|
-
if (!camera) return null;
|
|
139
307
|
inFlightRef.current = true;
|
|
140
308
|
try {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
309
|
+
const settings = { flashMode: 'off', enableShutterSound: false } as const;
|
|
310
|
+
if (IN_MEMORY_FRAMES) {
|
|
311
|
+
const photo = await photoOutput.capturePhoto(settings, {});
|
|
312
|
+
return { kind: 'memory', photo };
|
|
313
|
+
}
|
|
314
|
+
const file = await photoOutput.capturePhotoToFile(settings, {});
|
|
315
|
+
return { kind: 'file', filePath: file.filePath };
|
|
145
316
|
} catch {
|
|
146
317
|
// Frame failures are non-fatal — the parent loop just retries on the
|
|
147
318
|
// next tick. Keep the camera mounted.
|
|
@@ -149,47 +320,77 @@ export const LivenessCamera = forwardRef<LivenessCameraHandle, LivenessCameraPro
|
|
|
149
320
|
} finally {
|
|
150
321
|
inFlightRef.current = false;
|
|
151
322
|
}
|
|
152
|
-
}, []);
|
|
323
|
+
}, [photoOutput]);
|
|
153
324
|
|
|
154
|
-
// Recording is best-effort and orthogonal to the frame loop. We
|
|
155
|
-
// `
|
|
156
|
-
// parent calls it twice (e.g. on SESSION_COMPLETE and again on
|
|
157
|
-
|
|
325
|
+
// Recording is best-effort and orthogonal to the frame loop. We keep the
|
|
326
|
+
// live `Recorder` in a ref so `stopVideoRecording` is idempotent even if
|
|
327
|
+
// the parent calls it twice (e.g. on SESSION_COMPLETE and again on
|
|
328
|
+
// unmount). In v5 a Recorder is single-use: one is created per recording
|
|
329
|
+
// and discarded once it finishes.
|
|
330
|
+
const recorderRef = useRef<Recorder | null>(null);
|
|
331
|
+
// Duration read off the Recorder just before finalising. v5's
|
|
332
|
+
// `onRecordingFinished` only carries the file path, but the upload
|
|
333
|
+
// pipeline reports the duration in the `liveness-verify` metadata.
|
|
334
|
+
const recordedDurationRef = useRef<number | undefined>(undefined);
|
|
158
335
|
|
|
159
336
|
const startVideoRecording = useCallback(
|
|
160
|
-
(opts: {
|
|
161
|
-
onRecordingFinished: (video:
|
|
337
|
+
async (opts: {
|
|
338
|
+
onRecordingFinished: (video: LivenessVideoFile) => void;
|
|
162
339
|
onRecordingError: (err: unknown) => void;
|
|
163
|
-
}) => {
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
|
|
340
|
+
}): Promise<void> => {
|
|
341
|
+
if (recorderRef.current) return;
|
|
342
|
+
if (ACTIVE_LIVENESS_CAMERA_VARIANT === 'no-video') {
|
|
343
|
+
// The video output is not bound in this variant, so a Recorder on
|
|
344
|
+
// it would never start. Throwing sends the step down the same
|
|
345
|
+
// best-effort path as any other recording startup failure.
|
|
346
|
+
throw new Error('video recording disabled by diagnostic variant');
|
|
347
|
+
}
|
|
348
|
+
const recorder = await videoOutput.createRecorder({});
|
|
349
|
+
recorderRef.current = recorder;
|
|
350
|
+
recordedDurationRef.current = undefined;
|
|
351
|
+
try {
|
|
352
|
+
await recorder.startRecording(
|
|
353
|
+
(filePath) => {
|
|
354
|
+
const duration =
|
|
355
|
+
recordedDurationRef.current ??
|
|
356
|
+
(typeof recorder.recordedDuration === 'number'
|
|
357
|
+
? recorder.recordedDuration
|
|
358
|
+
: undefined);
|
|
359
|
+
recorderRef.current = null;
|
|
360
|
+
opts.onRecordingFinished({ path: filePath, duration });
|
|
361
|
+
},
|
|
362
|
+
(error) => {
|
|
363
|
+
recorderRef.current = null;
|
|
364
|
+
opts.onRecordingError(error);
|
|
365
|
+
},
|
|
366
|
+
);
|
|
367
|
+
} catch (err) {
|
|
368
|
+
// Startup failed, so neither callback will ever fire — release the
|
|
369
|
+
// ref here or every later start would short-circuit on it.
|
|
370
|
+
recorderRef.current = null;
|
|
371
|
+
throw err;
|
|
167
372
|
}
|
|
168
|
-
if (recordingRef.current) return;
|
|
169
|
-
recordingRef.current = true;
|
|
170
|
-
camera.startRecording({
|
|
171
|
-
fileType: 'mp4',
|
|
172
|
-
videoCodec: 'h264',
|
|
173
|
-
flash: 'off',
|
|
174
|
-
onRecordingFinished: (video) => {
|
|
175
|
-
recordingRef.current = false;
|
|
176
|
-
opts.onRecordingFinished(video);
|
|
177
|
-
},
|
|
178
|
-
onRecordingError: (err) => {
|
|
179
|
-
recordingRef.current = false;
|
|
180
|
-
opts.onRecordingError(err);
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
373
|
},
|
|
184
|
-
[],
|
|
374
|
+
[videoOutput],
|
|
185
375
|
);
|
|
186
376
|
|
|
187
377
|
const stopVideoRecording = useCallback(async (): Promise<void> => {
|
|
188
|
-
const
|
|
189
|
-
if (!
|
|
190
|
-
|
|
191
|
-
//
|
|
192
|
-
//
|
|
378
|
+
const recorder = recorderRef.current;
|
|
379
|
+
if (!recorder) return;
|
|
380
|
+
// Read the duration BEFORE stopping: once the recording is finalised the
|
|
381
|
+
// counter is no longer meaningful, and `onRecordingFinished` does not
|
|
382
|
+
// carry it.
|
|
383
|
+
try {
|
|
384
|
+
recordedDurationRef.current =
|
|
385
|
+
typeof recorder.recordedDuration === 'number'
|
|
386
|
+
? recorder.recordedDuration
|
|
387
|
+
: undefined;
|
|
388
|
+
} catch {
|
|
389
|
+
recordedDurationRef.current = undefined;
|
|
390
|
+
}
|
|
391
|
+
await recorder.stopRecording();
|
|
392
|
+
// recorderRef is cleared inside onRecordingFinished/onRecordingError to
|
|
393
|
+
// avoid a window where a follow-up start races with the unfinished stop.
|
|
193
394
|
}, []);
|
|
194
395
|
|
|
195
396
|
useImperativeHandle(
|
|
@@ -263,33 +464,26 @@ export const LivenessCamera = forwardRef<LivenessCameraHandle, LivenessCameraPro
|
|
|
263
464
|
ref={cameraRef}
|
|
264
465
|
style={StyleSheet.absoluteFill}
|
|
265
466
|
device={device}
|
|
266
|
-
//
|
|
267
|
-
//
|
|
268
|
-
//
|
|
269
|
-
{
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
//
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
//
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
//
|
|
282
|
-
//
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
// Keep the vision-camera default (`isMirrored=true` for front cam):
|
|
287
|
-
// overriding it to `false` causes a v4 iOS bug where the tkhd matrix
|
|
288
|
-
// is written rotated −90° instead of +90°, leaving the recorded mp4
|
|
289
|
-
// upside-down. The JPEG frames we send to Iris are un-mirrored
|
|
290
|
-
// separately in `captureAndSend` via a horizontal flip with
|
|
291
|
-
// expo-image-manipulator, so TURN_LEFT/RIGHT still maps to the
|
|
292
|
-
// real-world yaw.
|
|
467
|
+
// Photo stills feed Iris, video is the evidence recording; `<Camera>`
|
|
468
|
+
// prepends its own preview. See LIVENESS_CAMERA_VARIANT for the
|
|
469
|
+
// diagnostic combinations.
|
|
470
|
+
outputs={
|
|
471
|
+
ACTIVE_LIVENESS_CAMERA_VARIANT === 'no-video'
|
|
472
|
+
? [photoOutput]
|
|
473
|
+
: [photoOutput, videoOutput]
|
|
474
|
+
}
|
|
475
|
+
// Cap the sensor at 30 fps. Resolution and bit-rate are set on the
|
|
476
|
+
// video output itself (see `useVideoOutput` above).
|
|
477
|
+
constraints={SESSION_CONSTRAINTS}
|
|
478
|
+
// Lock the recorded video orientation to the interface's so it is
|
|
479
|
+
// never upside-down or sideways on the back-office player. (v5's
|
|
480
|
+
// spelling of what v4 called `outputOrientation="preview"`.)
|
|
481
|
+
orientationSource="interface"
|
|
482
|
+
// We keep the front camera's default mirroring rather than forcing
|
|
483
|
+
// `isMirrored=false`: in v4 that override triggered an iOS bug where
|
|
484
|
+
// the tkhd matrix was written rotated −90° instead of +90°, leaving
|
|
485
|
+
// the mp4 upside-down. Preview snapshots are un-mirrored in
|
|
486
|
+
// `takeFrame` before they go to Iris (OSDKR-23).
|
|
293
487
|
isActive
|
|
294
488
|
/>
|
|
295
489
|
<OvalOverlay
|
|
@@ -356,7 +356,7 @@ const styles = StyleSheet.create({
|
|
|
356
356
|
// so any backdrop colour would only show briefly while tiles are loading.
|
|
357
357
|
},
|
|
358
358
|
mapLoading: {
|
|
359
|
-
...StyleSheet.
|
|
359
|
+
...StyleSheet.absoluteFill,
|
|
360
360
|
alignItems: 'center',
|
|
361
361
|
justifyContent: 'center',
|
|
362
362
|
},
|
package/src/i18n/strings/en.ts
CHANGED
|
@@ -253,6 +253,8 @@ export const EN: StringsTable = {
|
|
|
253
253
|
positioningReady: 'Looking good — starting the challenges',
|
|
254
254
|
getReady: 'Heads up — starting now',
|
|
255
255
|
repositioning: "Let's pause a second — center your face and improve lighting. We'll retry the same step",
|
|
256
|
+
repositioningAfterMoveFarther:
|
|
257
|
+
"Go back to your previous distance — bring the phone a little closer and center your face. We'll retry the same step",
|
|
256
258
|
finalizing: 'Processing your video…',
|
|
257
259
|
challenge: {
|
|
258
260
|
FACE_FORWARD: 'Hold your face forward',
|
package/src/i18n/strings/es.ts
CHANGED
|
@@ -247,6 +247,8 @@ export const ES = {
|
|
|
247
247
|
positioningReady: 'Listo, ya estás bien posicionado — empezamos',
|
|
248
248
|
getReady: 'Atento — empezamos',
|
|
249
249
|
repositioning: 'Pausemos un segundo — centrá tu rostro y mejorá la luz. Reintentamos el mismo paso',
|
|
250
|
+
repositioningAfterMoveFarther:
|
|
251
|
+
'Volvé a la distancia de antes — acercá un poco el teléfono y centrá tu rostro. Reintentamos el mismo paso',
|
|
250
252
|
finalizing: 'Procesando tu video…',
|
|
251
253
|
analyzingHeadline: 'Analizando tu video',
|
|
252
254
|
analyzingCaption: 'Estamos verificando la prueba de vida. Tardará solo unos segundos.',
|