@incodetech/core 0.0.0-dev-20260127-938ff95 → 0.0.0-dev-20260130-5bb04b9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/OpenViduLogger-Cu0BjUgP.esm.js +3 -0
- package/dist/{deepsightLoader-Ct3HSIhk.esm.js → deepsightLoader-CGdK3U_s.esm.js} +7 -8
- package/dist/{deepsightService-B8c8aZje.esm.js → deepsightService-BqN04Xvz.esm.js} +53 -5
- package/dist/{types-CRVSv38Q.d.ts → deepsightService-C-8SR9TZ.d.ts} +91 -2
- package/dist/email.d.ts +1 -1
- package/dist/email.esm.js +3 -3
- package/dist/{endpoints-BUsSVoJV.esm.js → endpoints-CmGlc9UG.esm.js} +7 -1
- package/dist/{events-B8ZkhAZo.esm.js → events-CLVaKe2J.esm.js} +1 -1
- package/dist/flow.d.ts +2 -2
- package/dist/flow.esm.js +3 -3
- package/dist/id-DE76bgjS.esm.js +2498 -0
- package/dist/id.d.ts +5 -5
- package/dist/id.esm.js +7 -6
- package/dist/{index-CJMK8K5u.d.ts → index-aadmCg5s.d.ts} +84 -62
- package/dist/index.d.ts +78 -6
- package/dist/index.esm.js +12 -46
- package/dist/{lib-CbAibJlt.esm.js → lib-Cmee0CBZ.esm.js} +1 -1
- package/dist/phone.d.ts +1 -1
- package/dist/phone.esm.js +3 -3
- package/dist/selfie.d.ts +8 -87
- package/dist/selfie.esm.js +39 -19
- package/dist/{src-XSoNGEQW.esm.js → src-BEaVRVtC.esm.js} +6 -2
- package/dist/stats.d.ts +4 -0
- package/dist/stats.esm.js +1 -1
- package/dist/{streamingEvents-J6ffKmJL.esm.js → streamingEvents-EcGvh3bl.esm.js} +13 -4
- package/package.json +1 -1
- package/dist/OpenViduLogger-DyqID_-7.esm.js +0 -3
- package/dist/getDeviceClass-DkfbtsIJ.esm.js +0 -41
- package/dist/id-GPFS1Wo_.esm.js +0 -1827
- /package/dist/{Manager-Co-PsiG9.d.ts → Manager-WTb99jnh.d.ts} +0 -0
- /package/dist/{OpenViduLogger-BLxxXoyF.esm.js → OpenViduLogger-XKcjntVs.esm.js} +0 -0
- /package/dist/{stats-DnU4uUFv.esm.js → stats-onWUN0tY.esm.js} +0 -0
- /package/dist/{types-CMR6NkxW.d.ts → types-CflhN94Q.d.ts} +0 -0
package/dist/id-GPFS1Wo_.esm.js
DELETED
|
@@ -1,1827 +0,0 @@
|
|
|
1
|
-
import { d as addEvent, m as revokeObjectURL, n as eventModuleNames } from "./events-B8ZkhAZo.esm.js";
|
|
2
|
-
import { C as createManager, D as isIOS, E as isDesktop, O as isIPhone14OrHigher, S as stopCameraStream, T as isAndroid, b as enumerateVideoDevices, c as OpenViduRecordingProvider, d as BrowserTimerProvider, h as StreamCanvasCapture, k as isSafari, m as StreamCanvasProcessingSession, n as DEFAULT_ID_CAPTURE_THRESHOLDS, t as DEFAULT_ID_CAPTURE_MODEL_VERSION, v as IncodeCanvas, x as requestCameraAccess, y as applyTrackConstraints } from "./src-XSoNGEQW.esm.js";
|
|
3
|
-
import { n as getWindowDimensions } from "./getDeviceClass-DkfbtsIJ.esm.js";
|
|
4
|
-
import { a as fromPromise, i as fromCallback, n as setup, o as createActor, r as assign, t as endpoints } from "./endpoints-BUsSVoJV.esm.js";
|
|
5
|
-
import { c as getDeviceClass, i as stopRecording$1, n as createRecordingSession, o as checkPermission, r as startRecording, s as requestPermission, t as streamingEvents } from "./streamingEvents-J6ffKmJL.esm.js";
|
|
6
|
-
import { t as api } from "./api-DfRLAneb.esm.js";
|
|
7
|
-
|
|
8
|
-
//#region ../infra/src/capabilities/ITimerCapability.ts
|
|
9
|
-
function sleep(ms) {
|
|
10
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/modules/id/idCameraStream.ts
|
|
15
|
-
const BACK_CAMERA_KEYWORDS = [
|
|
16
|
-
"rear",
|
|
17
|
-
"back",
|
|
18
|
-
"rück",
|
|
19
|
-
"arrière",
|
|
20
|
-
"trasera",
|
|
21
|
-
"trás",
|
|
22
|
-
"traseira",
|
|
23
|
-
"posteriore",
|
|
24
|
-
"后面",
|
|
25
|
-
"後面",
|
|
26
|
-
"背面",
|
|
27
|
-
"后置",
|
|
28
|
-
"後置",
|
|
29
|
-
"背置",
|
|
30
|
-
"задней",
|
|
31
|
-
"الخلفية",
|
|
32
|
-
"후",
|
|
33
|
-
"arka",
|
|
34
|
-
"achterzijde",
|
|
35
|
-
"หลัง",
|
|
36
|
-
"baksidan",
|
|
37
|
-
"bagside",
|
|
38
|
-
"sau",
|
|
39
|
-
"bak",
|
|
40
|
-
"tylny",
|
|
41
|
-
"takakamera",
|
|
42
|
-
"belakang",
|
|
43
|
-
"אחורית",
|
|
44
|
-
"πίσω",
|
|
45
|
-
"spate",
|
|
46
|
-
"hátsó",
|
|
47
|
-
"zadní",
|
|
48
|
-
"darrere",
|
|
49
|
-
"zadná",
|
|
50
|
-
"задня",
|
|
51
|
-
"stražnja",
|
|
52
|
-
"बैक"
|
|
53
|
-
];
|
|
54
|
-
function isBackCameraLabel(label) {
|
|
55
|
-
const lowercaseLabel = label.toLowerCase();
|
|
56
|
-
return BACK_CAMERA_KEYWORDS.some((keyword) => lowercaseLabel.includes(keyword));
|
|
57
|
-
}
|
|
58
|
-
function classifyCamera(device, index, totalDevices) {
|
|
59
|
-
let cameraType;
|
|
60
|
-
if (device.label === "") cameraType = totalDevices === 1 || index + 1 <= totalDevices / 2 ? "front" : "back";
|
|
61
|
-
else cameraType = isBackCameraLabel(device.label) ? "back" : "front";
|
|
62
|
-
return {
|
|
63
|
-
deviceId: device.deviceId,
|
|
64
|
-
label: device.label,
|
|
65
|
-
cameraType
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
async function getCameras() {
|
|
69
|
-
const videoDevices = await enumerateVideoDevices();
|
|
70
|
-
const cameras = videoDevices.map((d, i) => classifyCamera(d, i, videoDevices.length));
|
|
71
|
-
if (cameras.length > 1 && !cameras.some((c) => c.cameraType === "back")) {
|
|
72
|
-
const resolutions = cameras.map((c) => {
|
|
73
|
-
const match = c.label.match(/\b([0-9]+)MP?\b/i);
|
|
74
|
-
return match ? parseInt(match[1], 10) : NaN;
|
|
75
|
-
});
|
|
76
|
-
let backCameraIndex = cameras.length - 1;
|
|
77
|
-
if (!resolutions.some(isNaN)) backCameraIndex = resolutions.lastIndexOf(Math.max(...resolutions));
|
|
78
|
-
cameras[backCameraIndex].cameraType = "back";
|
|
79
|
-
}
|
|
80
|
-
return cameras;
|
|
81
|
-
}
|
|
82
|
-
function selectMainCameraFromStream(track, cameras) {
|
|
83
|
-
const settings = track.getSettings();
|
|
84
|
-
const activeCamera = cameras.find((c) => c.deviceId === settings.deviceId || c.label !== "" && c.label === track.label);
|
|
85
|
-
if (!activeCamera) return void 0;
|
|
86
|
-
if ((settings.facingMode === "environment" || isBackCameraLabel(track.label)) && cameras.length > 1) {
|
|
87
|
-
cameras.forEach((camera) => {
|
|
88
|
-
if (camera.deviceId === activeCamera.deviceId) camera.cameraType = "back";
|
|
89
|
-
else if (!isBackCameraLabel(camera.label)) camera.cameraType = "front";
|
|
90
|
-
});
|
|
91
|
-
return cameras.filter((c) => c.cameraType === "back").sort((a, b) => a.label.localeCompare(b.label))[0];
|
|
92
|
-
}
|
|
93
|
-
if (cameras.length === 1) return activeCamera;
|
|
94
|
-
}
|
|
95
|
-
function getAndroidVideoConstraints(level) {
|
|
96
|
-
const base = {
|
|
97
|
-
resizeMode: "none",
|
|
98
|
-
facingMode: "environment"
|
|
99
|
-
};
|
|
100
|
-
switch (level) {
|
|
101
|
-
case 0: return {
|
|
102
|
-
...base,
|
|
103
|
-
height: { ideal: 720 },
|
|
104
|
-
aspectRatio: { ideal: 19.5 / 9 }
|
|
105
|
-
};
|
|
106
|
-
case 1: return {
|
|
107
|
-
...base,
|
|
108
|
-
width: {
|
|
109
|
-
min: 3200,
|
|
110
|
-
ideal: 3840,
|
|
111
|
-
max: 4096
|
|
112
|
-
},
|
|
113
|
-
height: {
|
|
114
|
-
min: 1800,
|
|
115
|
-
ideal: 2160,
|
|
116
|
-
max: 2400
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
case 2: return {
|
|
120
|
-
...base,
|
|
121
|
-
width: {
|
|
122
|
-
min: 1400,
|
|
123
|
-
ideal: 1920,
|
|
124
|
-
max: 2160
|
|
125
|
-
},
|
|
126
|
-
height: {
|
|
127
|
-
min: 900,
|
|
128
|
-
ideal: 1080,
|
|
129
|
-
max: 1440
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
case 3: return {
|
|
133
|
-
...base,
|
|
134
|
-
width: {
|
|
135
|
-
min: 640,
|
|
136
|
-
ideal: 640,
|
|
137
|
-
max: 800
|
|
138
|
-
},
|
|
139
|
-
height: {
|
|
140
|
-
min: 480,
|
|
141
|
-
ideal: 480,
|
|
142
|
-
max: 600
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
case 4: return {
|
|
146
|
-
...base,
|
|
147
|
-
width: {
|
|
148
|
-
min: 640,
|
|
149
|
-
ideal: 800,
|
|
150
|
-
max: 960
|
|
151
|
-
},
|
|
152
|
-
height: {
|
|
153
|
-
min: 480,
|
|
154
|
-
ideal: 480,
|
|
155
|
-
max: 480
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
default: return {};
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
async function getAndroidBackCameraStream(fallbackLevel = 0) {
|
|
162
|
-
if (fallbackLevel > 4) throw new Error("Failed to get camera after all fallback attempts");
|
|
163
|
-
try {
|
|
164
|
-
const initialStream = await requestCameraAccess({ video: getAndroidVideoConstraints(fallbackLevel) });
|
|
165
|
-
const track = initialStream.getVideoTracks()[0];
|
|
166
|
-
const mainCamera = selectMainCameraFromStream(track, await getCameras());
|
|
167
|
-
stopCameraStream(initialStream);
|
|
168
|
-
if (!mainCamera) throw new Error("Could not identify main camera");
|
|
169
|
-
let idealWidth = 1280;
|
|
170
|
-
let idealHeight = 720;
|
|
171
|
-
if (fallbackLevel > 1) {
|
|
172
|
-
const constraints = getAndroidVideoConstraints(fallbackLevel);
|
|
173
|
-
const width = constraints.width;
|
|
174
|
-
const height = constraints.height;
|
|
175
|
-
idealWidth = width?.ideal ?? 1280;
|
|
176
|
-
idealHeight = height?.ideal ?? 720;
|
|
177
|
-
}
|
|
178
|
-
return await requestCameraAccess({ video: {
|
|
179
|
-
deviceId: { exact: mainCamera.deviceId },
|
|
180
|
-
width: { ideal: idealWidth },
|
|
181
|
-
height: { ideal: idealHeight }
|
|
182
|
-
} });
|
|
183
|
-
} catch (error) {
|
|
184
|
-
const errorName = error instanceof Error ? error.name : "UnknownError";
|
|
185
|
-
const nextLevel = Math.min(fallbackLevel + 1, 4);
|
|
186
|
-
if (errorName === "NotReadableError") {
|
|
187
|
-
await sleep(300);
|
|
188
|
-
return getAndroidBackCameraStream(nextLevel);
|
|
189
|
-
}
|
|
190
|
-
if (errorName === "AbortError") {
|
|
191
|
-
await sleep(300);
|
|
192
|
-
return getAndroidBackCameraStream(fallbackLevel);
|
|
193
|
-
}
|
|
194
|
-
return getAndroidBackCameraStream(nextLevel);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
async function applyIOSFocusHack(stream) {
|
|
198
|
-
const videoTrack = stream.getVideoTracks()[0];
|
|
199
|
-
try {
|
|
200
|
-
await applyTrackConstraints(videoTrack, { advanced: [{ focusDistance: 1 }] });
|
|
201
|
-
} catch {}
|
|
202
|
-
}
|
|
203
|
-
function getIOSConstraints() {
|
|
204
|
-
return {
|
|
205
|
-
audio: false,
|
|
206
|
-
video: {
|
|
207
|
-
resizeMode: "none",
|
|
208
|
-
facingMode: "environment",
|
|
209
|
-
height: { ideal: isIPhone14OrHigher() ? 1080 : 720 },
|
|
210
|
-
aspectRatio: { ideal: 19.5 / 9 }
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
async function getIOSCameraStream() {
|
|
215
|
-
const stream = await requestCameraAccess(getIOSConstraints());
|
|
216
|
-
await applyIOSFocusHack(stream);
|
|
217
|
-
return stream;
|
|
218
|
-
}
|
|
219
|
-
function getDesktopConstraints(options) {
|
|
220
|
-
const { deviceId } = options;
|
|
221
|
-
return {
|
|
222
|
-
audio: isSafari(),
|
|
223
|
-
video: {
|
|
224
|
-
facingMode: "user",
|
|
225
|
-
deviceId: deviceId ? { exact: deviceId } : void 0,
|
|
226
|
-
height: { ideal: 1080 },
|
|
227
|
-
width: { ideal: 1920 }
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
async function getDesktopCameraStream(options) {
|
|
232
|
-
return requestCameraAccess(getDesktopConstraints(options));
|
|
233
|
-
}
|
|
234
|
-
async function getIdCameraStream(deviceId) {
|
|
235
|
-
if (isIOS()) return getIOSCameraStream();
|
|
236
|
-
if (isAndroid()) return getAndroidBackCameraStream(0);
|
|
237
|
-
if (isDesktop()) return getDesktopCameraStream({ deviceId });
|
|
238
|
-
return getDesktopCameraStream({ deviceId });
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
//#endregion
|
|
242
|
-
//#region src/modules/id/types.ts
|
|
243
|
-
const ID_ERROR_CODES = {
|
|
244
|
-
UPLOAD_ERROR: "UPLOAD_ERROR",
|
|
245
|
-
CLASSIFICATION_FAILED: "CLASSIFICATION_FAILED",
|
|
246
|
-
LOW_SHARPNESS: "LOW_SHARPNESS",
|
|
247
|
-
GLARE_DETECTED: "GLARE_DETECTED",
|
|
248
|
-
WRONG_DOCUMENT_SIDE: "WRONG_DOCUMENT_SIDE",
|
|
249
|
-
ID_TYPE_UNACCEPTABLE: "ID_TYPE_UNACCEPTABLE",
|
|
250
|
-
READABILITY_ISSUE: "READABILITY_ISSUE",
|
|
251
|
-
RETRY_EXHAUSTED_CONTINUE_TO_BACK: "RETRY_EXHAUSTED_CONTINUE_TO_BACK",
|
|
252
|
-
RETRY_EXHAUSTED_SKIP_BACK: "RETRY_EXHAUSTED_SKIP_BACK",
|
|
253
|
-
NO_MORE_TRIES: "NO_MORE_TRIES",
|
|
254
|
-
UNEXPECTED_ERROR: "UNEXPECTED_ERROR",
|
|
255
|
-
NO_TOKEN: "NO_TOKEN",
|
|
256
|
-
PERMISSION_DENIED: "PERMISSION_DENIED",
|
|
257
|
-
USER_CANCELLED: "USER_CANCELLED",
|
|
258
|
-
SERVER: "SERVER_ERROR"
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
//#endregion
|
|
262
|
-
//#region src/modules/id/idCaptureServices.ts
|
|
263
|
-
const SHARPNESS_THRESHOLD = 10;
|
|
264
|
-
const GLARE_THRESHOLD = 10;
|
|
265
|
-
const DEFAULT_ID_CAPTURE_THRESHOLDS$1 = {
|
|
266
|
-
blurThreshold: .2,
|
|
267
|
-
blurChangeThreshold: .2,
|
|
268
|
-
glareThreshold: .3,
|
|
269
|
-
clsThreshold: .98,
|
|
270
|
-
sideThreshold: .8,
|
|
271
|
-
iouThreshold: .8,
|
|
272
|
-
framesAggregationInterval: 3e3,
|
|
273
|
-
minFaceIdQualityScore: .62
|
|
274
|
-
};
|
|
275
|
-
const DEFAULT_ID_CAPTURE_SETTINGS = {
|
|
276
|
-
isFixedMask: false,
|
|
277
|
-
isIPhone14OrHigher: false,
|
|
278
|
-
idType: "",
|
|
279
|
-
blurCheckEnabled: false,
|
|
280
|
-
glareCheckEnabled: false,
|
|
281
|
-
faceQualityCheckEnabled: true,
|
|
282
|
-
iouCheckEnabled: true
|
|
283
|
-
};
|
|
284
|
-
async function initializeIdCapture(provider, config) {
|
|
285
|
-
await provider.initialize({});
|
|
286
|
-
provider.setThresholds({
|
|
287
|
-
...DEFAULT_ID_CAPTURE_THRESHOLDS$1,
|
|
288
|
-
...config.thresholds,
|
|
289
|
-
idDetectedTimeout: config.thresholds?.idDetectedTimeout ?? config.deviceIdleTimeout * 1e3,
|
|
290
|
-
autocaptureTimeout: config.thresholds?.autocaptureTimeout ?? config.autoCaptureTimeout * 1e3
|
|
291
|
-
});
|
|
292
|
-
if (config.settings) provider.setSettings({
|
|
293
|
-
...DEFAULT_ID_CAPTURE_SETTINGS,
|
|
294
|
-
...config.settings
|
|
295
|
-
});
|
|
296
|
-
return {
|
|
297
|
-
stream: await getIdCameraStream(),
|
|
298
|
-
provider
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
function stopStream(stream) {
|
|
302
|
-
for (const track of stream.getTracks()) track.stop();
|
|
303
|
-
}
|
|
304
|
-
function validateUploadResponse(response, sessionState) {
|
|
305
|
-
if (response.failReason === "ID_TYPE_UNACCEPTABLE") return {
|
|
306
|
-
error: true,
|
|
307
|
-
message: "ID type is not acceptable",
|
|
308
|
-
messageDescription: "Please use a valid ID type",
|
|
309
|
-
errorKey: ID_ERROR_CODES.ID_TYPE_UNACCEPTABLE
|
|
310
|
-
};
|
|
311
|
-
if (response.failReason === "WRONG_DOCUMENT_SIDE") return {
|
|
312
|
-
error: true,
|
|
313
|
-
message: "Wrong side of document",
|
|
314
|
-
messageDescription: response.side === "back" ? "Please show the back side of your ID" : "Please show the front side of your ID",
|
|
315
|
-
errorKey: ID_ERROR_CODES.WRONG_DOCUMENT_SIDE
|
|
316
|
-
};
|
|
317
|
-
if (!response.classification) return {
|
|
318
|
-
error: true,
|
|
319
|
-
message: "ID classification failed",
|
|
320
|
-
errorKey: ID_ERROR_CODES.CLASSIFICATION_FAILED
|
|
321
|
-
};
|
|
322
|
-
const sharpnessThreshold = getDeviceClass() === "desktop" ? -1 : SHARPNESS_THRESHOLD;
|
|
323
|
-
if (response.sharpness !== void 0 && sharpnessThreshold >= 0 && response.sharpness < sharpnessThreshold) return {
|
|
324
|
-
error: true,
|
|
325
|
-
message: "Image is not sharp enough",
|
|
326
|
-
messageDescription: "Please ensure the image is clear and well-focused",
|
|
327
|
-
errorKey: ID_ERROR_CODES.LOW_SHARPNESS
|
|
328
|
-
};
|
|
329
|
-
if (response.glare !== void 0 && response.glare < GLARE_THRESHOLD && !sessionState?.skipGlareFront && !sessionState?.skipGlareBack) return {
|
|
330
|
-
error: true,
|
|
331
|
-
message: "Glare detected on ID",
|
|
332
|
-
messageDescription: "Please avoid bright reflections on your ID",
|
|
333
|
-
errorKey: ID_ERROR_CODES.GLARE_DETECTED
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
async function getExtraImages(params) {
|
|
337
|
-
const extraImages = params.ageAssurance ? [params.type === "back" ? "croppedBackID" : "croppedFrontID"] : [];
|
|
338
|
-
try {
|
|
339
|
-
const res = await api.post(endpoints.getImages, { images: ["croppedIDFace", ...extraImages] }, { signal: params.signal });
|
|
340
|
-
if (!res.ok) throw new Error(`Failed to get extra images: ${res.status}`);
|
|
341
|
-
return res.data ?? {
|
|
342
|
-
croppedIDFace: "",
|
|
343
|
-
croppedFrontID: "",
|
|
344
|
-
croppedBackID: ""
|
|
345
|
-
};
|
|
346
|
-
} catch {
|
|
347
|
-
return {
|
|
348
|
-
croppedIDFace: "",
|
|
349
|
-
croppedFrontID: "",
|
|
350
|
-
croppedBackID: ""
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
const getRealQualityValue = (value) => (1 - value) * 100;
|
|
355
|
-
async function uploadIdImage(params) {
|
|
356
|
-
const { type, image, onProgress, signal, metadata, ageAssurance, glare, sharpness, shouldSkipGlareBack } = params;
|
|
357
|
-
addEvent({
|
|
358
|
-
code: "captureAttemptFinished",
|
|
359
|
-
module: eventModuleNames.id,
|
|
360
|
-
payload: { logs: [] }
|
|
361
|
-
});
|
|
362
|
-
const endpoint = type === "front" ? endpoints.frontId : endpoints.backId;
|
|
363
|
-
const body = {
|
|
364
|
-
base64Image: image,
|
|
365
|
-
metadata,
|
|
366
|
-
clientInfo: { deviceClass: getDeviceClass() }
|
|
367
|
-
};
|
|
368
|
-
const queryParams = { imageType: "id" };
|
|
369
|
-
if (shouldSkipGlareBack && type === "back") queryParams.glare = 0;
|
|
370
|
-
else if (glare !== void 0) queryParams.glare = getRealQualityValue(glare);
|
|
371
|
-
if (sharpness !== void 0) queryParams.sharpness = getRealQualityValue(sharpness);
|
|
372
|
-
try {
|
|
373
|
-
const res = await api.post(endpoint, body, {
|
|
374
|
-
signal,
|
|
375
|
-
query: queryParams,
|
|
376
|
-
onUploadProgress: onProgress
|
|
377
|
-
});
|
|
378
|
-
if (!res.ok) throw new Error(`POST ${endpoint} failed: ${res.status} ${res.statusText}`);
|
|
379
|
-
const response = res.data;
|
|
380
|
-
const extraImages = await getExtraImages({
|
|
381
|
-
type,
|
|
382
|
-
ageAssurance,
|
|
383
|
-
signal
|
|
384
|
-
});
|
|
385
|
-
const fullResponse = {
|
|
386
|
-
...response,
|
|
387
|
-
originalImage: image,
|
|
388
|
-
frontIdImage: type === "front" ? image : void 0,
|
|
389
|
-
backIdImage: extraImages.croppedBackID,
|
|
390
|
-
...extraImages
|
|
391
|
-
};
|
|
392
|
-
onProgress?.(100);
|
|
393
|
-
return fullResponse;
|
|
394
|
-
} catch (error) {
|
|
395
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
396
|
-
throw new Error(`${ID_ERROR_CODES.UPLOAD_ERROR}: ${errorMessage}`);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
function buildStandardResolution(width, height) {
|
|
400
|
-
return height > width ? {
|
|
401
|
-
width: 1080,
|
|
402
|
-
height: 1920
|
|
403
|
-
} : {
|
|
404
|
-
width: 1920,
|
|
405
|
-
height: 1080
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
function buildResolutionFromStream(stream) {
|
|
409
|
-
const track = stream.getVideoTracks()[0];
|
|
410
|
-
if (!track) return "1080x1920";
|
|
411
|
-
const settings = track.getSettings();
|
|
412
|
-
const width = settings.width;
|
|
413
|
-
const height = settings.height;
|
|
414
|
-
if (typeof width === "number" && typeof height === "number") {
|
|
415
|
-
const standard = buildStandardResolution(width, height);
|
|
416
|
-
return `${standard.width}x${standard.height}`;
|
|
417
|
-
}
|
|
418
|
-
return "1080x1920";
|
|
419
|
-
}
|
|
420
|
-
async function startRecordingSession(params) {
|
|
421
|
-
if (params.config.enableIdRecording !== true) return;
|
|
422
|
-
if (params.existing) return params.existing;
|
|
423
|
-
const provider = params.config.recording?.capability ?? new OpenViduRecordingProvider();
|
|
424
|
-
const clonedStream = params.stream.clone();
|
|
425
|
-
const hasAudio = clonedStream.getAudioTracks().length > 0;
|
|
426
|
-
const resolution = buildResolutionFromStream(clonedStream);
|
|
427
|
-
const session = await createRecordingSession(params.type);
|
|
428
|
-
const connection = await provider.connect({
|
|
429
|
-
sessionToken: session.token,
|
|
430
|
-
stream: clonedStream,
|
|
431
|
-
events: {
|
|
432
|
-
onSessionConnected: (sessionId) => {
|
|
433
|
-
addEvent({
|
|
434
|
-
code: streamingEvents.strSessionDidConnect,
|
|
435
|
-
module: eventModuleNames.id,
|
|
436
|
-
payload: {
|
|
437
|
-
message: "Recording session connected",
|
|
438
|
-
sessionId
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
},
|
|
442
|
-
onSessionDisconnected: (sessionId) => {
|
|
443
|
-
addEvent({
|
|
444
|
-
code: streamingEvents.strSessionDidDisconnect,
|
|
445
|
-
module: eventModuleNames.id,
|
|
446
|
-
payload: {
|
|
447
|
-
message: "Recording session disconnected",
|
|
448
|
-
sessionId
|
|
449
|
-
}
|
|
450
|
-
});
|
|
451
|
-
},
|
|
452
|
-
onSessionException: (event) => {
|
|
453
|
-
addEvent({
|
|
454
|
-
code: streamingEvents.strSessionDidFailWithError,
|
|
455
|
-
module: eventModuleNames.id,
|
|
456
|
-
payload: {
|
|
457
|
-
message: "Recording session failed due to an error",
|
|
458
|
-
eventName: event.name,
|
|
459
|
-
type: "OpenViduException",
|
|
460
|
-
errorMessage: event.message,
|
|
461
|
-
sessionId: event.sessionId
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
},
|
|
465
|
-
onPublisherCreated: (p) => {
|
|
466
|
-
addEvent({
|
|
467
|
-
code: streamingEvents.strStreamPublisherCreated,
|
|
468
|
-
module: eventModuleNames.id,
|
|
469
|
-
payload: {
|
|
470
|
-
message: "Recording publisher created",
|
|
471
|
-
sessionId: p.sessionId,
|
|
472
|
-
streamId: p.streamId
|
|
473
|
-
}
|
|
474
|
-
});
|
|
475
|
-
},
|
|
476
|
-
onPublisherError: (p) => {
|
|
477
|
-
addEvent({
|
|
478
|
-
code: streamingEvents.strStreamPublisherDidFailWithError,
|
|
479
|
-
module: eventModuleNames.id,
|
|
480
|
-
payload: {
|
|
481
|
-
message: "Recording publisher failed due to an error",
|
|
482
|
-
sessionId: p.sessionId,
|
|
483
|
-
streamId: p.streamId,
|
|
484
|
-
error: { message: p.message ?? "Unknown error" }
|
|
485
|
-
}
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
await startRecording({
|
|
491
|
-
videoRecordingId: session.videoRecordingId,
|
|
492
|
-
type: params.type,
|
|
493
|
-
resolution,
|
|
494
|
-
hasAudio
|
|
495
|
-
});
|
|
496
|
-
addEvent({
|
|
497
|
-
code: streamingEvents.strStreamVideoCaptureStart,
|
|
498
|
-
module: eventModuleNames.id,
|
|
499
|
-
payload: {
|
|
500
|
-
message: "Recording capture started",
|
|
501
|
-
resolution,
|
|
502
|
-
videoRecordingId: session.videoRecordingId,
|
|
503
|
-
sessionId: session.sessionId,
|
|
504
|
-
streamId: connection.publisher.getStreamId()
|
|
505
|
-
}
|
|
506
|
-
});
|
|
507
|
-
return {
|
|
508
|
-
token: session.token,
|
|
509
|
-
sessionId: session.sessionId,
|
|
510
|
-
videoRecordingId: session.videoRecordingId,
|
|
511
|
-
connection,
|
|
512
|
-
resolution,
|
|
513
|
-
hasAudio
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
function stopRecording(session) {
|
|
517
|
-
(async () => {
|
|
518
|
-
try {
|
|
519
|
-
addEvent({
|
|
520
|
-
code: streamingEvents.strStreamVideoCaptureStop,
|
|
521
|
-
module: eventModuleNames.id,
|
|
522
|
-
payload: {
|
|
523
|
-
message: "Recording capture stopped",
|
|
524
|
-
videoRecordingId: session.videoRecordingId,
|
|
525
|
-
sessionId: session.sessionId,
|
|
526
|
-
streamId: session.connection.publisher.getStreamId()
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
|
-
await stopRecording$1(session.videoRecordingId);
|
|
530
|
-
addEvent({
|
|
531
|
-
code: streamingEvents.strStreamPublisherDestroyed,
|
|
532
|
-
module: eventModuleNames.id,
|
|
533
|
-
payload: {
|
|
534
|
-
message: "Recording publisher destroyed",
|
|
535
|
-
sessionId: session.sessionId,
|
|
536
|
-
streamId: session.connection.publisher.getStreamId()
|
|
537
|
-
}
|
|
538
|
-
});
|
|
539
|
-
} finally {
|
|
540
|
-
await session.connection.disconnect();
|
|
541
|
-
addEvent({
|
|
542
|
-
code: streamingEvents.strSessionDidDisconnect,
|
|
543
|
-
module: eventModuleNames.id,
|
|
544
|
-
payload: {
|
|
545
|
-
message: "Recording session disconnected",
|
|
546
|
-
sessionId: session.sessionId
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
})();
|
|
551
|
-
}
|
|
552
|
-
async function processId(isSecondId = false, queueName = "", signal) {
|
|
553
|
-
const endpoint = isSecondId ? endpoints.processSecondId : endpoints.processId;
|
|
554
|
-
const url = queueName ? `${endpoint}?queueName=${queueName}` : endpoint;
|
|
555
|
-
return { isDocumentExpired: (await api.post(url, {}, { signal })).data?.isDocumentExpired ?? false };
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
//#endregion
|
|
559
|
-
//#region src/modules/id/idCaptureStateMachine.ts
|
|
560
|
-
function getIdErrorCodeFromUnknown(error) {
|
|
561
|
-
if (error instanceof Error) {
|
|
562
|
-
const message = error.message;
|
|
563
|
-
return Object.values(ID_ERROR_CODES).find((value) => message.includes(value));
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
const _idCaptureMachine = setup({
|
|
567
|
-
types: {
|
|
568
|
-
context: {},
|
|
569
|
-
events: {},
|
|
570
|
-
input: {}
|
|
571
|
-
},
|
|
572
|
-
actors: {
|
|
573
|
-
checkPermission: fromPromise(async () => {
|
|
574
|
-
return checkPermission();
|
|
575
|
-
}),
|
|
576
|
-
requestPermission: fromPromise(async () => {
|
|
577
|
-
return requestPermission();
|
|
578
|
-
}),
|
|
579
|
-
initializeCamera: fromPromise(async ({ input }) => {
|
|
580
|
-
return initializeIdCapture(input.provider, input.config);
|
|
581
|
-
}),
|
|
582
|
-
runDetection: fromCallback(({ input, sendBack }) => {
|
|
583
|
-
if (!input.frameCapturer || !input.provider) {
|
|
584
|
-
sendBack({
|
|
585
|
-
type: "DETECTION_UPDATE",
|
|
586
|
-
status: "error"
|
|
587
|
-
});
|
|
588
|
-
return () => {};
|
|
589
|
-
}
|
|
590
|
-
const provider = input.provider;
|
|
591
|
-
let session;
|
|
592
|
-
let currentCanvas = null;
|
|
593
|
-
let bestCanvas = null;
|
|
594
|
-
let storedQualityElements = {};
|
|
595
|
-
let isCapturing = false;
|
|
596
|
-
const timer = BrowserTimerProvider.getInstance();
|
|
597
|
-
let notificationTimeout = null;
|
|
598
|
-
let currentNotificationStatus = null;
|
|
599
|
-
const NOTIFICATION_DURATION_MS = 500;
|
|
600
|
-
const clearNotificationTimeout = () => {
|
|
601
|
-
if (notificationTimeout) {
|
|
602
|
-
timer.clearTimeout(notificationTimeout);
|
|
603
|
-
notificationTimeout = null;
|
|
604
|
-
currentNotificationStatus = null;
|
|
605
|
-
}
|
|
606
|
-
};
|
|
607
|
-
const sendNotification = (status) => {
|
|
608
|
-
if (notificationTimeout && currentNotificationStatus !== status) return;
|
|
609
|
-
if (notificationTimeout && currentNotificationStatus === status) timer.clearTimeout(notificationTimeout);
|
|
610
|
-
currentNotificationStatus = status;
|
|
611
|
-
sendBack({
|
|
612
|
-
type: "DETECTION_UPDATE",
|
|
613
|
-
status
|
|
614
|
-
});
|
|
615
|
-
notificationTimeout = timer.setTimeout(() => {
|
|
616
|
-
notificationTimeout = null;
|
|
617
|
-
currentNotificationStatus = null;
|
|
618
|
-
sendBack({
|
|
619
|
-
type: "DETECTION_UPDATE",
|
|
620
|
-
status: "detecting"
|
|
621
|
-
});
|
|
622
|
-
}, NOTIFICATION_DURATION_MS);
|
|
623
|
-
};
|
|
624
|
-
const canvas = input.frameCapturer.getLatestCanvas();
|
|
625
|
-
const windowDimensions = getWindowDimensions(canvas?.width() ?? 1280, canvas?.height() ?? 720);
|
|
626
|
-
const DEFAULT_GEOMETRY = {
|
|
627
|
-
areaDown: 25e3,
|
|
628
|
-
areaUp: 55e3,
|
|
629
|
-
areaIOSPassportUp: 3e4,
|
|
630
|
-
areaIOSPassportDown: 2e4,
|
|
631
|
-
widthIOSUp: 160,
|
|
632
|
-
widthIOSDown: 85,
|
|
633
|
-
widthDown: 110,
|
|
634
|
-
widthUp: 205
|
|
635
|
-
};
|
|
636
|
-
if (input.config.geometry) provider.setGeometry({
|
|
637
|
-
...input.config.geometry,
|
|
638
|
-
windowOuterWidth: windowDimensions.outerWidth,
|
|
639
|
-
windowOuterHeight: windowDimensions.outerHeight,
|
|
640
|
-
windowInnerWidth: windowDimensions.innerWidth,
|
|
641
|
-
windowInnerHeight: windowDimensions.innerHeight
|
|
642
|
-
});
|
|
643
|
-
else provider.setGeometry({
|
|
644
|
-
...DEFAULT_GEOMETRY,
|
|
645
|
-
windowOuterWidth: windowDimensions.outerWidth,
|
|
646
|
-
windowOuterHeight: windowDimensions.outerHeight,
|
|
647
|
-
windowInnerWidth: windowDimensions.innerWidth,
|
|
648
|
-
windowInnerHeight: windowDimensions.innerHeight
|
|
649
|
-
});
|
|
650
|
-
const idType = input.currentMode === "back" ? "BackId" : input.currentMode === "passport" || input.currentMode === "front" && input.config.onlyFront ? "Passport" : "FrontId";
|
|
651
|
-
provider.setSettings({
|
|
652
|
-
isFixedMask: input.config.settings?.isFixedMask ?? false,
|
|
653
|
-
isIPhone14OrHigher: input.config.settings?.isIPhone14OrHigher ?? false,
|
|
654
|
-
idType,
|
|
655
|
-
blurCheckEnabled: input.config.settings?.blurCheckEnabled ?? false,
|
|
656
|
-
glareCheckEnabled: input.config.settings?.glareCheckEnabled ?? false,
|
|
657
|
-
faceQualityCheckEnabled: input.config.settings?.faceQualityCheckEnabled ?? true,
|
|
658
|
-
iouCheckEnabled: input.config.settings?.iouCheckEnabled ?? true
|
|
659
|
-
});
|
|
660
|
-
const thresholds = {
|
|
661
|
-
...DEFAULT_ID_CAPTURE_THRESHOLDS,
|
|
662
|
-
...input.config.thresholds,
|
|
663
|
-
idDetectedTimeout: (input.config.deviceIdleTimeout ?? 10) * 1e3,
|
|
664
|
-
autocaptureTimeout: (input.config.autoCaptureTimeout ?? 5) * 1e3
|
|
665
|
-
};
|
|
666
|
-
provider.setThresholds(thresholds);
|
|
667
|
-
const modelType = input.config.modelVersion ?? DEFAULT_ID_CAPTURE_MODEL_VERSION;
|
|
668
|
-
provider.setModelType(modelType);
|
|
669
|
-
provider.setCallbacks({
|
|
670
|
-
onFarAway: () => {
|
|
671
|
-
if (!isCapturing) sendNotification("farAway");
|
|
672
|
-
},
|
|
673
|
-
onDetectionStarted: () => {},
|
|
674
|
-
onMaskChange: (_show, _mask, _top, orientation) => {
|
|
675
|
-
sendBack({
|
|
676
|
-
type: "ORIENTATION_CHANGE",
|
|
677
|
-
orientation
|
|
678
|
-
});
|
|
679
|
-
},
|
|
680
|
-
onBlur: () => {
|
|
681
|
-
if (!isCapturing) sendNotification("blur");
|
|
682
|
-
},
|
|
683
|
-
onGlare: () => {
|
|
684
|
-
if (!isCapturing) sendNotification("glare");
|
|
685
|
-
},
|
|
686
|
-
onIdNotDetected: () => {
|
|
687
|
-
if (!isCapturing) sendBack({
|
|
688
|
-
type: "DETECTION_UPDATE",
|
|
689
|
-
status: "idNotDetected"
|
|
690
|
-
});
|
|
691
|
-
},
|
|
692
|
-
onSwitchToManualCapture: () => {
|
|
693
|
-
isCapturing = false;
|
|
694
|
-
sendBack({
|
|
695
|
-
type: "DETECTION_UPDATE",
|
|
696
|
-
status: "manualCapture"
|
|
697
|
-
});
|
|
698
|
-
},
|
|
699
|
-
onCapturing: () => {
|
|
700
|
-
clearNotificationTimeout();
|
|
701
|
-
isCapturing = true;
|
|
702
|
-
sendBack({
|
|
703
|
-
type: "DETECTION_UPDATE",
|
|
704
|
-
status: "capturing"
|
|
705
|
-
});
|
|
706
|
-
},
|
|
707
|
-
onBestFrame: (blur, glare, orientation) => {
|
|
708
|
-
if (currentCanvas) {
|
|
709
|
-
bestCanvas = currentCanvas.clone();
|
|
710
|
-
storedQualityElements = {
|
|
711
|
-
glare,
|
|
712
|
-
sharpness: blur
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
|
-
if (orientation === "horizontal" || orientation === "vertical") sendBack({
|
|
716
|
-
type: "ORIENTATION_CHANGE",
|
|
717
|
-
orientation
|
|
718
|
-
});
|
|
719
|
-
},
|
|
720
|
-
onCapture: () => {
|
|
721
|
-
isCapturing = false;
|
|
722
|
-
if (bestCanvas) sendBack({
|
|
723
|
-
type: "DETECTION_SUCCESS",
|
|
724
|
-
canvas: bestCanvas,
|
|
725
|
-
qualityElements: storedQualityElements
|
|
726
|
-
});
|
|
727
|
-
else if (currentCanvas) sendBack({
|
|
728
|
-
type: "DETECTION_SUCCESS",
|
|
729
|
-
canvas: currentCanvas.clone(),
|
|
730
|
-
qualityElements: {}
|
|
731
|
-
});
|
|
732
|
-
},
|
|
733
|
-
onIdTypeChange: (idType$1) => {
|
|
734
|
-
sendBack({
|
|
735
|
-
type: "ID_TYPE_CHANGE",
|
|
736
|
-
idType: idType$1
|
|
737
|
-
});
|
|
738
|
-
},
|
|
739
|
-
onIdSideChange: (side) => {
|
|
740
|
-
if (isCapturing) return;
|
|
741
|
-
sendBack({
|
|
742
|
-
type: "ID_SIDE_CHANGE",
|
|
743
|
-
side
|
|
744
|
-
});
|
|
745
|
-
},
|
|
746
|
-
onCapturingCounterValueChange: (value) => {
|
|
747
|
-
sendBack({
|
|
748
|
-
type: "COUNTER_VALUE_CHANGE",
|
|
749
|
-
value
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
});
|
|
753
|
-
sendBack({
|
|
754
|
-
type: "DETECTION_UPDATE",
|
|
755
|
-
status: "detecting"
|
|
756
|
-
});
|
|
757
|
-
session = new StreamCanvasProcessingSession({
|
|
758
|
-
capturer: input.frameCapturer,
|
|
759
|
-
provider: {
|
|
760
|
-
processFrame: async (frame) => {
|
|
761
|
-
currentCanvas = IncodeCanvas.fromImageData(frame);
|
|
762
|
-
sendBack({
|
|
763
|
-
type: "DETECTION_FRAME",
|
|
764
|
-
frame
|
|
765
|
-
});
|
|
766
|
-
await provider.processFrame(frame);
|
|
767
|
-
},
|
|
768
|
-
reset: () => {
|
|
769
|
-
if (notificationTimeout) {
|
|
770
|
-
timer.clearTimeout(notificationTimeout);
|
|
771
|
-
notificationTimeout = null;
|
|
772
|
-
currentNotificationStatus = null;
|
|
773
|
-
}
|
|
774
|
-
currentCanvas = null;
|
|
775
|
-
bestCanvas = null;
|
|
776
|
-
storedQualityElements = {};
|
|
777
|
-
isCapturing = false;
|
|
778
|
-
provider.reset();
|
|
779
|
-
}
|
|
780
|
-
},
|
|
781
|
-
onFrame: (frame) => sendBack({
|
|
782
|
-
type: "DETECTION_FRAME",
|
|
783
|
-
frame
|
|
784
|
-
})
|
|
785
|
-
});
|
|
786
|
-
sendBack({
|
|
787
|
-
type: "DETECTION_RESET_READY",
|
|
788
|
-
reset: () => {
|
|
789
|
-
provider.reset();
|
|
790
|
-
}
|
|
791
|
-
});
|
|
792
|
-
return () => {
|
|
793
|
-
clearNotificationTimeout();
|
|
794
|
-
session?.dispose();
|
|
795
|
-
};
|
|
796
|
-
}),
|
|
797
|
-
uploadIdImage: fromPromise(async ({ input, signal }) => {
|
|
798
|
-
const image = input.canvas.getBase64Image();
|
|
799
|
-
if (!image) throw new Error(ID_ERROR_CODES.UPLOAD_ERROR);
|
|
800
|
-
return uploadIdImage({
|
|
801
|
-
image,
|
|
802
|
-
type: input.type,
|
|
803
|
-
sendBase64: true,
|
|
804
|
-
glare: input.qualityElements?.glare,
|
|
805
|
-
sharpness: input.qualityElements?.sharpness,
|
|
806
|
-
ageAssurance: false,
|
|
807
|
-
signal,
|
|
808
|
-
onProgress: input.onProgress
|
|
809
|
-
});
|
|
810
|
-
}),
|
|
811
|
-
processId: fromPromise(async ({ input, signal }) => {
|
|
812
|
-
return processId(input.isSecondId, "", signal);
|
|
813
|
-
}),
|
|
814
|
-
startRecording: fromPromise(async ({ input }) => {
|
|
815
|
-
if (!input.stream) return;
|
|
816
|
-
const type = input.currentMode === "back" ? "backId" : "frontId";
|
|
817
|
-
return startRecordingSession({
|
|
818
|
-
config: input.config,
|
|
819
|
-
stream: input.stream,
|
|
820
|
-
existing: input.existing,
|
|
821
|
-
type
|
|
822
|
-
});
|
|
823
|
-
}),
|
|
824
|
-
checkMotionSensor: fromCallback(({ input, sendBack }) => {
|
|
825
|
-
if (!input.motionProvider) {
|
|
826
|
-
sendBack({
|
|
827
|
-
type: "MOTION_STATUS",
|
|
828
|
-
status: "UNCLEAR"
|
|
829
|
-
});
|
|
830
|
-
return () => {};
|
|
831
|
-
}
|
|
832
|
-
const timer = BrowserTimerProvider.getInstance();
|
|
833
|
-
const interval = timer.setInterval(() => {
|
|
834
|
-
sendBack({
|
|
835
|
-
type: "MOTION_STATUS",
|
|
836
|
-
status: input.motionProvider.check()
|
|
837
|
-
});
|
|
838
|
-
}, 500);
|
|
839
|
-
return () => timer.clearInterval(interval);
|
|
840
|
-
})
|
|
841
|
-
},
|
|
842
|
-
actions: {
|
|
843
|
-
stopMediaStream: assign(({ context }) => {
|
|
844
|
-
context.frameCapturer?.dispose();
|
|
845
|
-
if (context.stream) stopStream(context.stream);
|
|
846
|
-
return {
|
|
847
|
-
stream: void 0,
|
|
848
|
-
frameCapturer: void 0
|
|
849
|
-
};
|
|
850
|
-
}),
|
|
851
|
-
disposeProvider: ({ context }) => {
|
|
852
|
-
context.provider?.dispose?.();
|
|
853
|
-
},
|
|
854
|
-
resetForBackCapture: assign(({ context }) => {
|
|
855
|
-
context.frameCapturer?.dispose();
|
|
856
|
-
if (context.stream) stopStream(context.stream);
|
|
857
|
-
context.provider?.reset();
|
|
858
|
-
return {
|
|
859
|
-
stream: void 0,
|
|
860
|
-
frameCapturer: void 0,
|
|
861
|
-
detectionStatus: "idle",
|
|
862
|
-
counterValue: 0,
|
|
863
|
-
orientation: void 0,
|
|
864
|
-
resetDetection: void 0,
|
|
865
|
-
idType: void 0,
|
|
866
|
-
qualityElements: void 0,
|
|
867
|
-
debugFrame: void 0,
|
|
868
|
-
frameRect: void 0,
|
|
869
|
-
previewImageUrl: void 0,
|
|
870
|
-
uploadProgress: void 0,
|
|
871
|
-
manualCaptureTriggered: false
|
|
872
|
-
};
|
|
873
|
-
}),
|
|
874
|
-
prepareForBackCapture: assign(({ context }) => {
|
|
875
|
-
context.provider?.reset();
|
|
876
|
-
return {
|
|
877
|
-
detectionStatus: "idle",
|
|
878
|
-
counterValue: 0,
|
|
879
|
-
orientation: void 0,
|
|
880
|
-
resetDetection: void 0,
|
|
881
|
-
idType: void 0,
|
|
882
|
-
qualityElements: void 0,
|
|
883
|
-
debugFrame: void 0,
|
|
884
|
-
frameRect: void 0,
|
|
885
|
-
previewImageUrl: void 0,
|
|
886
|
-
uploadProgress: void 0,
|
|
887
|
-
manualCaptureTriggered: false
|
|
888
|
-
};
|
|
889
|
-
}),
|
|
890
|
-
setStreamAndCapturer: assign({
|
|
891
|
-
stream: ({ event }) => {
|
|
892
|
-
if ("output" in event) return event.output.stream;
|
|
893
|
-
},
|
|
894
|
-
provider: ({ event }) => {
|
|
895
|
-
if ("output" in event) return event.output.provider;
|
|
896
|
-
},
|
|
897
|
-
frameCapturer: ({ event }) => {
|
|
898
|
-
if ("output" in event) {
|
|
899
|
-
const output = event.output;
|
|
900
|
-
if (output.stream) return new StreamCanvasCapture(output.stream);
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
}),
|
|
904
|
-
trackTutorialId: () => {
|
|
905
|
-
addEvent({
|
|
906
|
-
code: "tutorialVideoStarted",
|
|
907
|
-
module: eventModuleNames.id,
|
|
908
|
-
payload: { tutorialFrontID: true }
|
|
909
|
-
});
|
|
910
|
-
},
|
|
911
|
-
trackContinue: () => {},
|
|
912
|
-
resetContext: assign(({ context }) => {
|
|
913
|
-
context.provider?.reset();
|
|
914
|
-
return {
|
|
915
|
-
stream: void 0,
|
|
916
|
-
provider: context.provider,
|
|
917
|
-
frameCapturer: void 0,
|
|
918
|
-
error: void 0,
|
|
919
|
-
detectionStatus: "idle",
|
|
920
|
-
counterValue: 0,
|
|
921
|
-
orientation: void 0,
|
|
922
|
-
capturedImages: {},
|
|
923
|
-
uploadResponse: void 0,
|
|
924
|
-
recordingSession: void 0,
|
|
925
|
-
attemptsRemaining: context.config.captureAttempts,
|
|
926
|
-
uploadError: void 0,
|
|
927
|
-
permissionResult: void 0,
|
|
928
|
-
resetDetection: void 0,
|
|
929
|
-
idType: void 0,
|
|
930
|
-
qualityElements: void 0,
|
|
931
|
-
previewImageUrl: void 0,
|
|
932
|
-
uploadProgress: void 0,
|
|
933
|
-
currentMode: context.config.onlyBack ? "back" : !context.config.enableId && context.config.enablePassport ? "passport" : "front",
|
|
934
|
-
selectedDocumentType: void 0,
|
|
935
|
-
manualCaptureTriggered: false
|
|
936
|
-
};
|
|
937
|
-
}),
|
|
938
|
-
resetDetection: ({ context }) => {
|
|
939
|
-
context.resetDetection?.();
|
|
940
|
-
},
|
|
941
|
-
captureImage: assign({ qualityElements: ({ event }) => {
|
|
942
|
-
if ("qualityElements" in event) return event.qualityElements;
|
|
943
|
-
} }),
|
|
944
|
-
storeCapturedCanvasInProvider: ({ context, event }) => {
|
|
945
|
-
let canvas = null;
|
|
946
|
-
if ("canvas" in event && event.canvas) canvas = event.canvas;
|
|
947
|
-
else canvas = context.frameCapturer?.getLatestCanvas() ?? null;
|
|
948
|
-
if (!canvas || !context.provider) return;
|
|
949
|
-
const canvasWidth = canvas.width();
|
|
950
|
-
const canvasHeight = canvas.height();
|
|
951
|
-
if (!canvasWidth || !canvasHeight) return;
|
|
952
|
-
const originalCanvas = canvas;
|
|
953
|
-
let frameRect;
|
|
954
|
-
const { innerWidth: viewportWidth, innerHeight: viewportHeight } = getWindowDimensions();
|
|
955
|
-
if (context.detectionArea) {
|
|
956
|
-
const scaleX = viewportWidth / canvasWidth;
|
|
957
|
-
const scaleY = viewportHeight / canvasHeight;
|
|
958
|
-
const scale = Math.max(scaleX, scaleY);
|
|
959
|
-
const displayedWidth = canvasWidth * scale;
|
|
960
|
-
const displayedHeight = canvasHeight * scale;
|
|
961
|
-
const offsetX = (viewportWidth - displayedWidth) / 2;
|
|
962
|
-
const offsetY = (viewportHeight - displayedHeight) / 2;
|
|
963
|
-
frameRect = {
|
|
964
|
-
x: (context.detectionArea.x - offsetX) / scale,
|
|
965
|
-
y: (context.detectionArea.y - offsetY) / scale,
|
|
966
|
-
w: context.detectionArea.width / scale,
|
|
967
|
-
h: context.detectionArea.height / scale
|
|
968
|
-
};
|
|
969
|
-
} else if (context.frameRect) {
|
|
970
|
-
const scaleX = viewportWidth / canvasWidth;
|
|
971
|
-
const scaleY = viewportHeight / canvasHeight;
|
|
972
|
-
const scale = Math.max(scaleX, scaleY);
|
|
973
|
-
const displayedWidth = canvasWidth * scale;
|
|
974
|
-
const displayedHeight = canvasHeight * scale;
|
|
975
|
-
const offsetX = (viewportWidth - displayedWidth) / 2;
|
|
976
|
-
const offsetY = (viewportHeight - displayedHeight) / 2;
|
|
977
|
-
frameRect = {
|
|
978
|
-
x: (context.frameRect.x - offsetX) / scale,
|
|
979
|
-
y: (context.frameRect.y - offsetY) / scale,
|
|
980
|
-
w: context.frameRect.w / scale,
|
|
981
|
-
h: context.frameRect.h / scale
|
|
982
|
-
};
|
|
983
|
-
} else {
|
|
984
|
-
const quadValue = (context.provider.getLastProcessResult?.())?.quad;
|
|
985
|
-
const hasQuad = !!quadValue;
|
|
986
|
-
const quadSize = quadValue?.size ? quadValue.size() : quadValue?.length ?? 0;
|
|
987
|
-
if (hasQuad && quadSize >= 4 && quadValue.get) {
|
|
988
|
-
const p0 = quadValue.get(0);
|
|
989
|
-
const p1 = quadValue.get(1);
|
|
990
|
-
const p2 = quadValue.get(2);
|
|
991
|
-
const p3 = quadValue.get(3);
|
|
992
|
-
const minX = Math.min(p0.x, p1.x, p2.x, p3.x);
|
|
993
|
-
const maxX = Math.max(p0.x, p1.x, p2.x, p3.x);
|
|
994
|
-
const minY = Math.min(p0.y, p1.y, p2.y, p3.y);
|
|
995
|
-
const maxY = Math.max(p0.y, p1.y, p2.y, p3.y);
|
|
996
|
-
frameRect = {
|
|
997
|
-
x: minX,
|
|
998
|
-
y: minY,
|
|
999
|
-
w: maxX - minX,
|
|
1000
|
-
h: maxY - minY
|
|
1001
|
-
};
|
|
1002
|
-
} else {
|
|
1003
|
-
const frameViewportWidth = Math.min(387, viewportWidth * .9);
|
|
1004
|
-
const frameViewportHeight = frameViewportWidth / (35 / 22);
|
|
1005
|
-
const frameViewportX = (viewportWidth - frameViewportWidth) / 2;
|
|
1006
|
-
const frameViewportY = (viewportHeight - frameViewportHeight) / 2;
|
|
1007
|
-
frameRect = {
|
|
1008
|
-
x: canvasWidth * frameViewportX / viewportWidth,
|
|
1009
|
-
y: canvasHeight * frameViewportY / viewportHeight,
|
|
1010
|
-
w: canvasWidth * frameViewportWidth / viewportWidth,
|
|
1011
|
-
h: canvasHeight * frameViewportHeight / viewportHeight
|
|
1012
|
-
};
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
const transformedCanvas = context.provider.transformPerspective(originalCanvas, frameRect);
|
|
1016
|
-
context.provider.setCapturedCanvases(originalCanvas, transformedCanvas);
|
|
1017
|
-
},
|
|
1018
|
-
captureLatestFrame: ({ context }) => {
|
|
1019
|
-
context.frameCapturer?.getLatestCanvas();
|
|
1020
|
-
},
|
|
1021
|
-
clearUploadFailure: assign({
|
|
1022
|
-
uploadError: () => void 0,
|
|
1023
|
-
detectionStatus: () => "idle",
|
|
1024
|
-
previewImageUrl: ({ context }) => {
|
|
1025
|
-
if (context.previewImageUrl) revokeObjectURL(context.previewImageUrl);
|
|
1026
|
-
},
|
|
1027
|
-
uploadProgress: () => void 0
|
|
1028
|
-
}),
|
|
1029
|
-
decrementAttemptsRemaining: assign(({ context }) => ({ attemptsRemaining: context.attemptsRemaining - 1 })),
|
|
1030
|
-
setUploadErrorFromUploadValidation: assign({ uploadError: ({ context }) => {
|
|
1031
|
-
if (!context.uploadResponse) return ID_ERROR_CODES.SERVER;
|
|
1032
|
-
return validateUploadResponse(context.uploadResponse, {
|
|
1033
|
-
skipGlareFront: context.uploadResponse.skipGlareFront,
|
|
1034
|
-
skipGlareBack: context.uploadResponse.skipGlareBack
|
|
1035
|
-
})?.errorKey ?? ID_ERROR_CODES.SERVER;
|
|
1036
|
-
} }),
|
|
1037
|
-
stopMediaRecording: ({ context }) => {
|
|
1038
|
-
if (context.recordingSession) stopRecording(context.recordingSession);
|
|
1039
|
-
},
|
|
1040
|
-
clearRecordingSession: assign({ recordingSession: () => void 0 }),
|
|
1041
|
-
setSelectedDocument: assign({ selectedDocumentType: ({ event }) => {
|
|
1042
|
-
if ("documentType" in event) return event.documentType;
|
|
1043
|
-
} }),
|
|
1044
|
-
setCurrentMode: assign({ currentMode: ({ event, context }) => {
|
|
1045
|
-
if ("documentType" in event) {
|
|
1046
|
-
if (event.documentType === "passport") return "passport";
|
|
1047
|
-
return "front";
|
|
1048
|
-
}
|
|
1049
|
-
if (event.type === "FRONT_COMPLETE") return "back";
|
|
1050
|
-
return context.currentMode;
|
|
1051
|
-
} }),
|
|
1052
|
-
storeCapturedImage: assign({
|
|
1053
|
-
capturedImages: ({ context, event }) => {
|
|
1054
|
-
if (!context.currentMode) return context.capturedImages;
|
|
1055
|
-
const transformedImage = (context.provider?.getCapturedCanvas())?.getBase64Image(1, true);
|
|
1056
|
-
let fallbackImage = "";
|
|
1057
|
-
if ("output" in event) fallbackImage = event.output.originalImage ?? "";
|
|
1058
|
-
const imageData = { imageBase64: transformedImage ?? fallbackImage };
|
|
1059
|
-
if (context.currentMode === "front" || context.currentMode === "passport") return {
|
|
1060
|
-
...context.capturedImages,
|
|
1061
|
-
front: imageData
|
|
1062
|
-
};
|
|
1063
|
-
return {
|
|
1064
|
-
...context.capturedImages,
|
|
1065
|
-
back: imageData
|
|
1066
|
-
};
|
|
1067
|
-
},
|
|
1068
|
-
previewImageUrl: ({ context, event }) => {
|
|
1069
|
-
const transformedCanvas = context.provider?.getCapturedCanvas();
|
|
1070
|
-
if (transformedCanvas) {
|
|
1071
|
-
transformedCanvas.updateBlob();
|
|
1072
|
-
const blobData = transformedCanvas.getBlobData();
|
|
1073
|
-
if (blobData?.url) return blobData.url;
|
|
1074
|
-
}
|
|
1075
|
-
if ("canvas" in event && event.canvas) {
|
|
1076
|
-
const canvas = event.canvas;
|
|
1077
|
-
canvas.updateBlob();
|
|
1078
|
-
const blobData = canvas.getBlobData();
|
|
1079
|
-
if (blobData?.url) return blobData.url;
|
|
1080
|
-
}
|
|
1081
|
-
return context.previewImageUrl;
|
|
1082
|
-
}
|
|
1083
|
-
}),
|
|
1084
|
-
setDetectionStatus: assign({ detectionStatus: ({ event, context }) => {
|
|
1085
|
-
if (event.type === "DETECTION_UPDATE") {
|
|
1086
|
-
const newStatus = event.status;
|
|
1087
|
-
const currentStatus = context.detectionStatus;
|
|
1088
|
-
if ((newStatus === "blur" || newStatus === "glare") && (currentStatus === "wrongSide" || currentStatus === "farAway")) return currentStatus;
|
|
1089
|
-
if ((newStatus === "wrongSide" || newStatus === "farAway") && (currentStatus === "blur" || currentStatus === "glare")) return newStatus;
|
|
1090
|
-
return newStatus;
|
|
1091
|
-
}
|
|
1092
|
-
return "idle";
|
|
1093
|
-
} }),
|
|
1094
|
-
setCounterValue: assign({ counterValue: ({ event }) => {
|
|
1095
|
-
if ("value" in event) return event.value;
|
|
1096
|
-
return 0;
|
|
1097
|
-
} }),
|
|
1098
|
-
setIdType: assign({ idType: ({ event }) => {
|
|
1099
|
-
if ("idType" in event) return event.idType;
|
|
1100
|
-
} }),
|
|
1101
|
-
setOrientation: assign({ orientation: ({ event }) => {
|
|
1102
|
-
if ("orientation" in event) return event.orientation;
|
|
1103
|
-
} }),
|
|
1104
|
-
setFrameRect: assign({ frameRect: ({ event }) => {
|
|
1105
|
-
if ("frameRect" in event) return event.frameRect;
|
|
1106
|
-
} }),
|
|
1107
|
-
setDetectionArea: assign({ detectionArea: ({ event }) => {
|
|
1108
|
-
if ("detectionArea" in event) return event.detectionArea;
|
|
1109
|
-
} }),
|
|
1110
|
-
setMotionStatus: assign({ motionStatus: ({ event }) => {
|
|
1111
|
-
if ("status" in event && event.type === "MOTION_STATUS") return event.status;
|
|
1112
|
-
} })
|
|
1113
|
-
},
|
|
1114
|
-
guards: {
|
|
1115
|
-
hasShowTutorial: ({ context }) => context.config.showTutorial,
|
|
1116
|
-
hasShowDocumentChooser: ({ context }) => context.config.showDocumentChooserScreen ?? false,
|
|
1117
|
-
isPermissionGranted: ({ event }) => {
|
|
1118
|
-
if ("output" in event) return event.output === "granted";
|
|
1119
|
-
return false;
|
|
1120
|
-
},
|
|
1121
|
-
isPermissionDeniedError: ({ event }) => {
|
|
1122
|
-
if ("error" in event) {
|
|
1123
|
-
const error = event.error;
|
|
1124
|
-
return error?.name === "NotAllowedError" || error?.name === "PermissionDeniedError";
|
|
1125
|
-
}
|
|
1126
|
-
return false;
|
|
1127
|
-
},
|
|
1128
|
-
hasStream: ({ context }) => context.stream !== void 0,
|
|
1129
|
-
hasAttemptsRemaining: ({ context }) => context.attemptsRemaining > 0,
|
|
1130
|
-
hasCapturedImage: ({ context }) => {
|
|
1131
|
-
return context.provider?.getCapturedCanvas() !== null;
|
|
1132
|
-
},
|
|
1133
|
-
hasUploadValidationError: ({ context }) => {
|
|
1134
|
-
if (!context.uploadResponse) return false;
|
|
1135
|
-
return validateUploadResponse(context.uploadResponse, {
|
|
1136
|
-
skipGlareFront: context.uploadResponse.skipGlareFront,
|
|
1137
|
-
skipGlareBack: context.uploadResponse.skipGlareBack
|
|
1138
|
-
}) !== void 0;
|
|
1139
|
-
},
|
|
1140
|
-
isFrontMode: ({ context }) => context.currentMode === "front" || context.currentMode === "passport",
|
|
1141
|
-
isOnlyFront: ({ context }) => context.config.onlyFront,
|
|
1142
|
-
shouldContinueToBack: ({ context }) => {
|
|
1143
|
-
if (context.currentMode === "passport") return false;
|
|
1144
|
-
if (context.currentMode !== "front") return false;
|
|
1145
|
-
if (context.config.onlyFront) return false;
|
|
1146
|
-
if (context.config.onlyBack) return false;
|
|
1147
|
-
if (!context.config.enableId && context.config.enablePassport) return false;
|
|
1148
|
-
if (context.uploadResponse?.skipBackIdCapture) return false;
|
|
1149
|
-
return true;
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
}).createMachine({
|
|
1153
|
-
id: "idCapture",
|
|
1154
|
-
initial: "idle",
|
|
1155
|
-
context: ({ input }) => {
|
|
1156
|
-
const currentMode = input.config.onlyBack ? "back" : !input.config.enableId && input.config.enablePassport ? "passport" : "front";
|
|
1157
|
-
return {
|
|
1158
|
-
config: input.config,
|
|
1159
|
-
currentMode,
|
|
1160
|
-
selectedDocumentType: void 0,
|
|
1161
|
-
stream: void 0,
|
|
1162
|
-
provider: input.provider,
|
|
1163
|
-
frameCapturer: void 0,
|
|
1164
|
-
error: void 0,
|
|
1165
|
-
detectionStatus: "idle",
|
|
1166
|
-
counterValue: 0,
|
|
1167
|
-
orientation: void 0,
|
|
1168
|
-
capturedImages: {},
|
|
1169
|
-
uploadResponse: void 0,
|
|
1170
|
-
recordingSession: void 0,
|
|
1171
|
-
attemptsRemaining: input.config.captureAttempts,
|
|
1172
|
-
uploadError: void 0,
|
|
1173
|
-
permissionResult: void 0,
|
|
1174
|
-
resetDetection: void 0,
|
|
1175
|
-
idType: void 0,
|
|
1176
|
-
qualityElements: void 0,
|
|
1177
|
-
debugFrame: void 0,
|
|
1178
|
-
frameRect: void 0,
|
|
1179
|
-
detectionArea: void 0,
|
|
1180
|
-
previewImageUrl: void 0,
|
|
1181
|
-
uploadProgress: void 0,
|
|
1182
|
-
motionStatus: void 0,
|
|
1183
|
-
manualCaptureTriggered: false
|
|
1184
|
-
};
|
|
1185
|
-
},
|
|
1186
|
-
on: {
|
|
1187
|
-
QUIT: { target: "#idCapture.closed" },
|
|
1188
|
-
UPDATE_DETECTION_AREA: { actions: "setDetectionArea" }
|
|
1189
|
-
},
|
|
1190
|
-
states: {
|
|
1191
|
-
idle: { on: { LOAD: [
|
|
1192
|
-
{
|
|
1193
|
-
target: "chooser",
|
|
1194
|
-
guard: "hasShowDocumentChooser"
|
|
1195
|
-
},
|
|
1196
|
-
{
|
|
1197
|
-
target: "tutorial",
|
|
1198
|
-
guard: "hasShowTutorial"
|
|
1199
|
-
},
|
|
1200
|
-
{ target: "loading" }
|
|
1201
|
-
] } },
|
|
1202
|
-
chooser: { on: { SELECT_DOCUMENT: [{
|
|
1203
|
-
target: "tutorial",
|
|
1204
|
-
guard: "hasShowTutorial",
|
|
1205
|
-
actions: ["setSelectedDocument", "setCurrentMode"]
|
|
1206
|
-
}, {
|
|
1207
|
-
target: "loading",
|
|
1208
|
-
actions: ["setSelectedDocument", "setCurrentMode"]
|
|
1209
|
-
}] } },
|
|
1210
|
-
loading: { invoke: {
|
|
1211
|
-
id: "checkPermissionLoading",
|
|
1212
|
-
src: "checkPermission",
|
|
1213
|
-
onDone: [{
|
|
1214
|
-
target: "capture",
|
|
1215
|
-
guard: "isPermissionGranted",
|
|
1216
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
1217
|
-
}, {
|
|
1218
|
-
target: "permissions",
|
|
1219
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
1220
|
-
}],
|
|
1221
|
-
onError: {
|
|
1222
|
-
target: "permissions",
|
|
1223
|
-
actions: assign({ permissionResult: () => "prompt" })
|
|
1224
|
-
}
|
|
1225
|
-
} },
|
|
1226
|
-
tutorial: {
|
|
1227
|
-
initial: "checkingPermission",
|
|
1228
|
-
entry: "trackTutorialId",
|
|
1229
|
-
states: {
|
|
1230
|
-
checkingPermission: {
|
|
1231
|
-
invoke: {
|
|
1232
|
-
id: "checkPermissionTutorial",
|
|
1233
|
-
src: "checkPermission",
|
|
1234
|
-
onDone: [{
|
|
1235
|
-
target: "initializingCamera",
|
|
1236
|
-
guard: "isPermissionGranted",
|
|
1237
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
1238
|
-
}, {
|
|
1239
|
-
target: "ready",
|
|
1240
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
1241
|
-
}]
|
|
1242
|
-
},
|
|
1243
|
-
on: { NEXT_STEP: {
|
|
1244
|
-
target: "initializingCamera",
|
|
1245
|
-
actions: "trackContinue"
|
|
1246
|
-
} }
|
|
1247
|
-
},
|
|
1248
|
-
initializingCamera: {
|
|
1249
|
-
initial: "booting",
|
|
1250
|
-
invoke: {
|
|
1251
|
-
id: "tutorialInitCamera",
|
|
1252
|
-
src: "initializeCamera",
|
|
1253
|
-
input: ({ context }) => {
|
|
1254
|
-
if (!context.provider) throw new Error("Provider is required");
|
|
1255
|
-
return {
|
|
1256
|
-
provider: context.provider,
|
|
1257
|
-
config: context.config
|
|
1258
|
-
};
|
|
1259
|
-
},
|
|
1260
|
-
onDone: { actions: "setStreamAndCapturer" },
|
|
1261
|
-
onError: [{
|
|
1262
|
-
target: "ready",
|
|
1263
|
-
guard: "isPermissionDeniedError",
|
|
1264
|
-
actions: assign({ permissionResult: () => "denied" })
|
|
1265
|
-
}, {
|
|
1266
|
-
target: "ready",
|
|
1267
|
-
actions: assign({ error: ({ event }) => String(event.error) })
|
|
1268
|
-
}]
|
|
1269
|
-
},
|
|
1270
|
-
states: {
|
|
1271
|
-
booting: {
|
|
1272
|
-
always: [{
|
|
1273
|
-
target: "#tutorialCameraReady",
|
|
1274
|
-
guard: "hasStream"
|
|
1275
|
-
}],
|
|
1276
|
-
on: { NEXT_STEP: {
|
|
1277
|
-
target: "waitingForStream",
|
|
1278
|
-
actions: "trackContinue"
|
|
1279
|
-
} }
|
|
1280
|
-
},
|
|
1281
|
-
waitingForStream: { always: [{
|
|
1282
|
-
target: "#idCapture.capture",
|
|
1283
|
-
guard: "hasStream"
|
|
1284
|
-
}] }
|
|
1285
|
-
}
|
|
1286
|
-
},
|
|
1287
|
-
cameraReady: {
|
|
1288
|
-
id: "tutorialCameraReady",
|
|
1289
|
-
on: { NEXT_STEP: {
|
|
1290
|
-
target: "#idCapture.capture",
|
|
1291
|
-
actions: "trackContinue"
|
|
1292
|
-
} }
|
|
1293
|
-
},
|
|
1294
|
-
ready: { on: { NEXT_STEP: {
|
|
1295
|
-
target: "waitingForPermission",
|
|
1296
|
-
actions: "trackContinue"
|
|
1297
|
-
} } },
|
|
1298
|
-
waitingForPermission: { invoke: {
|
|
1299
|
-
id: "checkPermissionWaiting",
|
|
1300
|
-
src: "checkPermission",
|
|
1301
|
-
onDone: [{
|
|
1302
|
-
target: "#idCapture.capture",
|
|
1303
|
-
guard: "isPermissionGranted",
|
|
1304
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
1305
|
-
}, {
|
|
1306
|
-
target: "#idCapture.permissions",
|
|
1307
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
1308
|
-
}]
|
|
1309
|
-
} }
|
|
1310
|
-
}
|
|
1311
|
-
},
|
|
1312
|
-
permissions: {
|
|
1313
|
-
initial: "idle",
|
|
1314
|
-
states: {
|
|
1315
|
-
idle: {
|
|
1316
|
-
invoke: {
|
|
1317
|
-
id: "checkPermissionIdle",
|
|
1318
|
-
src: "checkPermission",
|
|
1319
|
-
onDone: [
|
|
1320
|
-
{
|
|
1321
|
-
target: "#idCapture.capture",
|
|
1322
|
-
guard: "isPermissionGranted",
|
|
1323
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
1324
|
-
},
|
|
1325
|
-
{
|
|
1326
|
-
target: "denied",
|
|
1327
|
-
guard: ({ event }) => event.output === "denied",
|
|
1328
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
1329
|
-
},
|
|
1330
|
-
{
|
|
1331
|
-
target: "waitingForUser",
|
|
1332
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
1333
|
-
}
|
|
1334
|
-
],
|
|
1335
|
-
onError: {
|
|
1336
|
-
target: "waitingForUser",
|
|
1337
|
-
actions: assign({ permissionResult: () => "prompt" })
|
|
1338
|
-
}
|
|
1339
|
-
},
|
|
1340
|
-
on: {
|
|
1341
|
-
REQUEST_PERMISSION: "requesting",
|
|
1342
|
-
GO_TO_LEARN_MORE: "learnMore"
|
|
1343
|
-
}
|
|
1344
|
-
},
|
|
1345
|
-
waitingForUser: { on: {
|
|
1346
|
-
REQUEST_PERMISSION: "requesting",
|
|
1347
|
-
GO_TO_LEARN_MORE: "learnMore"
|
|
1348
|
-
} },
|
|
1349
|
-
learnMore: { on: {
|
|
1350
|
-
BACK: "idle",
|
|
1351
|
-
REQUEST_PERMISSION: "requesting"
|
|
1352
|
-
} },
|
|
1353
|
-
requesting: { invoke: {
|
|
1354
|
-
id: "requestPermission",
|
|
1355
|
-
src: "requestPermission",
|
|
1356
|
-
onDone: [
|
|
1357
|
-
{
|
|
1358
|
-
target: "#idCapture.capture",
|
|
1359
|
-
guard: "isPermissionGranted",
|
|
1360
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
1361
|
-
},
|
|
1362
|
-
{
|
|
1363
|
-
target: "denied",
|
|
1364
|
-
guard: ({ event }) => event.output === "denied",
|
|
1365
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
1366
|
-
},
|
|
1367
|
-
{
|
|
1368
|
-
target: "idle",
|
|
1369
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
1370
|
-
}
|
|
1371
|
-
],
|
|
1372
|
-
onError: { target: "denied" }
|
|
1373
|
-
} },
|
|
1374
|
-
denied: { entry: assign({ permissionResult: () => "refresh" }) }
|
|
1375
|
-
}
|
|
1376
|
-
},
|
|
1377
|
-
capture: {
|
|
1378
|
-
initial: "checkingStream",
|
|
1379
|
-
exit: ["stopMediaRecording", "clearRecordingSession"],
|
|
1380
|
-
on: { SET_FRAME_RECT: { actions: "setFrameRect" } },
|
|
1381
|
-
states: {
|
|
1382
|
-
checkingStream: { always: [{
|
|
1383
|
-
target: "detecting",
|
|
1384
|
-
guard: "hasStream"
|
|
1385
|
-
}, { target: "initializing" }] },
|
|
1386
|
-
initializing: { invoke: {
|
|
1387
|
-
id: "initializeCamera",
|
|
1388
|
-
src: "initializeCamera",
|
|
1389
|
-
input: ({ context }) => {
|
|
1390
|
-
if (!context.provider) throw new Error("Provider is required");
|
|
1391
|
-
return {
|
|
1392
|
-
provider: context.provider,
|
|
1393
|
-
config: context.config
|
|
1394
|
-
};
|
|
1395
|
-
},
|
|
1396
|
-
onDone: {
|
|
1397
|
-
target: "detecting",
|
|
1398
|
-
actions: "setStreamAndCapturer"
|
|
1399
|
-
},
|
|
1400
|
-
onError: [{
|
|
1401
|
-
target: "#idCapture.permissions",
|
|
1402
|
-
guard: "isPermissionDeniedError",
|
|
1403
|
-
actions: assign({ permissionResult: () => "denied" })
|
|
1404
|
-
}, {
|
|
1405
|
-
target: "#idCapture.error",
|
|
1406
|
-
actions: assign({ error: ({ event }) => String(event.error) })
|
|
1407
|
-
}]
|
|
1408
|
-
} },
|
|
1409
|
-
detecting: {
|
|
1410
|
-
always: [{
|
|
1411
|
-
target: "manualCaptureWaiting",
|
|
1412
|
-
guard: ({ context }) => context.manualCaptureTriggered,
|
|
1413
|
-
actions: assign({ detectionStatus: () => "manualCapture" })
|
|
1414
|
-
}],
|
|
1415
|
-
entry: [assign({ detectionStatus: () => "detecting" })],
|
|
1416
|
-
invoke: [{
|
|
1417
|
-
id: "startRecording",
|
|
1418
|
-
src: "startRecording",
|
|
1419
|
-
input: ({ context }) => ({
|
|
1420
|
-
config: context.config,
|
|
1421
|
-
stream: context.stream,
|
|
1422
|
-
existing: context.recordingSession,
|
|
1423
|
-
currentMode: context.currentMode
|
|
1424
|
-
}),
|
|
1425
|
-
onDone: { actions: assign({ recordingSession: ({ context, event }) => {
|
|
1426
|
-
return event.output ?? context.recordingSession;
|
|
1427
|
-
} }) },
|
|
1428
|
-
onError: { actions: () => void 0 }
|
|
1429
|
-
}, {
|
|
1430
|
-
id: "runDetection",
|
|
1431
|
-
src: "runDetection",
|
|
1432
|
-
input: ({ context }) => ({
|
|
1433
|
-
frameCapturer: context.frameCapturer,
|
|
1434
|
-
provider: context.provider,
|
|
1435
|
-
config: context.config,
|
|
1436
|
-
currentMode: context.currentMode,
|
|
1437
|
-
detectionArea: context.detectionArea ?? context.config.detectionArea
|
|
1438
|
-
})
|
|
1439
|
-
}],
|
|
1440
|
-
on: {
|
|
1441
|
-
DETECTION_UPDATE: { actions: "setDetectionStatus" },
|
|
1442
|
-
DETECTION_FRAME: { actions: assign({ debugFrame: ({ event }) => event.frame }) },
|
|
1443
|
-
DETECTION_RESET_READY: { actions: assign({ resetDetection: ({ event }) => event.reset }) },
|
|
1444
|
-
DETECTION_SUCCESS: {
|
|
1445
|
-
target: "capturing",
|
|
1446
|
-
actions: assign({ qualityElements: ({ event }) => event.qualityElements })
|
|
1447
|
-
},
|
|
1448
|
-
MANUAL_CAPTURE: { target: "capturingManual" },
|
|
1449
|
-
SWITCH_TO_MANUAL_CAPTURE: {
|
|
1450
|
-
target: "manualCaptureWaiting",
|
|
1451
|
-
actions: assign({
|
|
1452
|
-
detectionStatus: () => "manualCapture",
|
|
1453
|
-
manualCaptureTriggered: () => true
|
|
1454
|
-
})
|
|
1455
|
-
},
|
|
1456
|
-
COUNTER_VALUE_CHANGE: { actions: "setCounterValue" },
|
|
1457
|
-
ID_TYPE_CHANGE: { actions: "setIdType" },
|
|
1458
|
-
ID_SIDE_CHANGE: { actions: assign({ detectionStatus: ({ event, context }) => {
|
|
1459
|
-
const detectedSide = event.side?.toLowerCase() || "";
|
|
1460
|
-
const currentMode = context.currentMode;
|
|
1461
|
-
if (detectedSide === "wrong") return "wrongSide";
|
|
1462
|
-
const isBackDetected = detectedSide.includes("back") && !detectedSide.includes("front");
|
|
1463
|
-
const isFrontDetected = detectedSide.includes("front") && !detectedSide.includes("back");
|
|
1464
|
-
if (currentMode === "front" && isBackDetected || currentMode === "back" && isFrontDetected) return "wrongSide";
|
|
1465
|
-
if (currentMode === "front" && isFrontDetected || currentMode === "back" && isBackDetected || currentMode === "passport") return "detecting";
|
|
1466
|
-
return "detecting";
|
|
1467
|
-
} }) },
|
|
1468
|
-
ORIENTATION_CHANGE: { actions: "setOrientation" }
|
|
1469
|
-
}
|
|
1470
|
-
},
|
|
1471
|
-
manualCaptureWaiting: { on: { MANUAL_CAPTURE: { target: "capturingManual" } } },
|
|
1472
|
-
capturing: {
|
|
1473
|
-
entry: [
|
|
1474
|
-
"captureImage",
|
|
1475
|
-
"storeCapturedCanvasInProvider",
|
|
1476
|
-
"storeCapturedImage"
|
|
1477
|
-
],
|
|
1478
|
-
always: [{
|
|
1479
|
-
target: "uploading",
|
|
1480
|
-
guard: "hasCapturedImage"
|
|
1481
|
-
}, {
|
|
1482
|
-
target: "uploadError",
|
|
1483
|
-
actions: assign(({ context }) => ({
|
|
1484
|
-
uploadError: ID_ERROR_CODES.UPLOAD_ERROR,
|
|
1485
|
-
attemptsRemaining: context.attemptsRemaining - 1
|
|
1486
|
-
}))
|
|
1487
|
-
}]
|
|
1488
|
-
},
|
|
1489
|
-
capturingManual: {
|
|
1490
|
-
entry: [
|
|
1491
|
-
"captureLatestFrame",
|
|
1492
|
-
"storeCapturedCanvasInProvider",
|
|
1493
|
-
"storeCapturedImage"
|
|
1494
|
-
],
|
|
1495
|
-
always: [{
|
|
1496
|
-
target: "uploading",
|
|
1497
|
-
guard: "hasCapturedImage"
|
|
1498
|
-
}, {
|
|
1499
|
-
target: "uploadError",
|
|
1500
|
-
actions: assign(({ context }) => ({
|
|
1501
|
-
uploadError: ID_ERROR_CODES.UPLOAD_ERROR,
|
|
1502
|
-
attemptsRemaining: context.attemptsRemaining - 1
|
|
1503
|
-
}))
|
|
1504
|
-
}]
|
|
1505
|
-
},
|
|
1506
|
-
uploading: {
|
|
1507
|
-
entry: assign({ uploadProgress: () => 0 }),
|
|
1508
|
-
invoke: {
|
|
1509
|
-
id: "uploadIdImage",
|
|
1510
|
-
src: "uploadIdImage",
|
|
1511
|
-
input: ({ context, self }) => {
|
|
1512
|
-
const canvas = context.provider?.getOriginalCapturedCanvas();
|
|
1513
|
-
if (!canvas) throw new Error(ID_ERROR_CODES.UPLOAD_ERROR);
|
|
1514
|
-
return {
|
|
1515
|
-
canvas,
|
|
1516
|
-
type: context.currentMode === "back" ? "back" : "front",
|
|
1517
|
-
qualityElements: context.qualityElements,
|
|
1518
|
-
onProgress: (progress) => {
|
|
1519
|
-
self.send({
|
|
1520
|
-
type: "UPLOAD_PROGRESS",
|
|
1521
|
-
progress
|
|
1522
|
-
});
|
|
1523
|
-
}
|
|
1524
|
-
};
|
|
1525
|
-
},
|
|
1526
|
-
onDone: {
|
|
1527
|
-
target: "validatingUpload",
|
|
1528
|
-
actions: [assign({
|
|
1529
|
-
uploadResponse: ({ event }) => event.output,
|
|
1530
|
-
uploadProgress: () => 100
|
|
1531
|
-
}), "storeCapturedImage"]
|
|
1532
|
-
},
|
|
1533
|
-
onError: {
|
|
1534
|
-
target: "uploadError",
|
|
1535
|
-
actions: assign(({ context, event }) => ({
|
|
1536
|
-
uploadError: getIdErrorCodeFromUnknown(event.error) ?? ID_ERROR_CODES.UPLOAD_ERROR,
|
|
1537
|
-
attemptsRemaining: context.attemptsRemaining - 1
|
|
1538
|
-
}))
|
|
1539
|
-
}
|
|
1540
|
-
},
|
|
1541
|
-
on: { UPLOAD_PROGRESS: { actions: assign({ uploadProgress: ({ event }) => event.progress }) } }
|
|
1542
|
-
},
|
|
1543
|
-
validatingUpload: { always: [{
|
|
1544
|
-
target: "uploadError",
|
|
1545
|
-
guard: "hasUploadValidationError",
|
|
1546
|
-
actions: ["setUploadErrorFromUploadValidation", "decrementAttemptsRemaining"]
|
|
1547
|
-
}, { target: "success" }] },
|
|
1548
|
-
uploadError: { on: { CONTINUE_FROM_ERROR: [
|
|
1549
|
-
{
|
|
1550
|
-
target: "detecting",
|
|
1551
|
-
guard: "hasAttemptsRemaining",
|
|
1552
|
-
actions: [
|
|
1553
|
-
"resetDetection",
|
|
1554
|
-
"clearUploadFailure",
|
|
1555
|
-
assign({ manualCaptureTriggered: () => false })
|
|
1556
|
-
]
|
|
1557
|
-
},
|
|
1558
|
-
{
|
|
1559
|
-
target: "#idCapture.frontFinished",
|
|
1560
|
-
guard: "shouldContinueToBack"
|
|
1561
|
-
},
|
|
1562
|
-
{ target: "#idCapture.finished" }
|
|
1563
|
-
] } },
|
|
1564
|
-
success: { on: { NEXT_STEP: [{
|
|
1565
|
-
target: "#idCapture.frontFinished",
|
|
1566
|
-
guard: "shouldContinueToBack"
|
|
1567
|
-
}, { target: "#idCapture.processing" }] } }
|
|
1568
|
-
}
|
|
1569
|
-
},
|
|
1570
|
-
frontFinished: {
|
|
1571
|
-
entry: ["stopMediaRecording", "prepareForBackCapture"],
|
|
1572
|
-
on: { CONTINUE_TO_BACK: {
|
|
1573
|
-
target: "capture",
|
|
1574
|
-
actions: assign({ currentMode: () => "back" })
|
|
1575
|
-
} }
|
|
1576
|
-
},
|
|
1577
|
-
processing: {
|
|
1578
|
-
entry: "stopMediaStream",
|
|
1579
|
-
invoke: {
|
|
1580
|
-
id: "processId",
|
|
1581
|
-
src: "processId",
|
|
1582
|
-
input: ({ context }) => ({ isSecondId: context.config.isSecondId ?? false }),
|
|
1583
|
-
onDone: [{
|
|
1584
|
-
target: "expired",
|
|
1585
|
-
guard: ({ event }) => event.output.isDocumentExpired
|
|
1586
|
-
}, { target: "finished" }],
|
|
1587
|
-
onError: { target: "finished" }
|
|
1588
|
-
}
|
|
1589
|
-
},
|
|
1590
|
-
expired: { on: { RETRY_CAPTURE: [
|
|
1591
|
-
{
|
|
1592
|
-
target: "chooser",
|
|
1593
|
-
guard: "hasShowDocumentChooser",
|
|
1594
|
-
actions: ["resetContext"]
|
|
1595
|
-
},
|
|
1596
|
-
{
|
|
1597
|
-
target: "tutorial",
|
|
1598
|
-
guard: "hasShowTutorial",
|
|
1599
|
-
actions: "resetContext"
|
|
1600
|
-
},
|
|
1601
|
-
{
|
|
1602
|
-
target: "loading",
|
|
1603
|
-
actions: "resetContext"
|
|
1604
|
-
}
|
|
1605
|
-
] } },
|
|
1606
|
-
finished: {
|
|
1607
|
-
entry: [
|
|
1608
|
-
"stopMediaRecording",
|
|
1609
|
-
"stopMediaStream",
|
|
1610
|
-
"disposeProvider"
|
|
1611
|
-
],
|
|
1612
|
-
type: "final"
|
|
1613
|
-
},
|
|
1614
|
-
closed: {
|
|
1615
|
-
entry: ["stopMediaStream", "disposeProvider"],
|
|
1616
|
-
type: "final"
|
|
1617
|
-
},
|
|
1618
|
-
error: {
|
|
1619
|
-
entry: ["stopMediaStream", "disposeProvider"],
|
|
1620
|
-
on: { RESET: {
|
|
1621
|
-
target: "idle",
|
|
1622
|
-
actions: "resetContext"
|
|
1623
|
-
} }
|
|
1624
|
-
},
|
|
1625
|
-
manualIdUpload: { on: { QUIT: { target: "closed" } } },
|
|
1626
|
-
digitalIdUpload: { on: { QUIT: { target: "closed" } } }
|
|
1627
|
-
}
|
|
1628
|
-
});
|
|
1629
|
-
const idCaptureMachine = _idCaptureMachine;
|
|
1630
|
-
|
|
1631
|
-
//#endregion
|
|
1632
|
-
//#region src/modules/id/idCaptureActor.ts
|
|
1633
|
-
function createIdCaptureActor(options) {
|
|
1634
|
-
return createActor(idCaptureMachine, { input: {
|
|
1635
|
-
config: options.config,
|
|
1636
|
-
provider: options.provider
|
|
1637
|
-
} }).start();
|
|
1638
|
-
}
|
|
1639
|
-
|
|
1640
|
-
//#endregion
|
|
1641
|
-
//#region src/modules/id/idCaptureManager.ts
|
|
1642
|
-
function getPermissionStatus(snapshot) {
|
|
1643
|
-
if (!snapshot.matches("permissions")) return;
|
|
1644
|
-
if (snapshot.matches({ permissions: "idle" })) return "idle";
|
|
1645
|
-
if (snapshot.matches({ permissions: "waitingForUser" })) return "idle";
|
|
1646
|
-
if (snapshot.matches({ permissions: "learnMore" })) return "learnMore";
|
|
1647
|
-
if (snapshot.matches({ permissions: "requesting" })) return "requesting";
|
|
1648
|
-
if (snapshot.matches({ permissions: "denied" })) return "denied";
|
|
1649
|
-
}
|
|
1650
|
-
function getCaptureStatus(snapshot) {
|
|
1651
|
-
const matches = {
|
|
1652
|
-
initializing: snapshot.matches({ capture: "initializing" }),
|
|
1653
|
-
detecting: snapshot.matches({ capture: "detecting" }),
|
|
1654
|
-
manualCaptureWaiting: snapshot.matches({ capture: "manualCaptureWaiting" }),
|
|
1655
|
-
capturing: snapshot.matches({ capture: "capturing" }),
|
|
1656
|
-
capturingManual: snapshot.matches({ capture: "capturingManual" }),
|
|
1657
|
-
uploading: snapshot.matches({ capture: "uploading" }),
|
|
1658
|
-
uploadError: snapshot.matches({ capture: "uploadError" }),
|
|
1659
|
-
success: snapshot.matches({ capture: "success" })
|
|
1660
|
-
};
|
|
1661
|
-
if (matches.initializing) return "initializing";
|
|
1662
|
-
if (matches.detecting || matches.manualCaptureWaiting) return "detecting";
|
|
1663
|
-
if (matches.capturing || matches.capturingManual) return "capturing";
|
|
1664
|
-
if (matches.uploading) return "uploading";
|
|
1665
|
-
if (matches.uploadError) return "uploadError";
|
|
1666
|
-
if (matches.success) return "success";
|
|
1667
|
-
}
|
|
1668
|
-
function getErrorMessage(errorCode) {
|
|
1669
|
-
if (!errorCode) return void 0;
|
|
1670
|
-
return {
|
|
1671
|
-
UPLOAD_ERROR: "Upload failed",
|
|
1672
|
-
CLASSIFICATION_FAILED: "ID classification failed",
|
|
1673
|
-
LOW_SHARPNESS: "Image is not sharp enough",
|
|
1674
|
-
GLARE_DETECTED: "Glare detected on ID",
|
|
1675
|
-
WRONG_DOCUMENT_SIDE: "Wrong side of document",
|
|
1676
|
-
ID_TYPE_UNACCEPTABLE: "ID type is not acceptable",
|
|
1677
|
-
READABILITY_ISSUE: "ID readability issue",
|
|
1678
|
-
RETRY_EXHAUSTED_CONTINUE_TO_BACK: "Retry exhausted",
|
|
1679
|
-
RETRY_EXHAUSTED_SKIP_BACK: "Retry exhausted",
|
|
1680
|
-
NO_MORE_TRIES: "No more tries remaining",
|
|
1681
|
-
UNEXPECTED_ERROR: "An unexpected error occurred",
|
|
1682
|
-
NO_TOKEN: "No token available",
|
|
1683
|
-
PERMISSION_DENIED: "Permission denied",
|
|
1684
|
-
USER_CANCELLED: "User cancelled",
|
|
1685
|
-
SERVER_ERROR: "Server error"
|
|
1686
|
-
}[errorCode];
|
|
1687
|
-
}
|
|
1688
|
-
function getErrorDescription(errorCode, uploadResponse) {
|
|
1689
|
-
if (!errorCode) return void 0;
|
|
1690
|
-
return {
|
|
1691
|
-
UPLOAD_ERROR: "Please try again",
|
|
1692
|
-
CLASSIFICATION_FAILED: "Please ensure your ID is clearly visible",
|
|
1693
|
-
LOW_SHARPNESS: "Please ensure the image is clear and well-focused",
|
|
1694
|
-
GLARE_DETECTED: "Please avoid bright reflections on your ID",
|
|
1695
|
-
WRONG_DOCUMENT_SIDE: uploadResponse?.side === "back" ? "Please show the back side of your ID" : "Please show the front side of your ID",
|
|
1696
|
-
ID_TYPE_UNACCEPTABLE: "Please use a valid ID type",
|
|
1697
|
-
READABILITY_ISSUE: "Please ensure all text is clearly visible",
|
|
1698
|
-
RETRY_EXHAUSTED_CONTINUE_TO_BACK: "Continuing to back side capture",
|
|
1699
|
-
RETRY_EXHAUSTED_SKIP_BACK: "Skipping back side capture",
|
|
1700
|
-
NO_MORE_TRIES: "Maximum attempts reached",
|
|
1701
|
-
UNEXPECTED_ERROR: "Please try again later",
|
|
1702
|
-
NO_TOKEN: "Session expired",
|
|
1703
|
-
PERMISSION_DENIED: "Camera permission is required",
|
|
1704
|
-
USER_CANCELLED: "Capture was cancelled",
|
|
1705
|
-
SERVER_ERROR: "Please try again later"
|
|
1706
|
-
}[errorCode];
|
|
1707
|
-
}
|
|
1708
|
-
function mapState(snapshot) {
|
|
1709
|
-
const { context } = snapshot;
|
|
1710
|
-
if (snapshot.matches("idle")) return { status: "idle" };
|
|
1711
|
-
if (snapshot.matches("chooser")) return { status: "chooser" };
|
|
1712
|
-
if (snapshot.matches("loading")) return { status: "loading" };
|
|
1713
|
-
if (snapshot.matches("tutorial")) return {
|
|
1714
|
-
status: "tutorial",
|
|
1715
|
-
selectedDocumentType: context.selectedDocumentType
|
|
1716
|
-
};
|
|
1717
|
-
if (snapshot.matches("closed")) return { status: "closed" };
|
|
1718
|
-
if (snapshot.matches("permissions")) {
|
|
1719
|
-
const permissionStatus = getPermissionStatus(snapshot);
|
|
1720
|
-
if (permissionStatus === void 0) return {
|
|
1721
|
-
status: "permissions",
|
|
1722
|
-
permissionStatus: "idle"
|
|
1723
|
-
};
|
|
1724
|
-
return {
|
|
1725
|
-
status: "permissions",
|
|
1726
|
-
permissionStatus
|
|
1727
|
-
};
|
|
1728
|
-
}
|
|
1729
|
-
if (snapshot.matches("capture")) {
|
|
1730
|
-
const captureStatus = getCaptureStatus(snapshot);
|
|
1731
|
-
const needsBackCapture = context.currentMode === "front" && !context.config.onlyFront && !context.config.onlyBack;
|
|
1732
|
-
return {
|
|
1733
|
-
status: "capture",
|
|
1734
|
-
captureStatus: captureStatus ?? "initializing",
|
|
1735
|
-
stream: context.stream,
|
|
1736
|
-
detectionStatus: context.detectionStatus,
|
|
1737
|
-
debugFrame: void 0,
|
|
1738
|
-
attemptsRemaining: context.attemptsRemaining,
|
|
1739
|
-
uploadError: context.uploadError,
|
|
1740
|
-
currentMode: context.currentMode,
|
|
1741
|
-
counterValue: context.counterValue,
|
|
1742
|
-
orientation: context.orientation,
|
|
1743
|
-
idType: context.idType,
|
|
1744
|
-
previewImageUrl: context.previewImageUrl,
|
|
1745
|
-
uploadProgress: context.uploadProgress ?? 0,
|
|
1746
|
-
uploadErrorMessage: context.uploadError ? getErrorMessage(context.uploadError) : void 0,
|
|
1747
|
-
uploadErrorDescription: context.uploadError ? getErrorDescription(context.uploadError, context.uploadResponse) : void 0,
|
|
1748
|
-
needsBackCapture,
|
|
1749
|
-
showCaptureButtonInAuto: context.config.showCaptureButtonInAuto ?? false,
|
|
1750
|
-
canRetry: context.attemptsRemaining > 0
|
|
1751
|
-
};
|
|
1752
|
-
}
|
|
1753
|
-
if (snapshot.matches("frontFinished")) return { status: "frontFinished" };
|
|
1754
|
-
if (snapshot.matches("processing")) return { status: "processing" };
|
|
1755
|
-
if (snapshot.matches("expired")) return { status: "expired" };
|
|
1756
|
-
if (snapshot.matches("finished")) return { status: "finished" };
|
|
1757
|
-
if (snapshot.matches("error")) return {
|
|
1758
|
-
status: "error",
|
|
1759
|
-
error: context.error ?? "Unknown error"
|
|
1760
|
-
};
|
|
1761
|
-
return { status: "idle" };
|
|
1762
|
-
}
|
|
1763
|
-
function createApi({ actor }) {
|
|
1764
|
-
return {
|
|
1765
|
-
load() {
|
|
1766
|
-
actor.send({ type: "LOAD" });
|
|
1767
|
-
},
|
|
1768
|
-
selectDocument(documentType) {
|
|
1769
|
-
actor.send({
|
|
1770
|
-
type: "SELECT_DOCUMENT",
|
|
1771
|
-
documentType
|
|
1772
|
-
});
|
|
1773
|
-
},
|
|
1774
|
-
nextStep() {
|
|
1775
|
-
actor.send({ type: "NEXT_STEP" });
|
|
1776
|
-
},
|
|
1777
|
-
requestPermission() {
|
|
1778
|
-
actor.send({ type: "REQUEST_PERMISSION" });
|
|
1779
|
-
},
|
|
1780
|
-
goToLearnMore() {
|
|
1781
|
-
actor.send({ type: "GO_TO_LEARN_MORE" });
|
|
1782
|
-
},
|
|
1783
|
-
back() {
|
|
1784
|
-
actor.send({ type: "BACK" });
|
|
1785
|
-
},
|
|
1786
|
-
close() {
|
|
1787
|
-
actor.send({ type: "QUIT" });
|
|
1788
|
-
},
|
|
1789
|
-
reset() {
|
|
1790
|
-
actor.send({ type: "RESET" });
|
|
1791
|
-
},
|
|
1792
|
-
retryCapture() {
|
|
1793
|
-
actor.send({ type: "RETRY_CAPTURE" });
|
|
1794
|
-
},
|
|
1795
|
-
continueFromError() {
|
|
1796
|
-
actor.send({ type: "CONTINUE_FROM_ERROR" });
|
|
1797
|
-
},
|
|
1798
|
-
capture() {
|
|
1799
|
-
actor.send({ type: "MANUAL_CAPTURE" });
|
|
1800
|
-
},
|
|
1801
|
-
switchToManualCapture() {
|
|
1802
|
-
actor.send({ type: "SWITCH_TO_MANUAL_CAPTURE" });
|
|
1803
|
-
},
|
|
1804
|
-
continueToBack() {
|
|
1805
|
-
actor.send({ type: "CONTINUE_TO_BACK" });
|
|
1806
|
-
},
|
|
1807
|
-
skipBack() {
|
|
1808
|
-
actor.send({ type: "SKIP_BACK" });
|
|
1809
|
-
},
|
|
1810
|
-
updateDetectionArea(detectionArea) {
|
|
1811
|
-
actor.send({
|
|
1812
|
-
type: "UPDATE_DETECTION_AREA",
|
|
1813
|
-
detectionArea
|
|
1814
|
-
});
|
|
1815
|
-
}
|
|
1816
|
-
};
|
|
1817
|
-
}
|
|
1818
|
-
function createIdCaptureManager(options) {
|
|
1819
|
-
return createManager({
|
|
1820
|
-
actor: createIdCaptureActor(options),
|
|
1821
|
-
mapState,
|
|
1822
|
-
createApi
|
|
1823
|
-
});
|
|
1824
|
-
}
|
|
1825
|
-
|
|
1826
|
-
//#endregion
|
|
1827
|
-
export { processId as a, stopStream as c, ID_ERROR_CODES as d, initializeIdCapture as i, uploadIdImage as l, createIdCaptureActor as n, startRecordingSession as o, idCaptureMachine as r, stopRecording as s, createIdCaptureManager as t, validateUploadResponse as u };
|