@incodetech/core 0.0.0-dev-20260207-ef0d08c → 0.0.0-dev-20260209-168e887
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/Actor-uC1hxvGo.d.ts +2 -0
- package/dist/{OpenViduLogger-DrE4_cHh.esm.js → OpenViduLogger-Cut9zn-U.esm.js} +1 -1
- package/dist/OpenViduLogger-D_YCgaLD.esm.js +3 -0
- package/dist/authentication.d.ts +75 -0
- package/dist/authentication.esm.js +194 -0
- package/dist/{deepsightLoader-CHzDt5p2.esm.js → deepsightLoader-DHzfMqHS.esm.js} +4 -4
- package/dist/{deepsightService-D8qaikEi.d.ts → deepsightService-D9Isk8fg.d.ts} +4 -134
- package/dist/{deepsightService-C_AyxXhJ.esm.js → deepsightService-DLabZ49g.esm.js} +3 -3
- package/dist/email.d.ts +1 -1
- package/dist/email.esm.js +4 -4
- package/dist/{endpoints-Q2cBwc8v.esm.js → endpoints-CJtl25ka.esm.js} +1 -0
- package/dist/{events-BN5bIhsN.esm.js → events-CieIKgPk.esm.js} +3 -2
- package/dist/face-match.d.ts +1 -1
- package/dist/face-match.esm.js +4 -4
- package/dist/faceCaptureManagerFactory-CZgmP4pc.d.ts +227 -0
- package/dist/faceCaptureSetup-DRbBF7AJ.esm.js +1202 -0
- package/dist/flow.d.ts +2 -2
- package/dist/flow.esm.js +3 -3
- package/dist/{id-B6VREnGU.esm.js → id-2r4nZyH_.esm.js} +8 -8
- package/dist/id.d.ts +6 -4
- package/dist/id.esm.js +8 -8
- package/dist/{index-BOpNqAs7.d.ts → index-C0SJR9cc.d.ts} +5 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.esm.js +8 -8
- package/dist/{lib-ieMlAKG1.esm.js → lib-BbiUxUyg.esm.js} +2 -2
- package/dist/phone.d.ts +1 -1
- package/dist/phone.esm.js +4 -4
- package/dist/selfie.d.ts +38 -224
- package/dist/selfie.esm.js +22 -1145
- package/dist/{src-B0UBQ8zw.esm.js → src-BFHUdMI6.esm.js} +3 -3
- package/dist/{stats-CpcCA-Ml.esm.js → stats-DuS7aVaJ.esm.js} +1 -1
- package/dist/stats.esm.js +2 -2
- package/dist/{streamingEvents-DhMoimL8.esm.js → streamingEvents-DM6KFfsz.esm.js} +3 -3
- package/dist/types-u31qr1MR.d.ts +133 -0
- package/package.json +5 -1
- package/dist/OpenViduLogger-B6-UWyJe.esm.js +0 -3
- /package/dist/{Manager-CWwvSZqZ.d.ts → Manager-BiAYYF50.d.ts} +0 -0
- /package/dist/{api-BkkE6cfa.esm.js → api-Cqrn4bGi.esm.js} +0 -0
- /package/dist/{chunk-CiY78uGR.esm.js → chunk-CbPq_V01.esm.js} +0 -0
- /package/dist/{types-BHcijCvX.d.ts → types-Dc1nBvy2.d.ts} +0 -0
package/dist/selfie.esm.js
CHANGED
|
@@ -1,53 +1,14 @@
|
|
|
1
|
-
import { d as addEvent, n as eventModuleNames } from "./events-
|
|
2
|
-
import {
|
|
3
|
-
import { a as fromPromise,
|
|
4
|
-
import
|
|
5
|
-
import "./deepsightService-
|
|
6
|
-
import
|
|
7
|
-
import
|
|
1
|
+
import { d as addEvent, n as eventModuleNames } from "./events-CieIKgPk.esm.js";
|
|
2
|
+
import { m as BrowserStorageProvider, r as WasmUtilProvider } from "./src-BFHUdMI6.esm.js";
|
|
3
|
+
import { a as fromPromise, o as createActor, r as assign } from "./endpoints-CJtl25ka.esm.js";
|
|
4
|
+
import "./streamingEvents-DM6KFfsz.esm.js";
|
|
5
|
+
import "./deepsightService-DLabZ49g.esm.js";
|
|
6
|
+
import "./api-Cqrn4bGi.esm.js";
|
|
7
|
+
import "./stats-DuS7aVaJ.esm.js";
|
|
8
|
+
import { a as FACE_ERROR_CODES, i as uploadSelfie, n as faceCaptureMachine, o as createFaceCaptureManager, r as processFace, t as FACE_CAPTURE_EVENT_CODES } from "./faceCaptureSetup-DRbBF7AJ.esm.js";
|
|
8
9
|
|
|
9
|
-
//#region src/modules/selfie/types.ts
|
|
10
|
-
const FACE_ERROR_CODES = {
|
|
11
|
-
FACE_OCCLUDED: "FACE_OCCLUDED",
|
|
12
|
-
LIVENESS: "LIVENESS_ERROR",
|
|
13
|
-
BRIGHTNESS: "BRIGHTNESS_ERROR",
|
|
14
|
-
LENSES: "LENSES_ERROR",
|
|
15
|
-
MASK: "MASK_ERROR",
|
|
16
|
-
CLOSED_EYES: "CLOSED_EYES_ERROR",
|
|
17
|
-
HEAD_COVER: "HEAD_COVER_ERROR",
|
|
18
|
-
SERVER: "SERVER_ERROR",
|
|
19
|
-
FACE_NOT_FOUND: "FACE_NOT_FOUND",
|
|
20
|
-
MULTIPLE_FACES: "MULTIPLE_FACES",
|
|
21
|
-
TOO_BLURRY: "TOO_BLURRY_ERROR",
|
|
22
|
-
TOO_DARK: "TOO_DARK_ERROR",
|
|
23
|
-
USER_IS_NOT_RECOGNIZED: "USER_IS_NOT_RECOGNIZED",
|
|
24
|
-
SPOOF_ATTEMPT_DETECTED: "SPOOF_ATTEMPT_DETECTED",
|
|
25
|
-
FACE_TOO_DARK: "FACE_TOO_DARK",
|
|
26
|
-
LENSES_DETECTED: "LENSES_DETECTED",
|
|
27
|
-
FACE_MASK_DETECTED: "FACE_MASK_DETECTED",
|
|
28
|
-
CLOSED_EYES_DETECTED: "CLOSED_EYES_DETECTED",
|
|
29
|
-
HEAD_COVER_DETECTED: "HEAD_COVER_DETECTED",
|
|
30
|
-
FACE_CROPPING_FAILED: "FACE_CROPPING_FAILED",
|
|
31
|
-
FACE_TOO_SMALL: "FACE_TOO_SMALL",
|
|
32
|
-
FACE_TOO_BLURRY: "FACE_TOO_BLURRY",
|
|
33
|
-
BAD_PHOTO_QUALITY: "BAD_PHOTO_QUALITY",
|
|
34
|
-
PROCESSING_ERROR: "PROCESSING_ERROR",
|
|
35
|
-
BAD_REQUEST: "BAD_REQUEST",
|
|
36
|
-
NONEXISTENT_CUSTOMER: "NONEXISTENT_CUSTOMER",
|
|
37
|
-
HINT_NOT_PROVIDED: "HINT_NOT_PROVIDED",
|
|
38
|
-
SELFIE_IMAGE_LOW_QUALITY: "SELFIE_IMAGE_LOW_QUALITY"
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
//#endregion
|
|
42
10
|
//#region src/modules/selfie/selfieErrorUtils.ts
|
|
43
11
|
const FACE_ERROR_CODE_VALUES = Object.values(FACE_ERROR_CODES);
|
|
44
|
-
const isFaceErrorCode = (value) => {
|
|
45
|
-
return FACE_ERROR_CODE_VALUES.includes(value);
|
|
46
|
-
};
|
|
47
|
-
const getFaceErrorCodeFromUnknown = (value) => {
|
|
48
|
-
if (value instanceof Error && typeof value.message === "string") return isFaceErrorCode(value.message) ? value.message : void 0;
|
|
49
|
-
if (typeof value === "string") return isFaceErrorCode(value) ? value : void 0;
|
|
50
|
-
};
|
|
51
12
|
const validateUploadResponse = ({ config, response }) => {
|
|
52
13
|
if (!response) return FACE_ERROR_CODES.SERVER;
|
|
53
14
|
if (response.confidence !== 0) return FACE_ERROR_CODES.LIVENESS;
|
|
@@ -58,487 +19,17 @@ const validateUploadResponse = ({ config, response }) => {
|
|
|
58
19
|
if (config.validateHeadCover && response.hasHeadCover) return FACE_ERROR_CODES.HEAD_COVER;
|
|
59
20
|
};
|
|
60
21
|
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/modules/selfie/selfieUploadService.ts
|
|
63
|
-
/**
|
|
64
|
-
* Uploads a selfie image to the backend.
|
|
65
|
-
*/
|
|
66
|
-
async function uploadSelfie({ encryptedBase64Image, faceCoordinates, signal, metadata, recordingId }) {
|
|
67
|
-
try {
|
|
68
|
-
const payload = {
|
|
69
|
-
base64Image: encryptedBase64Image,
|
|
70
|
-
faceCoordinates: faceCoordinates ?? void 0,
|
|
71
|
-
encrypted: true,
|
|
72
|
-
clientInfo: { deviceClass: getDeviceClass() },
|
|
73
|
-
metadata: metadata ?? void 0
|
|
74
|
-
};
|
|
75
|
-
const query = { imageType: "selfie" };
|
|
76
|
-
if (recordingId) query.recordingId = recordingId;
|
|
77
|
-
const res = await api.post(endpoints.selfie, payload, {
|
|
78
|
-
signal,
|
|
79
|
-
query
|
|
80
|
-
});
|
|
81
|
-
if (!res.ok) throw new Error(`POST ${endpoints.selfie} failed: ${res.status} ${res.statusText}`);
|
|
82
|
-
return res.data;
|
|
83
|
-
} catch (error) {
|
|
84
|
-
const errorCode = getFaceErrorCodeFromHttpError(error);
|
|
85
|
-
if (errorCode) throw new Error(errorCode);
|
|
86
|
-
throw new Error(FACE_ERROR_CODES.SERVER);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const getFaceErrorCodeFromHttpError = (error) => {
|
|
90
|
-
const err = error;
|
|
91
|
-
if (err.ok !== false || typeof err.status !== "number") return;
|
|
92
|
-
if (err.status !== 400) return FACE_ERROR_CODES.SERVER;
|
|
93
|
-
if (typeof err.data?.status !== "number") return FACE_ERROR_CODES.BAD_REQUEST;
|
|
94
|
-
return {
|
|
95
|
-
3004: FACE_ERROR_CODES.FACE_NOT_FOUND,
|
|
96
|
-
3005: FACE_ERROR_CODES.FACE_NOT_FOUND,
|
|
97
|
-
3006: FACE_ERROR_CODES.TOO_BLURRY,
|
|
98
|
-
3007: FACE_ERROR_CODES.TOO_DARK,
|
|
99
|
-
4010: FACE_ERROR_CODES.MULTIPLE_FACES,
|
|
100
|
-
4019: FACE_ERROR_CODES.FACE_NOT_FOUND,
|
|
101
|
-
4077: FACE_ERROR_CODES.BAD_PHOTO_QUALITY,
|
|
102
|
-
4078: FACE_ERROR_CODES.FACE_OCCLUDED
|
|
103
|
-
}[err.data.status] ?? FACE_ERROR_CODES.BAD_REQUEST;
|
|
104
|
-
};
|
|
105
|
-
async function processFace(imageType = "selfie", signal) {
|
|
106
|
-
return (await api.post(endpoints.processFace, {}, {
|
|
107
|
-
query: { imageType },
|
|
108
|
-
signal
|
|
109
|
-
})).data;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region src/modules/selfie/selfieServices.ts
|
|
114
|
-
function sendLabelInspectionEvent() {
|
|
115
|
-
return addDeviceStats({ cameraLabelInspectionStatus: "FAIL" });
|
|
116
|
-
}
|
|
117
|
-
const CAMERA_CONSTRAINTS = {
|
|
118
|
-
video: {
|
|
119
|
-
facingMode: "user",
|
|
120
|
-
height: { ideal: 480 },
|
|
121
|
-
width: { ideal: 640 }
|
|
122
|
-
},
|
|
123
|
-
audio: false
|
|
124
|
-
};
|
|
125
|
-
function stopStream(stream) {
|
|
126
|
-
stopCameraStream(stream);
|
|
127
|
-
}
|
|
128
|
-
async function initializeCamera(params) {
|
|
129
|
-
const { config } = params;
|
|
130
|
-
const provider = new FaceDetectionProvider();
|
|
131
|
-
await provider.initialize({ autocaptureInterval: config.autoCaptureTimeout * 1e3 });
|
|
132
|
-
provider.setChecksEnabled({
|
|
133
|
-
lenses: config.validateLenses,
|
|
134
|
-
mask: config.validateFaceMask,
|
|
135
|
-
closedEyes: config.validateClosedEyes,
|
|
136
|
-
headWear: config.validateHeadCover,
|
|
137
|
-
occlusion: false
|
|
138
|
-
});
|
|
139
|
-
console.log("performPrcCheck init");
|
|
140
|
-
const timerName = `performPrcCheck ${Math.random()}`;
|
|
141
|
-
console.time(timerName);
|
|
142
|
-
await params.deepsightService.performPrcCheck({ constraints: { video: CAMERA_CONSTRAINTS.video } });
|
|
143
|
-
console.timeEnd(timerName);
|
|
144
|
-
console.log("performPrcCheck end");
|
|
145
|
-
return {
|
|
146
|
-
stream: await requestCameraAccess({
|
|
147
|
-
video: CAMERA_CONSTRAINTS.video,
|
|
148
|
-
audio: false
|
|
149
|
-
}),
|
|
150
|
-
provider
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Encrypts the provided selfie image using WASM.
|
|
155
|
-
*/
|
|
156
|
-
async function encryptSelfieImage({ canvas, dependencies }) {
|
|
157
|
-
const base64Image = canvas.getBase64Image();
|
|
158
|
-
if (!base64Image) throw new Error("Canvas image is empty or null");
|
|
159
|
-
return (await dependencies.getWasmUtil()).encryptImage(base64Image);
|
|
160
|
-
}
|
|
161
|
-
function startDetection(params) {
|
|
162
|
-
let lastStatus;
|
|
163
|
-
let session;
|
|
164
|
-
const { provider } = params;
|
|
165
|
-
const setStatus = (status) => {
|
|
166
|
-
if (session?.isDisposed() === true) return;
|
|
167
|
-
if (lastStatus === status) return;
|
|
168
|
-
lastStatus = status;
|
|
169
|
-
params.onUpdate(status);
|
|
170
|
-
};
|
|
171
|
-
const stopDetectionLoop = () => {
|
|
172
|
-
session?.dispose();
|
|
173
|
-
};
|
|
174
|
-
const reset = () => {
|
|
175
|
-
provider.reset();
|
|
176
|
-
};
|
|
177
|
-
const cleanup = () => {
|
|
178
|
-
stopDetectionLoop();
|
|
179
|
-
};
|
|
180
|
-
(async () => {
|
|
181
|
-
try {
|
|
182
|
-
provider.setCallbacks({
|
|
183
|
-
onFarAway: () => setStatus("tooFar"),
|
|
184
|
-
onTooClose: () => setStatus("tooClose"),
|
|
185
|
-
onTooManyFaces: () => setStatus("tooManyFaces"),
|
|
186
|
-
onNoFace: () => setStatus("idle"),
|
|
187
|
-
onCenterFace: () => setStatus("centerFace"),
|
|
188
|
-
onGetReady: () => setStatus("getReady"),
|
|
189
|
-
onGetReadyFinished: () => setStatus("getReadyFinished"),
|
|
190
|
-
onDark: () => {
|
|
191
|
-
if (params.config.validateBrightness) setStatus("dark");
|
|
192
|
-
},
|
|
193
|
-
onBlur: () => setStatus("blur"),
|
|
194
|
-
onFaceAngle: () => setStatus("faceAngle"),
|
|
195
|
-
onLenses: () => {
|
|
196
|
-
if (params.config.validateLenses) setStatus("lenses");
|
|
197
|
-
},
|
|
198
|
-
onMask: () => {
|
|
199
|
-
if (params.config.validateFaceMask) setStatus("faceMask");
|
|
200
|
-
},
|
|
201
|
-
onEyesClosed: () => {
|
|
202
|
-
if (params.config.validateClosedEyes) setStatus("eyesClosed");
|
|
203
|
-
},
|
|
204
|
-
onHeadWear: () => {
|
|
205
|
-
if (params.config.validateHeadCover) setStatus("headWear");
|
|
206
|
-
},
|
|
207
|
-
onFaceOccluded: () => {},
|
|
208
|
-
onSwitchToManualCapture: () => {
|
|
209
|
-
setStatus("manualCapture");
|
|
210
|
-
stopDetectionLoop();
|
|
211
|
-
},
|
|
212
|
-
onCapture: (canvas, faceCoordinates) => {
|
|
213
|
-
setStatus("success");
|
|
214
|
-
params.onSuccess(canvas, faceCoordinates);
|
|
215
|
-
cleanup();
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
setStatus("detecting");
|
|
219
|
-
session = new StreamCanvasProcessingSession({
|
|
220
|
-
capturer: params.capturer,
|
|
221
|
-
provider,
|
|
222
|
-
onFrame: params.onFrame
|
|
223
|
-
});
|
|
224
|
-
} catch {
|
|
225
|
-
setStatus("error");
|
|
226
|
-
cleanup();
|
|
227
|
-
}
|
|
228
|
-
})();
|
|
229
|
-
return {
|
|
230
|
-
cleanup,
|
|
231
|
-
reset
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
function buildResolutionFromStream(stream) {
|
|
235
|
-
const track = stream.getVideoTracks()[0];
|
|
236
|
-
if (!track) return;
|
|
237
|
-
const settings = track.getSettings();
|
|
238
|
-
const width = settings.width;
|
|
239
|
-
const height = settings.height;
|
|
240
|
-
if (typeof width === "number" && typeof height === "number") return `${width}x${height}`;
|
|
241
|
-
}
|
|
242
|
-
async function startRecordingSession(params) {
|
|
243
|
-
if (params.config.deepsightLiveness === "VIDEOLIVENESS") return;
|
|
244
|
-
if (params.config.enableFaceRecording !== true) return;
|
|
245
|
-
if (params.existing) return params.existing;
|
|
246
|
-
const provider = params.config.recording?.capability ?? new OpenViduRecordingProvider();
|
|
247
|
-
const clonedStream = params.clonedStream;
|
|
248
|
-
const hasAudio = clonedStream.getAudioTracks().length > 0;
|
|
249
|
-
const resolution = buildResolutionFromStream(clonedStream);
|
|
250
|
-
const session = await createRecordingSession("selfie");
|
|
251
|
-
const connection = await provider.connect({
|
|
252
|
-
sessionToken: session.token,
|
|
253
|
-
stream: clonedStream,
|
|
254
|
-
events: {
|
|
255
|
-
onSessionConnected: (sessionId) => {
|
|
256
|
-
addEvent({
|
|
257
|
-
code: streamingEvents.strSessionDidConnect,
|
|
258
|
-
module: eventModuleNames.selfie,
|
|
259
|
-
payload: {
|
|
260
|
-
message: "Recording session connected",
|
|
261
|
-
sessionId
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
},
|
|
265
|
-
onSessionDisconnected: (sessionId) => {
|
|
266
|
-
addEvent({
|
|
267
|
-
code: streamingEvents.strSessionDidDisconnect,
|
|
268
|
-
module: eventModuleNames.selfie,
|
|
269
|
-
payload: {
|
|
270
|
-
message: "Recording session disconnected",
|
|
271
|
-
sessionId
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
},
|
|
275
|
-
onSessionException: (event) => {
|
|
276
|
-
addEvent({
|
|
277
|
-
code: streamingEvents.strSessionDidFailWithError,
|
|
278
|
-
module: eventModuleNames.selfie,
|
|
279
|
-
payload: {
|
|
280
|
-
message: "Recording session failed due to an error",
|
|
281
|
-
eventName: event.name,
|
|
282
|
-
type: "OpenViduException",
|
|
283
|
-
errorMessage: event.message,
|
|
284
|
-
sessionId: event.sessionId
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
},
|
|
288
|
-
onPublisherCreated: (p) => {
|
|
289
|
-
addEvent({
|
|
290
|
-
code: streamingEvents.strStreamPublisherCreated,
|
|
291
|
-
module: eventModuleNames.selfie,
|
|
292
|
-
payload: {
|
|
293
|
-
message: "Recording publisher created",
|
|
294
|
-
sessionId: p.sessionId,
|
|
295
|
-
streamId: p.streamId
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
},
|
|
299
|
-
onPublisherError: (p) => {
|
|
300
|
-
addEvent({
|
|
301
|
-
code: streamingEvents.strStreamPublisherDidFailWithError,
|
|
302
|
-
module: eventModuleNames.selfie,
|
|
303
|
-
payload: {
|
|
304
|
-
message: "Recording publisher failed due to an error",
|
|
305
|
-
sessionId: p.sessionId,
|
|
306
|
-
streamId: p.streamId,
|
|
307
|
-
error: { message: p.message ?? "Unknown error" }
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
await startRecording({
|
|
314
|
-
videoRecordingId: session.videoRecordingId,
|
|
315
|
-
type: "selfie",
|
|
316
|
-
resolution,
|
|
317
|
-
hasAudio
|
|
318
|
-
});
|
|
319
|
-
addEvent({
|
|
320
|
-
code: streamingEvents.strStreamVideoCaptureStart,
|
|
321
|
-
module: eventModuleNames.selfie,
|
|
322
|
-
payload: {
|
|
323
|
-
message: "Recording capture started",
|
|
324
|
-
resolution,
|
|
325
|
-
videoRecordingId: session.videoRecordingId,
|
|
326
|
-
sessionId: session.sessionId,
|
|
327
|
-
streamId: connection.publisher.getStreamId()
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
return {
|
|
331
|
-
token: session.token,
|
|
332
|
-
sessionId: session.sessionId,
|
|
333
|
-
videoRecordingId: session.videoRecordingId,
|
|
334
|
-
connection,
|
|
335
|
-
resolution,
|
|
336
|
-
hasAudio
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
function stopRecording(session) {
|
|
340
|
-
(async () => {
|
|
341
|
-
try {
|
|
342
|
-
addEvent({
|
|
343
|
-
code: streamingEvents.strStreamVideoCaptureStop,
|
|
344
|
-
module: eventModuleNames.selfie,
|
|
345
|
-
payload: {
|
|
346
|
-
message: "Recording capture stopped",
|
|
347
|
-
videoRecordingId: session.videoRecordingId,
|
|
348
|
-
sessionId: session.sessionId,
|
|
349
|
-
streamId: session.connection.publisher.getStreamId()
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
await stopRecording$1(session.videoRecordingId);
|
|
353
|
-
addEvent({
|
|
354
|
-
code: streamingEvents.strStreamPublisherDestroyed,
|
|
355
|
-
module: eventModuleNames.selfie,
|
|
356
|
-
payload: {
|
|
357
|
-
message: "Recording publisher destroyed",
|
|
358
|
-
sessionId: session.sessionId,
|
|
359
|
-
streamId: session.connection.publisher.getStreamId()
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
} finally {
|
|
363
|
-
await session.connection.disconnect();
|
|
364
|
-
addEvent({
|
|
365
|
-
code: streamingEvents.strSessionDidDisconnect,
|
|
366
|
-
module: eventModuleNames.selfie,
|
|
367
|
-
payload: {
|
|
368
|
-
message: "Recording session disconnected",
|
|
369
|
-
sessionId: session.sessionId
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
})();
|
|
374
|
-
}
|
|
375
|
-
async function initializeDeepsightSession(options) {
|
|
376
|
-
const { loadDeepsightSession } = await import("./deepsightLoader-CHzDt5p2.esm.js");
|
|
377
|
-
return loadDeepsightSession({
|
|
378
|
-
ds: options.ds,
|
|
379
|
-
storage: options.storage
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
//#endregion
|
|
384
|
-
//#region src/modules/selfie/recordingService.ts
|
|
385
|
-
/**
|
|
386
|
-
* Records on-device and uploads encrypted video for liveness.
|
|
387
|
-
*/
|
|
388
|
-
var LocalRecordingService = class {
|
|
389
|
-
constructor(wasmUtil, sessionToken) {
|
|
390
|
-
this.recorder = new LocalRecordingProvider();
|
|
391
|
-
this.sessionToken = sessionToken;
|
|
392
|
-
this.wasmUtil = wasmUtil;
|
|
393
|
-
}
|
|
394
|
-
async start(stream) {
|
|
395
|
-
this.recorder.startRecording(stream);
|
|
396
|
-
}
|
|
397
|
-
async stop() {
|
|
398
|
-
if (!this.recorder.isRecording) return { recordingId: null };
|
|
399
|
-
const result = await this.recorder.stopRecording(10, (base64) => this.wasmUtil.encryptImage(base64), (buffer) => this.wasmUtil.ckvcks(buffer));
|
|
400
|
-
if (!this.sessionToken) return { recordingId: null };
|
|
401
|
-
return { recordingId: await uploadDeepsightVideo(result.encryptedVideo, this.sessionToken) };
|
|
402
|
-
}
|
|
403
|
-
cleanup() {
|
|
404
|
-
this.recorder.reset();
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
/**
|
|
408
|
-
* Records through OpenVidu and manages the session lifecycle.
|
|
409
|
-
*/
|
|
410
|
-
var OpenViduRecordingService = class {
|
|
411
|
-
constructor(config) {
|
|
412
|
-
this.provider = new OpenViduRecordingProvider();
|
|
413
|
-
this.config = config;
|
|
414
|
-
}
|
|
415
|
-
async start(stream) {
|
|
416
|
-
this.session = await startRecordingSession({
|
|
417
|
-
config: {
|
|
418
|
-
...this.config,
|
|
419
|
-
recording: { capability: this.provider }
|
|
420
|
-
},
|
|
421
|
-
clonedStream: stream.clone(),
|
|
422
|
-
existing: this.session
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
async stop() {
|
|
426
|
-
if (this.session) {
|
|
427
|
-
stopRecording(this.session);
|
|
428
|
-
this.session = void 0;
|
|
429
|
-
}
|
|
430
|
-
return { recordingId: null };
|
|
431
|
-
}
|
|
432
|
-
cleanup() {
|
|
433
|
-
if (this.session) stopRecording(this.session);
|
|
434
|
-
}
|
|
435
|
-
};
|
|
436
|
-
/**
|
|
437
|
-
* Creates the recording service for the current configuration.
|
|
438
|
-
*/
|
|
439
|
-
function createRecordingService(params) {
|
|
440
|
-
if (params.config.deepsightLiveness === "VIDEOLIVENESS") return new LocalRecordingService(params.wasmUtil, params.sessionToken);
|
|
441
|
-
if (params.config.enableFaceRecording === true) return new OpenViduRecordingService(params.config);
|
|
442
|
-
}
|
|
443
|
-
|
|
444
22
|
//#endregion
|
|
445
23
|
//#region src/modules/selfie/selfieStateMachine.ts
|
|
446
|
-
const _selfieMachine =
|
|
447
|
-
types: {
|
|
448
|
-
context: {},
|
|
449
|
-
events: {},
|
|
450
|
-
input: {}
|
|
451
|
-
},
|
|
24
|
+
const _selfieMachine = faceCaptureMachine.provide({
|
|
452
25
|
actors: {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}),
|
|
456
|
-
requestPermission: fromPromise(async () => {
|
|
457
|
-
return requestPermission();
|
|
458
|
-
}),
|
|
459
|
-
initializeCamera: fromPromise(async ({ input }) => {
|
|
460
|
-
return initializeCamera({
|
|
461
|
-
config: input.config,
|
|
462
|
-
deepsightService: input.deepsightService
|
|
463
|
-
});
|
|
464
|
-
}),
|
|
465
|
-
runDetection: fromCallback(({ input, sendBack }) => {
|
|
466
|
-
if (!input.frameCapturer || !input.provider) {
|
|
467
|
-
sendBack({
|
|
468
|
-
type: "DETECTION_UPDATE",
|
|
469
|
-
status: "error"
|
|
470
|
-
});
|
|
471
|
-
return () => {};
|
|
472
|
-
}
|
|
473
|
-
const { cleanup, reset } = startDetection({
|
|
474
|
-
config: input.config,
|
|
475
|
-
capturer: input.frameCapturer,
|
|
476
|
-
onUpdate: (status) => sendBack({
|
|
477
|
-
type: "DETECTION_UPDATE",
|
|
478
|
-
status
|
|
479
|
-
}),
|
|
480
|
-
onFrame: (frame) => sendBack({
|
|
481
|
-
type: "DETECTION_FRAME",
|
|
482
|
-
frame
|
|
483
|
-
}),
|
|
484
|
-
onSuccess: (canvas, faceCoordinates) => sendBack({
|
|
485
|
-
type: "DETECTION_SUCCESS",
|
|
486
|
-
canvas,
|
|
487
|
-
faceCoordinates
|
|
488
|
-
}),
|
|
489
|
-
provider: input.provider
|
|
490
|
-
});
|
|
491
|
-
sendBack({
|
|
492
|
-
type: "DETECTION_RESET_READY",
|
|
493
|
-
reset
|
|
494
|
-
});
|
|
495
|
-
return cleanup;
|
|
496
|
-
}),
|
|
497
|
-
initializeDeepsightSession: fromPromise(async ({ input }) => {
|
|
498
|
-
return await initializeDeepsightSession({
|
|
499
|
-
ds: input.ds,
|
|
500
|
-
storage: input.storage
|
|
501
|
-
});
|
|
502
|
-
}),
|
|
503
|
-
startRecording: fromPromise(async ({ input }) => {
|
|
504
|
-
if (!input.stream) return input.recordingService;
|
|
505
|
-
const wasmUtil = await input.dependencies.getWasmUtil();
|
|
506
|
-
const sessionToken = getToken();
|
|
507
|
-
const service = input.recordingService ?? createRecordingService({
|
|
508
|
-
config: input.config,
|
|
509
|
-
wasmUtil,
|
|
510
|
-
sessionToken
|
|
511
|
-
});
|
|
512
|
-
if (service) await service.start(input.stream);
|
|
513
|
-
return service;
|
|
514
|
-
}),
|
|
515
|
-
checkVirtualCamera: fromPromise(async ({ input }) => {
|
|
516
|
-
if (!input.deepsightService || !input.stream) return false;
|
|
517
|
-
const videoTrack = input.stream.getVideoTracks()[0];
|
|
518
|
-
if (!videoTrack) return false;
|
|
519
|
-
return input.deepsightService.checkVirtualCamera(videoTrack);
|
|
520
|
-
}),
|
|
521
|
-
uploadSelfie: fromPromise(async ({ input, signal }) => {
|
|
522
|
-
let recordingId = null;
|
|
523
|
-
const sessionToken = getToken();
|
|
524
|
-
try {
|
|
525
|
-
if (input.deepsightService) {
|
|
526
|
-
const [_, recordingServiceStopResult] = await Promise.all([
|
|
527
|
-
input.deepsightService.performVirtualCameraCheck(sessionToken, "SELFIE"),
|
|
528
|
-
input.recordingService?.stop(),
|
|
529
|
-
input.deepsightService.analyzeFrame(input.canvas.getImageData())
|
|
530
|
-
]);
|
|
531
|
-
recordingId = recordingServiceStopResult?.recordingId ?? null;
|
|
532
|
-
}
|
|
533
|
-
} catch (error) {}
|
|
26
|
+
uploadFace: fromPromise(async ({ input, signal }) => {
|
|
27
|
+
const ctx = input;
|
|
534
28
|
return uploadSelfie({
|
|
535
|
-
encryptedBase64Image:
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
faceCoordinates: input.faceCoordinates,
|
|
540
|
-
metadata: input.deepsightService?.getMetadata(),
|
|
541
|
-
recordingId,
|
|
29
|
+
encryptedBase64Image: ctx.encryptedBase64Image,
|
|
30
|
+
faceCoordinates: ctx.faceCoordinates,
|
|
31
|
+
metadata: ctx.deepsightService?.getMetadata(),
|
|
32
|
+
recordingId: ctx.uploadRecordingId,
|
|
542
33
|
signal
|
|
543
34
|
});
|
|
544
35
|
}),
|
|
@@ -547,550 +38,23 @@ const _selfieMachine = setup({
|
|
|
547
38
|
})
|
|
548
39
|
},
|
|
549
40
|
actions: {
|
|
550
|
-
stopMediaStream: assign(({ context }) => {
|
|
551
|
-
context.frameCapturer?.dispose();
|
|
552
|
-
if (context.stream) stopStream(context.stream);
|
|
553
|
-
context.provider?.dispose();
|
|
554
|
-
return {
|
|
555
|
-
stream: void 0,
|
|
556
|
-
provider: void 0,
|
|
557
|
-
frameCapturer: void 0
|
|
558
|
-
};
|
|
559
|
-
}),
|
|
560
|
-
setStreamAndCapturer: assign({
|
|
561
|
-
stream: ({ event }) => {
|
|
562
|
-
if ("output" in event) return event.output.stream;
|
|
563
|
-
},
|
|
564
|
-
provider: ({ event }) => {
|
|
565
|
-
if ("output" in event) return event.output.provider;
|
|
566
|
-
},
|
|
567
|
-
frameCapturer: ({ event }) => {
|
|
568
|
-
if ("output" in event) return new StreamCanvasCapture(event.output.stream);
|
|
569
|
-
}
|
|
570
|
-
}),
|
|
571
|
-
trackTutorialSelfie: () => {
|
|
572
|
-
addEvent({
|
|
573
|
-
code: "tutorialSelfie",
|
|
574
|
-
module: eventModuleNames.selfie,
|
|
575
|
-
payload: { tutorialSelfie: true }
|
|
576
|
-
});
|
|
577
|
-
},
|
|
578
41
|
trackContinue: () => {
|
|
579
42
|
addEvent({
|
|
580
|
-
code:
|
|
43
|
+
code: FACE_CAPTURE_EVENT_CODES.CONTINUE,
|
|
581
44
|
module: eventModuleNames.selfie
|
|
582
45
|
});
|
|
583
46
|
},
|
|
584
|
-
resetContext: assign(({ context }) => ({
|
|
585
|
-
stream: void 0,
|
|
586
|
-
provider: void 0,
|
|
587
|
-
frameCapturer: void 0,
|
|
588
|
-
error: void 0,
|
|
589
|
-
detectionStatus: "idle",
|
|
590
|
-
debugFrame: void 0,
|
|
591
|
-
capturedImage: void 0,
|
|
592
|
-
faceCoordinates: void 0,
|
|
593
|
-
uploadResponse: void 0,
|
|
594
|
-
processResponse: void 0,
|
|
595
|
-
recordingService: void 0,
|
|
596
|
-
attemptsRemaining: context.config.captureAttempts,
|
|
597
|
-
uploadError: void 0,
|
|
598
|
-
permissionResult: void 0,
|
|
599
|
-
resetDetection: void 0,
|
|
600
|
-
deepsightService: void 0
|
|
601
|
-
})),
|
|
602
|
-
resetDetection: ({ context }) => {
|
|
603
|
-
context.resetDetection?.();
|
|
604
|
-
},
|
|
605
|
-
captureImage: assign({ capturedImage: ({ context }) => {
|
|
606
|
-
if (context.capturedImage) return context.capturedImage;
|
|
607
|
-
return context.frameCapturer?.getLatestCanvas() ?? void 0;
|
|
608
|
-
} }),
|
|
609
|
-
captureLatestFrame: assign({ capturedImage: ({ context }) => {
|
|
610
|
-
return context.frameCapturer?.getLatestCanvas() ?? void 0;
|
|
611
|
-
} }),
|
|
612
|
-
clearUploadFailure: assign({
|
|
613
|
-
uploadError: () => void 0,
|
|
614
|
-
detectionStatus: () => "idle",
|
|
615
|
-
capturedImage: () => void 0
|
|
616
|
-
}),
|
|
617
|
-
clearStreamForRetry: assign({
|
|
618
|
-
stream: () => void 0,
|
|
619
|
-
provider: () => void 0,
|
|
620
|
-
frameCapturer: () => void 0
|
|
621
|
-
}),
|
|
622
|
-
decrementAttemptsRemaining: assign(({ context }) => ({ attemptsRemaining: context.attemptsRemaining - 1 })),
|
|
623
47
|
setUploadErrorFromUploadValidation: assign({ uploadError: ({ context }) => validateUploadResponse({
|
|
624
48
|
config: context.config,
|
|
625
49
|
response: context.uploadResponse
|
|
626
|
-
}) ?? FACE_ERROR_CODES.SERVER })
|
|
627
|
-
clearRecordingService: assign({ recordingService: () => void 0 }),
|
|
628
|
-
cleanup: ({ context }) => {
|
|
629
|
-
context.deepsightService?.cleanup();
|
|
630
|
-
context.recordingService?.cleanup();
|
|
631
|
-
}
|
|
50
|
+
}) ?? FACE_ERROR_CODES.SERVER })
|
|
632
51
|
},
|
|
633
52
|
guards: {
|
|
634
|
-
hasShowTutorial: ({ context }) => context.config.showTutorial,
|
|
635
|
-
isPermissionGranted: ({ event }) => {
|
|
636
|
-
if ("output" in event) return event.output === "granted";
|
|
637
|
-
return false;
|
|
638
|
-
},
|
|
639
|
-
isPermissionDeniedError: ({ event }) => {
|
|
640
|
-
if ("error" in event) {
|
|
641
|
-
const error = event.error;
|
|
642
|
-
return error?.name === "NotAllowedError" || error?.name === "PermissionDeniedError";
|
|
643
|
-
}
|
|
644
|
-
return false;
|
|
645
|
-
},
|
|
646
|
-
hasStream: ({ context }) => context.stream !== void 0,
|
|
647
|
-
isCameraAndDeepsightReady: ({ context }) => context.stream !== void 0 && context.deepsightService !== void 0,
|
|
648
|
-
hasAttemptsRemaining: ({ context }) => context.attemptsRemaining > 0,
|
|
649
|
-
hasCapturedImage: ({ context }) => context.capturedImage !== void 0,
|
|
650
53
|
hasUploadValidationError: ({ context }) => validateUploadResponse({
|
|
651
54
|
config: context.config,
|
|
652
55
|
response: context.uploadResponse
|
|
653
|
-
}) !== void 0
|
|
654
|
-
|
|
655
|
-
}).createMachine({
|
|
656
|
-
id: "selfie",
|
|
657
|
-
initial: "idle",
|
|
658
|
-
context: ({ input }) => ({
|
|
659
|
-
config: input.config,
|
|
660
|
-
dependencies: input.dependencies,
|
|
661
|
-
stream: void 0,
|
|
662
|
-
provider: void 0,
|
|
663
|
-
frameCapturer: void 0,
|
|
664
|
-
error: void 0,
|
|
665
|
-
detectionStatus: "idle",
|
|
666
|
-
debugFrame: void 0,
|
|
667
|
-
capturedImage: void 0,
|
|
668
|
-
faceCoordinates: void 0,
|
|
669
|
-
uploadResponse: void 0,
|
|
670
|
-
processResponse: void 0,
|
|
671
|
-
recordingService: void 0,
|
|
672
|
-
attemptsRemaining: input.config.captureAttempts,
|
|
673
|
-
uploadError: void 0,
|
|
674
|
-
permissionResult: void 0,
|
|
675
|
-
resetDetection: void 0,
|
|
676
|
-
deepsightService: void 0
|
|
677
|
-
}),
|
|
678
|
-
on: { QUIT: { target: "#selfie.closed" } },
|
|
679
|
-
states: {
|
|
680
|
-
idle: { on: { LOAD: [{
|
|
681
|
-
target: "tutorial",
|
|
682
|
-
guard: "hasShowTutorial"
|
|
683
|
-
}, { target: "loading" }] } },
|
|
684
|
-
loading: { invoke: [{
|
|
685
|
-
id: "checkPermissionLoading",
|
|
686
|
-
src: "checkPermission",
|
|
687
|
-
onDone: [{
|
|
688
|
-
target: "capture",
|
|
689
|
-
guard: "isPermissionGranted",
|
|
690
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
691
|
-
}, {
|
|
692
|
-
target: "permissions",
|
|
693
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
694
|
-
}]
|
|
695
|
-
}, {
|
|
696
|
-
id: "loadingInitDeepsight",
|
|
697
|
-
src: "initializeDeepsightSession",
|
|
698
|
-
input: ({ context }) => ({
|
|
699
|
-
ds: context.config.ds,
|
|
700
|
-
storage: context.dependencies.storage
|
|
701
|
-
}),
|
|
702
|
-
onDone: { actions: assign({ deepsightService: ({ event }) => event.output }) },
|
|
703
|
-
onError: { actions: () => void 0 }
|
|
704
|
-
}] },
|
|
705
|
-
tutorial: {
|
|
706
|
-
initial: "checkingPermission",
|
|
707
|
-
entry: "trackTutorialSelfie",
|
|
708
|
-
states: {
|
|
709
|
-
checkingPermission: { invoke: {
|
|
710
|
-
id: "checkPermissionTutorial",
|
|
711
|
-
src: "checkPermission",
|
|
712
|
-
onDone: [{
|
|
713
|
-
target: "initializingCamera",
|
|
714
|
-
guard: "isPermissionGranted",
|
|
715
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
716
|
-
}, {
|
|
717
|
-
target: "ready",
|
|
718
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
719
|
-
}]
|
|
720
|
-
} },
|
|
721
|
-
initializingCamera: {
|
|
722
|
-
type: "parallel",
|
|
723
|
-
states: {
|
|
724
|
-
cameraInit: {
|
|
725
|
-
initial: "initializingDeepsight",
|
|
726
|
-
states: {
|
|
727
|
-
initializingDeepsight: { invoke: {
|
|
728
|
-
id: "tutorialInitDeepsight",
|
|
729
|
-
src: "initializeDeepsightSession",
|
|
730
|
-
input: ({ context }) => ({
|
|
731
|
-
ds: context.config.ds,
|
|
732
|
-
storage: context.dependencies.storage
|
|
733
|
-
}),
|
|
734
|
-
onDone: {
|
|
735
|
-
target: "initializingStream",
|
|
736
|
-
actions: assign({ deepsightService: ({ event }) => event.output })
|
|
737
|
-
},
|
|
738
|
-
onError: { target: "#selfie.tutorial.ready" }
|
|
739
|
-
} },
|
|
740
|
-
initializingStream: { invoke: {
|
|
741
|
-
id: "tutorialInitCamera",
|
|
742
|
-
src: "initializeCamera",
|
|
743
|
-
input: ({ context }) => ({
|
|
744
|
-
config: context.config,
|
|
745
|
-
dependencies: context.dependencies,
|
|
746
|
-
deepsightService: context.deepsightService
|
|
747
|
-
}),
|
|
748
|
-
onDone: {
|
|
749
|
-
target: "ready",
|
|
750
|
-
actions: "setStreamAndCapturer"
|
|
751
|
-
},
|
|
752
|
-
onError: [{
|
|
753
|
-
target: "#selfie.tutorial.ready",
|
|
754
|
-
guard: "isPermissionDeniedError",
|
|
755
|
-
actions: assign({ permissionResult: () => "denied" })
|
|
756
|
-
}, {
|
|
757
|
-
target: "#selfie.tutorial.ready",
|
|
758
|
-
actions: assign({ error: ({ event }) => String(event.error) })
|
|
759
|
-
}]
|
|
760
|
-
} },
|
|
761
|
-
ready: { type: "final" }
|
|
762
|
-
}
|
|
763
|
-
},
|
|
764
|
-
userIntent: {
|
|
765
|
-
initial: "waiting",
|
|
766
|
-
states: {
|
|
767
|
-
waiting: { on: { NEXT_STEP: {
|
|
768
|
-
target: "clicked",
|
|
769
|
-
actions: "trackContinue"
|
|
770
|
-
} } },
|
|
771
|
-
clicked: { type: "final" }
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
},
|
|
775
|
-
onDone: { target: "#selfie.capture" }
|
|
776
|
-
},
|
|
777
|
-
ready: {
|
|
778
|
-
initial: "idle",
|
|
779
|
-
states: {
|
|
780
|
-
idle: { always: [{
|
|
781
|
-
target: "initializingDeepsight",
|
|
782
|
-
guard: ({ context }) => context.deepsightService === void 0
|
|
783
|
-
}, { target: "readyForNext" }] },
|
|
784
|
-
initializingDeepsight: { invoke: {
|
|
785
|
-
id: "initializeDeepsightTutorial",
|
|
786
|
-
src: "initializeDeepsightSession",
|
|
787
|
-
input: ({ context }) => ({
|
|
788
|
-
ds: context.config.ds,
|
|
789
|
-
storage: context.dependencies.storage
|
|
790
|
-
}),
|
|
791
|
-
onDone: {
|
|
792
|
-
target: "readyForNext",
|
|
793
|
-
actions: assign({ deepsightService: ({ event }) => event.output })
|
|
794
|
-
},
|
|
795
|
-
onError: { target: "readyForNext" }
|
|
796
|
-
} },
|
|
797
|
-
readyForNext: { on: { NEXT_STEP: {
|
|
798
|
-
target: "#selfie.tutorial.waitingForPermission",
|
|
799
|
-
actions: "trackContinue"
|
|
800
|
-
} } }
|
|
801
|
-
}
|
|
802
|
-
},
|
|
803
|
-
waitingForPermission: { invoke: {
|
|
804
|
-
id: "checkPermissionWaiting",
|
|
805
|
-
src: "checkPermission",
|
|
806
|
-
onDone: [{
|
|
807
|
-
target: "#selfie.capture",
|
|
808
|
-
guard: "isPermissionGranted",
|
|
809
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
810
|
-
}, {
|
|
811
|
-
target: "#selfie.permissions",
|
|
812
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
813
|
-
}]
|
|
814
|
-
} }
|
|
815
|
-
}
|
|
816
|
-
},
|
|
817
|
-
permissions: {
|
|
818
|
-
initial: "checkingDeepsight",
|
|
819
|
-
states: {
|
|
820
|
-
checkingDeepsight: { always: [{
|
|
821
|
-
target: "initializingDeepsight",
|
|
822
|
-
guard: ({ context }) => context.deepsightService === void 0
|
|
823
|
-
}, { target: "idle" }] },
|
|
824
|
-
initializingDeepsight: { invoke: {
|
|
825
|
-
id: "initializeDeepsightPerms",
|
|
826
|
-
src: "initializeDeepsightSession",
|
|
827
|
-
input: ({ context }) => ({
|
|
828
|
-
ds: context.config.ds,
|
|
829
|
-
storage: context.dependencies.storage
|
|
830
|
-
}),
|
|
831
|
-
onDone: {
|
|
832
|
-
target: "idle",
|
|
833
|
-
actions: assign({ deepsightService: ({ event }) => event.output })
|
|
834
|
-
},
|
|
835
|
-
onError: { target: "idle" }
|
|
836
|
-
} },
|
|
837
|
-
idle: {
|
|
838
|
-
invoke: {
|
|
839
|
-
id: "checkPermissionIdle",
|
|
840
|
-
src: "checkPermission",
|
|
841
|
-
onDone: [{
|
|
842
|
-
target: "#selfie.capture",
|
|
843
|
-
guard: "isPermissionGranted",
|
|
844
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
845
|
-
}, {
|
|
846
|
-
target: "denied",
|
|
847
|
-
guard: ({ event }) => event.output === "denied",
|
|
848
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
849
|
-
}]
|
|
850
|
-
},
|
|
851
|
-
on: {
|
|
852
|
-
REQUEST_PERMISSION: "requesting",
|
|
853
|
-
GO_TO_LEARN_MORE: "learnMore"
|
|
854
|
-
}
|
|
855
|
-
},
|
|
856
|
-
learnMore: { on: {
|
|
857
|
-
BACK: "idle",
|
|
858
|
-
REQUEST_PERMISSION: "requesting"
|
|
859
|
-
} },
|
|
860
|
-
requesting: { invoke: {
|
|
861
|
-
id: "requestPermission",
|
|
862
|
-
src: "requestPermission",
|
|
863
|
-
onDone: [
|
|
864
|
-
{
|
|
865
|
-
target: "#selfie.capture",
|
|
866
|
-
guard: "isPermissionGranted",
|
|
867
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
868
|
-
},
|
|
869
|
-
{
|
|
870
|
-
target: "denied",
|
|
871
|
-
guard: ({ event }) => event.output === "denied",
|
|
872
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
873
|
-
},
|
|
874
|
-
{
|
|
875
|
-
target: "idle",
|
|
876
|
-
actions: assign({ permissionResult: ({ event }) => event.output })
|
|
877
|
-
}
|
|
878
|
-
],
|
|
879
|
-
onError: { target: "denied" }
|
|
880
|
-
} },
|
|
881
|
-
denied: { entry: assign({ permissionResult: () => "refresh" }) }
|
|
882
|
-
}
|
|
883
|
-
},
|
|
884
|
-
capture: {
|
|
885
|
-
initial: "checkingDeepsight",
|
|
886
|
-
exit: [
|
|
887
|
-
"stopMediaStream",
|
|
888
|
-
"cleanup",
|
|
889
|
-
"clearRecordingService"
|
|
890
|
-
],
|
|
891
|
-
states: {
|
|
892
|
-
checkingDeepsight: { always: [{
|
|
893
|
-
target: "initializingDeepsight",
|
|
894
|
-
guard: ({ context }) => context.deepsightService === void 0
|
|
895
|
-
}, { target: "checkingStream" }] },
|
|
896
|
-
initializingDeepsight: { invoke: {
|
|
897
|
-
id: "initializeDeepsightCapture",
|
|
898
|
-
src: "initializeDeepsightSession",
|
|
899
|
-
input: ({ context }) => ({
|
|
900
|
-
ds: context.config.ds,
|
|
901
|
-
storage: context.dependencies.storage
|
|
902
|
-
}),
|
|
903
|
-
onDone: {
|
|
904
|
-
target: "checkingStream",
|
|
905
|
-
actions: [assign({ deepsightService: ({ event }) => event.output })]
|
|
906
|
-
},
|
|
907
|
-
onError: { target: "#selfie.permissions" }
|
|
908
|
-
} },
|
|
909
|
-
checkingStream: { always: [
|
|
910
|
-
{
|
|
911
|
-
target: "initializingDeepsight",
|
|
912
|
-
guard: ({ context }) => context.deepsightService === void 0
|
|
913
|
-
},
|
|
914
|
-
{
|
|
915
|
-
target: "detecting",
|
|
916
|
-
guard: "hasStream"
|
|
917
|
-
},
|
|
918
|
-
{ target: "initializing" }
|
|
919
|
-
] },
|
|
920
|
-
initializing: { invoke: {
|
|
921
|
-
id: "initializeCamera",
|
|
922
|
-
src: "initializeCamera",
|
|
923
|
-
input: ({ context }) => ({
|
|
924
|
-
config: context.config,
|
|
925
|
-
dependencies: context.dependencies,
|
|
926
|
-
deepsightService: context.deepsightService
|
|
927
|
-
}),
|
|
928
|
-
onDone: {
|
|
929
|
-
target: "detecting",
|
|
930
|
-
actions: ["setStreamAndCapturer"]
|
|
931
|
-
},
|
|
932
|
-
onError: [{
|
|
933
|
-
target: "#selfie.permissions",
|
|
934
|
-
guard: "isPermissionDeniedError",
|
|
935
|
-
actions: assign({ permissionResult: () => "denied" })
|
|
936
|
-
}, {
|
|
937
|
-
target: "#selfie.error",
|
|
938
|
-
actions: assign({ error: ({ event }) => String(event.error) })
|
|
939
|
-
}]
|
|
940
|
-
} },
|
|
941
|
-
detecting: {
|
|
942
|
-
entry: [assign({ detectionStatus: () => "detecting" })],
|
|
943
|
-
invoke: [
|
|
944
|
-
{
|
|
945
|
-
id: "checkVirtualCamera",
|
|
946
|
-
src: "checkVirtualCamera",
|
|
947
|
-
input: ({ context }) => ({
|
|
948
|
-
stream: context.stream,
|
|
949
|
-
deepsightService: context.deepsightService
|
|
950
|
-
}),
|
|
951
|
-
onDone: [{
|
|
952
|
-
target: "#selfie.processing",
|
|
953
|
-
guard: ({ event }) => event.output === true,
|
|
954
|
-
actions: () => {
|
|
955
|
-
sendLabelInspectionEvent();
|
|
956
|
-
}
|
|
957
|
-
}],
|
|
958
|
-
onError: { actions: () => void 0 }
|
|
959
|
-
},
|
|
960
|
-
{
|
|
961
|
-
id: "startRecording",
|
|
962
|
-
src: "startRecording",
|
|
963
|
-
input: ({ context }) => ({
|
|
964
|
-
config: context.config,
|
|
965
|
-
dependencies: context.dependencies,
|
|
966
|
-
recordingService: context.recordingService,
|
|
967
|
-
stream: context.stream
|
|
968
|
-
}),
|
|
969
|
-
onDone: { actions: assign({ recordingService: ({ context, event }) => {
|
|
970
|
-
return event.output ?? context.recordingService;
|
|
971
|
-
} }) },
|
|
972
|
-
onError: { actions: () => void 0 }
|
|
973
|
-
},
|
|
974
|
-
{
|
|
975
|
-
id: "runDetection",
|
|
976
|
-
src: "runDetection",
|
|
977
|
-
input: ({ context }) => ({
|
|
978
|
-
frameCapturer: context.frameCapturer,
|
|
979
|
-
provider: context.provider,
|
|
980
|
-
config: context.config
|
|
981
|
-
})
|
|
982
|
-
}
|
|
983
|
-
],
|
|
984
|
-
on: {
|
|
985
|
-
DETECTION_UPDATE: { actions: assign({ detectionStatus: ({ event }) => event.status }) },
|
|
986
|
-
DETECTION_FRAME: { actions: assign({ debugFrame: ({ event }) => event.frame }) },
|
|
987
|
-
DETECTION_RESET_READY: { actions: assign({ resetDetection: ({ event }) => event.reset }) },
|
|
988
|
-
DETECTION_SUCCESS: {
|
|
989
|
-
target: "capturing",
|
|
990
|
-
actions: assign({
|
|
991
|
-
capturedImage: ({ event }) => event.canvas,
|
|
992
|
-
faceCoordinates: ({ event }) => event.faceCoordinates
|
|
993
|
-
})
|
|
994
|
-
},
|
|
995
|
-
MANUAL_CAPTURE: { target: "capturingManual" }
|
|
996
|
-
}
|
|
997
|
-
},
|
|
998
|
-
capturing: {
|
|
999
|
-
entry: ["captureImage"],
|
|
1000
|
-
always: [{
|
|
1001
|
-
target: "uploading",
|
|
1002
|
-
guard: "hasCapturedImage"
|
|
1003
|
-
}, {
|
|
1004
|
-
target: "uploadError",
|
|
1005
|
-
actions: assign(({ context }) => ({
|
|
1006
|
-
uploadError: FACE_ERROR_CODES.SERVER,
|
|
1007
|
-
attemptsRemaining: context.attemptsRemaining - 1
|
|
1008
|
-
}))
|
|
1009
|
-
}]
|
|
1010
|
-
},
|
|
1011
|
-
capturingManual: {
|
|
1012
|
-
entry: ["captureLatestFrame"],
|
|
1013
|
-
always: [{
|
|
1014
|
-
target: "uploading",
|
|
1015
|
-
guard: "hasCapturedImage"
|
|
1016
|
-
}, {
|
|
1017
|
-
target: "uploadError",
|
|
1018
|
-
actions: assign(({ context }) => ({
|
|
1019
|
-
uploadError: FACE_ERROR_CODES.SERVER,
|
|
1020
|
-
attemptsRemaining: context.attemptsRemaining - 1
|
|
1021
|
-
}))
|
|
1022
|
-
}]
|
|
1023
|
-
},
|
|
1024
|
-
uploading: { invoke: {
|
|
1025
|
-
id: "uploadSelfie",
|
|
1026
|
-
src: "uploadSelfie",
|
|
1027
|
-
input: ({ context }) => {
|
|
1028
|
-
const canvas = context.capturedImage;
|
|
1029
|
-
if (!canvas) throw new Error(FACE_ERROR_CODES.SERVER);
|
|
1030
|
-
return {
|
|
1031
|
-
canvas,
|
|
1032
|
-
faceCoordinates: context.faceCoordinates,
|
|
1033
|
-
deepsightService: context.deepsightService,
|
|
1034
|
-
dependencies: context.dependencies,
|
|
1035
|
-
recordingService: context.recordingService
|
|
1036
|
-
};
|
|
1037
|
-
},
|
|
1038
|
-
onDone: {
|
|
1039
|
-
target: "validatingUpload",
|
|
1040
|
-
actions: assign({ uploadResponse: ({ event }) => event.output })
|
|
1041
|
-
},
|
|
1042
|
-
onError: {
|
|
1043
|
-
target: "uploadError",
|
|
1044
|
-
actions: assign(({ context, event }) => ({
|
|
1045
|
-
uploadError: getFaceErrorCodeFromUnknown(event.error) ?? FACE_ERROR_CODES.SERVER,
|
|
1046
|
-
attemptsRemaining: context.attemptsRemaining - 1
|
|
1047
|
-
}))
|
|
1048
|
-
}
|
|
1049
|
-
} },
|
|
1050
|
-
validatingUpload: { always: [{
|
|
1051
|
-
target: "uploadError",
|
|
1052
|
-
guard: "hasUploadValidationError",
|
|
1053
|
-
actions: ["setUploadErrorFromUploadValidation", "decrementAttemptsRemaining"]
|
|
1054
|
-
}, { target: "success" }] },
|
|
1055
|
-
uploadError: { on: { RETRY_CAPTURE: {
|
|
1056
|
-
target: "checkingStream",
|
|
1057
|
-
guard: "hasAttemptsRemaining",
|
|
1058
|
-
actions: [
|
|
1059
|
-
"resetDetection",
|
|
1060
|
-
"clearUploadFailure",
|
|
1061
|
-
"clearStreamForRetry"
|
|
1062
|
-
]
|
|
1063
|
-
} } },
|
|
1064
|
-
success: {
|
|
1065
|
-
entry: "cleanup",
|
|
1066
|
-
after: { 3e3: { target: "#selfie.processing" } }
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
},
|
|
1070
|
-
processing: { invoke: {
|
|
1071
|
-
id: "processFace",
|
|
1072
|
-
src: "processFace",
|
|
1073
|
-
onDone: {
|
|
1074
|
-
target: "finished",
|
|
1075
|
-
actions: assign({ processResponse: ({ event }) => event.output })
|
|
1076
|
-
},
|
|
1077
|
-
onError: { target: "finished" }
|
|
1078
|
-
} },
|
|
1079
|
-
finished: {
|
|
1080
|
-
entry: "stopMediaStream",
|
|
1081
|
-
type: "final"
|
|
1082
|
-
},
|
|
1083
|
-
closed: {
|
|
1084
|
-
entry: "stopMediaStream",
|
|
1085
|
-
type: "final"
|
|
1086
|
-
},
|
|
1087
|
-
error: {
|
|
1088
|
-
entry: "stopMediaStream",
|
|
1089
|
-
on: { RESET: {
|
|
1090
|
-
target: "idle",
|
|
1091
|
-
actions: "resetContext"
|
|
1092
|
-
} }
|
|
1093
|
-
}
|
|
56
|
+
}) !== void 0,
|
|
57
|
+
isTerminalUploadError: () => false
|
|
1094
58
|
}
|
|
1095
59
|
});
|
|
1096
60
|
/**
|
|
@@ -1110,96 +74,13 @@ function createSelfieActor(options) {
|
|
|
1110
74
|
};
|
|
1111
75
|
return createActor(selfieMachine, { input: {
|
|
1112
76
|
config: options.config,
|
|
1113
|
-
dependencies
|
|
77
|
+
dependencies,
|
|
78
|
+
authHint: options.authHint
|
|
1114
79
|
} }).start();
|
|
1115
80
|
}
|
|
1116
81
|
|
|
1117
82
|
//#endregion
|
|
1118
83
|
//#region src/modules/selfie/selfieManager.ts
|
|
1119
|
-
function getPermissionStatus(snapshot) {
|
|
1120
|
-
if (!snapshot.matches("permissions")) return;
|
|
1121
|
-
if (snapshot.matches({ permissions: "idle" })) return "idle";
|
|
1122
|
-
if (snapshot.matches({ permissions: "learnMore" })) return "learnMore";
|
|
1123
|
-
if (snapshot.matches({ permissions: "requesting" })) return "requesting";
|
|
1124
|
-
if (snapshot.matches({ permissions: "denied" })) return "denied";
|
|
1125
|
-
}
|
|
1126
|
-
function getCaptureStatus(snapshot) {
|
|
1127
|
-
if (snapshot.matches({ capture: "initializing" })) return "initializing";
|
|
1128
|
-
if (snapshot.matches({ capture: "detecting" })) return "detecting";
|
|
1129
|
-
if (snapshot.matches({ capture: "capturing" })) return "capturing";
|
|
1130
|
-
if (snapshot.matches({ capture: "capturingManual" })) return "capturing";
|
|
1131
|
-
if (snapshot.matches({ capture: "uploading" })) return "uploading";
|
|
1132
|
-
if (snapshot.matches({ capture: "uploadError" })) return "uploadError";
|
|
1133
|
-
if (snapshot.matches({ capture: "success" })) return "success";
|
|
1134
|
-
}
|
|
1135
|
-
function mapState(snapshot) {
|
|
1136
|
-
const { context } = snapshot;
|
|
1137
|
-
if (snapshot.matches("idle")) return { status: "idle" };
|
|
1138
|
-
if (snapshot.matches("loading")) return { status: "loading" };
|
|
1139
|
-
if (snapshot.matches("tutorial")) return { status: "tutorial" };
|
|
1140
|
-
if (snapshot.matches("closed")) return { status: "closed" };
|
|
1141
|
-
if (snapshot.matches("permissions")) {
|
|
1142
|
-
const permissionStatus = getPermissionStatus(snapshot);
|
|
1143
|
-
if (permissionStatus === void 0) return {
|
|
1144
|
-
status: "permissions",
|
|
1145
|
-
permissionStatus: "idle"
|
|
1146
|
-
};
|
|
1147
|
-
return {
|
|
1148
|
-
status: "permissions",
|
|
1149
|
-
permissionStatus
|
|
1150
|
-
};
|
|
1151
|
-
}
|
|
1152
|
-
if (snapshot.matches("capture")) return {
|
|
1153
|
-
status: "capture",
|
|
1154
|
-
captureStatus: getCaptureStatus(snapshot) ?? "initializing",
|
|
1155
|
-
stream: context.stream,
|
|
1156
|
-
detectionStatus: context.detectionStatus,
|
|
1157
|
-
debugFrame: context.debugFrame,
|
|
1158
|
-
attemptsRemaining: context.attemptsRemaining,
|
|
1159
|
-
uploadError: context.uploadError
|
|
1160
|
-
};
|
|
1161
|
-
if (snapshot.matches("processing")) return { status: "processing" };
|
|
1162
|
-
if (snapshot.matches("finished")) return {
|
|
1163
|
-
status: "finished",
|
|
1164
|
-
processResponse: context.processResponse
|
|
1165
|
-
};
|
|
1166
|
-
if (snapshot.matches("error")) return {
|
|
1167
|
-
status: "error",
|
|
1168
|
-
error: context.error ?? "Unknown error"
|
|
1169
|
-
};
|
|
1170
|
-
return { status: "idle" };
|
|
1171
|
-
}
|
|
1172
|
-
function createApi({ actor }) {
|
|
1173
|
-
return {
|
|
1174
|
-
load() {
|
|
1175
|
-
actor.send({ type: "LOAD" });
|
|
1176
|
-
},
|
|
1177
|
-
nextStep() {
|
|
1178
|
-
actor.send({ type: "NEXT_STEP" });
|
|
1179
|
-
},
|
|
1180
|
-
requestPermission() {
|
|
1181
|
-
actor.send({ type: "REQUEST_PERMISSION" });
|
|
1182
|
-
},
|
|
1183
|
-
goToLearnMore() {
|
|
1184
|
-
actor.send({ type: "GO_TO_LEARN_MORE" });
|
|
1185
|
-
},
|
|
1186
|
-
back() {
|
|
1187
|
-
actor.send({ type: "BACK" });
|
|
1188
|
-
},
|
|
1189
|
-
close() {
|
|
1190
|
-
actor.send({ type: "QUIT" });
|
|
1191
|
-
},
|
|
1192
|
-
reset() {
|
|
1193
|
-
actor.send({ type: "RESET" });
|
|
1194
|
-
},
|
|
1195
|
-
retryCapture() {
|
|
1196
|
-
actor.send({ type: "RETRY_CAPTURE" });
|
|
1197
|
-
},
|
|
1198
|
-
capture() {
|
|
1199
|
-
actor.send({ type: "MANUAL_CAPTURE" });
|
|
1200
|
-
}
|
|
1201
|
-
};
|
|
1202
|
-
}
|
|
1203
84
|
/**
|
|
1204
85
|
* Creates a selfie manager instance for handling selfie capture flow.
|
|
1205
86
|
*
|
|
@@ -1230,11 +111,7 @@ function createApi({ actor }) {
|
|
|
1230
111
|
* ```
|
|
1231
112
|
*/
|
|
1232
113
|
function createSelfieManager(options) {
|
|
1233
|
-
return
|
|
1234
|
-
actor: createSelfieActor(options),
|
|
1235
|
-
mapState,
|
|
1236
|
-
createApi
|
|
1237
|
-
});
|
|
114
|
+
return createFaceCaptureManager(createSelfieActor(options));
|
|
1238
115
|
}
|
|
1239
116
|
|
|
1240
117
|
//#endregion
|