@incodetech/core 2.0.0-alpha.12 → 2.0.0-alpha.14

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.
Files changed (39) hide show
  1. package/dist/{OpenViduLogger-CRbRNZA7.esm.js → OpenViduLogger-BLxxXoyF.esm.js} +1 -1
  2. package/dist/OpenViduLogger-DyqID_-7.esm.js +3 -0
  3. package/dist/api-DfRLAneb.esm.js +53 -0
  4. package/dist/deepsightLoader-BMT0FSg6.esm.js +24 -0
  5. package/dist/deepsightService-j5zMt6wf.esm.js +236 -0
  6. package/dist/email.d.ts +5 -5
  7. package/dist/email.esm.js +16 -17
  8. package/dist/{xstate.esm-2hDiAXvZ.esm.js → endpoints-BUsSVoJV.esm.js} +28 -1
  9. package/dist/events-B8ZkhAZo.esm.js +285 -0
  10. package/dist/flow.d.ts +2 -3
  11. package/dist/flow.esm.js +18 -7
  12. package/dist/getDeviceClass-DkfbtsIJ.esm.js +41 -0
  13. package/dist/{id-CJKLe8HS.esm.js → id-r1mw9zBM.esm.js} +48 -39
  14. package/dist/id.d.ts +4 -5
  15. package/dist/id.esm.js +7 -6
  16. package/dist/{index-CbF_uI-x.d.ts → index-CJMK8K5u.d.ts} +3 -7
  17. package/dist/index.d.ts +220 -6
  18. package/dist/index.esm.js +12 -8
  19. package/dist/{lib-BJoLTN_W.esm.js → lib-CbAibJlt.esm.js} +2 -2
  20. package/dist/phone.d.ts +5 -5
  21. package/dist/phone.esm.js +16 -14
  22. package/dist/selfie.d.ts +119 -46
  23. package/dist/selfie.esm.js +284 -161
  24. package/dist/{endpoints-D9TGnxRK.esm.js → src-DYtpbFY5.esm.js} +242 -111
  25. package/dist/stats-DnU4uUFv.esm.js +16 -0
  26. package/dist/stats.d.ts +12 -0
  27. package/dist/stats.esm.js +4 -0
  28. package/dist/{streamingEvents-B3hNanPl.esm.js → streamingEvents-CfEJv3xH.esm.js} +35 -36
  29. package/dist/{types-BpCrZLU6.d.ts → types-CMR6NkxW.d.ts} +58 -1
  30. package/dist/{types-DZbrbPgj.d.ts → types-CRVSv38Q.d.ts} +10 -1
  31. package/package.json +2 -2
  32. package/dist/OpenViduLogger-Dy5P806a.esm.js +0 -3
  33. package/dist/StateMachine-pi8byl8C.d.ts +0 -58
  34. package/dist/addEvent-BGKc_lHF.esm.js +0 -16
  35. package/dist/deepsightLoader-B36_XZ7r.esm.js +0 -25
  36. package/dist/deepsightService-BWxcc4OC.esm.js +0 -225
  37. package/dist/recordingsRepository-D5MURoVB.esm.js +0 -40
  38. /package/dist/{Manager-BZUZTRPx.d.ts → Manager-Co-PsiG9.d.ts} +0 -0
  39. /package/dist/{chunk-FbsBJI8u.esm.js → chunk-V5DOKNPJ.esm.js} +0 -0
@@ -1,9 +1,11 @@
1
- import { E as createManager, T as stopCameraStream, f as FaceDetectionProvider, h as OpenViduRecordingProvider, i as getToken, n as api, t as endpoints, u as WasmUtilProvider, v as StreamCanvasProcessingSession, w as requestCameraAccess, y as StreamCanvasCapture } from "./endpoints-D9TGnxRK.esm.js";
2
- import { n as startRecording, r as stopRecording$1, t as createRecordingSession } from "./recordingsRepository-D5MURoVB.esm.js";
3
- import { i as getDeviceClass, n as checkPermission, r as requestPermission, t as streamingEvents } from "./streamingEvents-B3hNanPl.esm.js";
4
- import { a as createActor, i as fromPromise, n as assign, r as fromCallback, t as setup } from "./xstate.esm-2hDiAXvZ.esm.js";
5
- import { t as addEvent } from "./addEvent-BGKc_lHF.esm.js";
6
- import "./deepsightService-BWxcc4OC.esm.js";
1
+ import { d as addEvent, n as eventModuleNames } from "./events-B8ZkhAZo.esm.js";
2
+ import { C as createManager, S as stopCameraStream, a as FaceDetectionProvider, c as OpenViduRecordingProvider, f as BrowserStorageProvider, h as StreamCanvasCapture, m as StreamCanvasProcessingSession, r as WasmUtilProvider, u as LocalRecordingProvider, x as requestCameraAccess } from "./src-DYtpbFY5.esm.js";
3
+ import "./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 { a as uploadDeepsightVideo, c as getDeviceClass, i as stopRecording$1, n as createRecordingSession, o as checkPermission, r as startRecording, s as requestPermission, t as streamingEvents } from "./streamingEvents-CfEJv3xH.esm.js";
6
+ import { r as getToken, t as api } from "./api-DfRLAneb.esm.js";
7
+ import "./deepsightService-j5zMt6wf.esm.js";
8
+ import { t as addDeviceStats } from "./stats-DnU4uUFv.esm.js";
7
9
 
8
10
  //#region src/modules/selfie/types.ts
9
11
  const FACE_ERROR_CODES = {
@@ -110,6 +112,9 @@ async function processFace(imageType = "selfie", signal) {
110
112
 
111
113
  //#endregion
112
114
  //#region src/modules/selfie/selfieServices.ts
115
+ function sendLabelInspectionEvent() {
116
+ return addDeviceStats({ cameraLabelInspectionStatus: "FAIL" });
117
+ }
113
118
  const CAMERA_CONSTRAINTS = {
114
119
  video: {
115
120
  facingMode: "user",
@@ -121,7 +126,8 @@ const CAMERA_CONSTRAINTS = {
121
126
  function stopStream(stream) {
122
127
  stopCameraStream(stream);
123
128
  }
124
- async function initializeCamera(config) {
129
+ async function initializeCamera(params) {
130
+ const { config, dependencies } = params;
125
131
  const provider = new FaceDetectionProvider();
126
132
  await provider.initialize({ autocaptureInterval: config.autoCaptureTimeout * 1e3 });
127
133
  provider.setChecksEnabled({
@@ -131,6 +137,16 @@ async function initializeCamera(config) {
131
137
  headWear: config.validateHeadCover,
132
138
  occlusion: false
133
139
  });
140
+ console.log("performPrcCheck init");
141
+ const timerName = `performPrcCheck ${Math.random()}`;
142
+ console.time(timerName);
143
+ await params.deepsightService.performPrcCheck({
144
+ constraints: { video: CAMERA_CONSTRAINTS.video },
145
+ ds: config.ds,
146
+ storage: dependencies.storage
147
+ });
148
+ console.timeEnd(timerName);
149
+ console.log("performPrcCheck end");
134
150
  return {
135
151
  stream: await requestCameraAccess({
136
152
  video: CAMERA_CONSTRAINTS.video,
@@ -142,10 +158,10 @@ async function initializeCamera(config) {
142
158
  /**
143
159
  * Encrypts the provided selfie image using WASM.
144
160
  */
145
- async function encryptSelfieImage({ canvas }) {
161
+ async function encryptSelfieImage({ canvas, dependencies }) {
146
162
  const base64Image = canvas.getBase64Image();
147
163
  if (!base64Image) throw new Error("Canvas image is empty or null");
148
- return (await WasmUtilProvider.getInstance()).encryptImage(base64Image);
164
+ return (await dependencies.getWasmUtil()).encryptImage(base64Image);
149
165
  }
150
166
  function startDetection(params) {
151
167
  let lastStatus;
@@ -244,6 +260,7 @@ async function startRecordingSession(params) {
244
260
  onSessionConnected: (sessionId) => {
245
261
  addEvent({
246
262
  code: streamingEvents.strSessionDidConnect,
263
+ module: eventModuleNames.selfie,
247
264
  payload: {
248
265
  message: "Recording session connected",
249
266
  sessionId
@@ -253,6 +270,7 @@ async function startRecordingSession(params) {
253
270
  onSessionDisconnected: (sessionId) => {
254
271
  addEvent({
255
272
  code: streamingEvents.strSessionDidDisconnect,
273
+ module: eventModuleNames.selfie,
256
274
  payload: {
257
275
  message: "Recording session disconnected",
258
276
  sessionId
@@ -262,6 +280,7 @@ async function startRecordingSession(params) {
262
280
  onSessionException: (event) => {
263
281
  addEvent({
264
282
  code: streamingEvents.strSessionDidFailWithError,
283
+ module: eventModuleNames.selfie,
265
284
  payload: {
266
285
  message: "Recording session failed due to an error",
267
286
  eventName: event.name,
@@ -274,6 +293,7 @@ async function startRecordingSession(params) {
274
293
  onPublisherCreated: (p) => {
275
294
  addEvent({
276
295
  code: streamingEvents.strStreamPublisherCreated,
296
+ module: eventModuleNames.selfie,
277
297
  payload: {
278
298
  message: "Recording publisher created",
279
299
  sessionId: p.sessionId,
@@ -284,6 +304,7 @@ async function startRecordingSession(params) {
284
304
  onPublisherError: (p) => {
285
305
  addEvent({
286
306
  code: streamingEvents.strStreamPublisherDidFailWithError,
307
+ module: eventModuleNames.selfie,
287
308
  payload: {
288
309
  message: "Recording publisher failed due to an error",
289
310
  sessionId: p.sessionId,
@@ -302,6 +323,7 @@ async function startRecordingSession(params) {
302
323
  });
303
324
  addEvent({
304
325
  code: streamingEvents.strStreamVideoCaptureStart,
326
+ module: eventModuleNames.selfie,
305
327
  payload: {
306
328
  message: "Recording capture started",
307
329
  resolution,
@@ -324,6 +346,7 @@ function stopRecording(session) {
324
346
  try {
325
347
  addEvent({
326
348
  code: streamingEvents.strStreamVideoCaptureStop,
349
+ module: eventModuleNames.selfie,
327
350
  payload: {
328
351
  message: "Recording capture stopped",
329
352
  videoRecordingId: session.videoRecordingId,
@@ -334,6 +357,7 @@ function stopRecording(session) {
334
357
  await stopRecording$1(session.videoRecordingId);
335
358
  addEvent({
336
359
  code: streamingEvents.strStreamPublisherDestroyed,
360
+ module: eventModuleNames.selfie,
337
361
  payload: {
338
362
  message: "Recording publisher destroyed",
339
363
  sessionId: session.sessionId,
@@ -344,6 +368,7 @@ function stopRecording(session) {
344
368
  await session.connection.disconnect();
345
369
  addEvent({
346
370
  code: streamingEvents.strSessionDidDisconnect,
371
+ module: eventModuleNames.selfie,
347
372
  payload: {
348
373
  message: "Recording session disconnected",
349
374
  sessionId: session.sessionId
@@ -352,12 +377,72 @@ function stopRecording(session) {
352
377
  }
353
378
  })();
354
379
  }
355
- async function initializeDeepsightSession(config) {
356
- if (config.deepsightLiveness !== "VIDEOLIVENESS") return;
357
- const { loadDeepsightSession } = await import("./deepsightLoader-B36_XZ7r.esm.js");
380
+ async function initializeDeepsightSession() {
381
+ const { loadDeepsightSession } = await import("./deepsightLoader-BMT0FSg6.esm.js");
358
382
  return loadDeepsightSession();
359
383
  }
360
384
 
385
+ //#endregion
386
+ //#region src/modules/selfie/recordingService.ts
387
+ /**
388
+ * Records on-device and uploads encrypted video for liveness.
389
+ */
390
+ var LocalRecordingService = class {
391
+ constructor(wasmUtil, sessionToken) {
392
+ this.recorder = new LocalRecordingProvider();
393
+ this.sessionToken = sessionToken;
394
+ this.wasmUtil = wasmUtil;
395
+ }
396
+ async start(stream) {
397
+ this.recorder.startRecording(stream);
398
+ }
399
+ async stop() {
400
+ if (!this.recorder.isRecording) return { recordingId: null };
401
+ const result = await this.recorder.stopRecording(10, (base64) => this.wasmUtil.encryptImage(base64), (buffer) => this.wasmUtil.ckvcks(buffer));
402
+ if (!this.sessionToken) return { recordingId: null };
403
+ return { recordingId: await uploadDeepsightVideo(result.encryptedVideo, this.sessionToken) };
404
+ }
405
+ cleanup() {
406
+ this.recorder.reset();
407
+ }
408
+ };
409
+ /**
410
+ * Records through OpenVidu and manages the session lifecycle.
411
+ */
412
+ var OpenViduRecordingService = class {
413
+ constructor(config) {
414
+ this.provider = new OpenViduRecordingProvider();
415
+ this.config = config;
416
+ }
417
+ async start(stream) {
418
+ this.session = await startRecordingSession({
419
+ config: {
420
+ ...this.config,
421
+ recording: { capability: this.provider }
422
+ },
423
+ clonedStream: stream.clone(),
424
+ existing: this.session
425
+ });
426
+ }
427
+ async stop() {
428
+ if (this.session) {
429
+ stopRecording(this.session);
430
+ this.session = void 0;
431
+ }
432
+ return { recordingId: null };
433
+ }
434
+ cleanup() {
435
+ if (this.session) stopRecording(this.session);
436
+ }
437
+ };
438
+ /**
439
+ * Creates the recording service for the current configuration.
440
+ */
441
+ function createRecordingService(params) {
442
+ if (params.config.deepsightLiveness === "VIDEOLIVENESS") return new LocalRecordingService(params.wasmUtil, params.sessionToken);
443
+ if (params.config.enableFaceRecording === true) return new OpenViduRecordingService(params.config);
444
+ }
445
+
361
446
  //#endregion
362
447
  //#region src/modules/selfie/selfieStateMachine.ts
363
448
  const _selfieMachine = setup({
@@ -374,7 +459,11 @@ const _selfieMachine = setup({
374
459
  return requestPermission();
375
460
  }),
376
461
  initializeCamera: fromPromise(async ({ input }) => {
377
- return initializeCamera(input);
462
+ return initializeCamera({
463
+ config: input.config,
464
+ dependencies: input.dependencies,
465
+ deepsightService: input.deepsightService
466
+ });
378
467
  }),
379
468
  runDetection: fromCallback(({ input, sendBack }) => {
380
469
  if (!input.frameCapturer || !input.provider) {
@@ -408,37 +497,51 @@ const _selfieMachine = setup({
408
497
  });
409
498
  return cleanup;
410
499
  }),
411
- initializeDeepsightSession: fromPromise(async ({ input }) => {
412
- return await initializeDeepsightSession(input.config);
500
+ initializeDeepsightSession: fromPromise(async () => {
501
+ return await initializeDeepsightSession();
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);
413
520
  }),
414
521
  uploadSelfie: fromPromise(async ({ input, signal }) => {
415
- let metadata;
416
522
  let recordingId = null;
417
- if (input.deepsightService) {
418
- const imageData = input.canvas.getImageData();
419
- const sessionToken = getToken();
420
- if (imageData && sessionToken) {
421
- const result = await input.deepsightService.performCapture(sessionToken, imageData);
422
- metadata = result.metadata;
423
- recordingId = result.recordingId;
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;
424
532
  }
425
- }
533
+ } catch (error) {}
426
534
  return uploadSelfie({
427
- encryptedBase64Image: await encryptSelfieImage({ canvas: input.canvas }),
535
+ encryptedBase64Image: await encryptSelfieImage({
536
+ canvas: input.canvas,
537
+ dependencies: input.dependencies
538
+ }),
428
539
  faceCoordinates: input.faceCoordinates,
429
- metadata,
540
+ metadata: input.deepsightService?.getMetadata(),
430
541
  recordingId,
431
542
  signal
432
543
  });
433
544
  }),
434
- startRecording: fromPromise(async ({ input }) => {
435
- if (!input.clonedStream) return;
436
- return startRecordingSession({
437
- config: input.config,
438
- clonedStream: input.clonedStream,
439
- existing: input.existing
440
- });
441
- }),
442
545
  processFace: fromPromise(async ({ signal }) => {
443
546
  return processFace("selfie", signal);
444
547
  })
@@ -468,11 +571,15 @@ const _selfieMachine = setup({
468
571
  trackTutorialSelfie: () => {
469
572
  addEvent({
470
573
  code: "tutorialSelfie",
574
+ module: eventModuleNames.selfie,
471
575
  payload: { tutorialSelfie: true }
472
576
  });
473
577
  },
474
578
  trackContinue: () => {
475
- addEvent({ code: "continue" });
579
+ addEvent({
580
+ code: "continue",
581
+ module: eventModuleNames.selfie
582
+ });
476
583
  },
477
584
  resetContext: assign(({ context }) => ({
478
585
  stream: void 0,
@@ -485,8 +592,7 @@ const _selfieMachine = setup({
485
592
  faceCoordinates: void 0,
486
593
  uploadResponse: void 0,
487
594
  processResponse: void 0,
488
- recordingSession: void 0,
489
- recordingStream: void 0,
595
+ recordingService: void 0,
490
596
  attemptsRemaining: context.config.captureAttempts,
491
597
  uploadError: void 0,
492
598
  permissionResult: void 0,
@@ -508,39 +614,20 @@ const _selfieMachine = setup({
508
614
  detectionStatus: () => "idle",
509
615
  capturedImage: () => void 0
510
616
  }),
617
+ clearStreamForRetry: assign({
618
+ stream: () => void 0,
619
+ provider: () => void 0,
620
+ frameCapturer: () => void 0
621
+ }),
511
622
  decrementAttemptsRemaining: assign(({ context }) => ({ attemptsRemaining: context.attemptsRemaining - 1 })),
512
623
  setUploadErrorFromUploadValidation: assign({ uploadError: ({ context }) => validateUploadResponse({
513
624
  config: context.config,
514
625
  response: context.uploadResponse
515
626
  }) ?? FACE_ERROR_CODES.SERVER }),
516
- stopMediaRecording: ({ context }) => {
517
- if (context.recordingSession) stopRecording(context.recordingSession);
518
- },
519
- clearRecordingSession: assign({
520
- recordingSession: () => void 0,
521
- recordingStream: () => void 0
522
- }),
523
- createRecordingStream: assign({ recordingStream: ({ context }) => {
524
- if (!context.config.enableFaceRecording) return;
525
- if (context.recordingStream) return context.recordingStream;
526
- return context.stream?.clone();
527
- } }),
528
- stopRecordingStream: ({ context }) => {
529
- if (context.recordingStream) stopStream(context.recordingStream);
530
- },
531
- startDeepsightRecording: ({ context }) => {
532
- if (context.deepsightService && context.stream) context.deepsightService.startRecording(context.stream);
533
- },
534
- checkVirtualCamera: ({ context }) => {
535
- (async () => {
536
- if (context.deepsightService && context.stream) {
537
- const videoTrack = context.stream.getVideoTracks()[0];
538
- if (videoTrack) await context.deepsightService.checkVirtualCamera(videoTrack);
539
- }
540
- })();
541
- },
542
- cleanupDeepsight: ({ context }) => {
627
+ clearRecordingService: assign({ recordingService: () => void 0 }),
628
+ cleanup: ({ context }) => {
543
629
  context.deepsightService?.cleanup();
630
+ context.recordingService?.cleanup();
544
631
  }
545
632
  },
546
633
  guards: {
@@ -557,7 +644,7 @@ const _selfieMachine = setup({
557
644
  return false;
558
645
  },
559
646
  hasStream: ({ context }) => context.stream !== void 0,
560
- isCameraAndDeepsightReady: ({ context }) => context.stream !== void 0 && (context.config.deepsightLiveness !== "VIDEOLIVENESS" || context.deepsightService !== void 0),
647
+ isCameraAndDeepsightReady: ({ context }) => context.stream !== void 0 && context.deepsightService !== void 0,
561
648
  hasAttemptsRemaining: ({ context }) => context.attemptsRemaining > 0,
562
649
  hasCapturedImage: ({ context }) => context.capturedImage !== void 0,
563
650
  hasUploadValidationError: ({ context }) => validateUploadResponse({
@@ -570,6 +657,7 @@ const _selfieMachine = setup({
570
657
  initial: "idle",
571
658
  context: ({ input }) => ({
572
659
  config: input.config,
660
+ dependencies: input.dependencies,
573
661
  stream: void 0,
574
662
  provider: void 0,
575
663
  frameCapturer: void 0,
@@ -580,8 +668,7 @@ const _selfieMachine = setup({
580
668
  faceCoordinates: void 0,
581
669
  uploadResponse: void 0,
582
670
  processResponse: void 0,
583
- recordingSession: void 0,
584
- recordingStream: void 0,
671
+ recordingService: void 0,
585
672
  attemptsRemaining: input.config.captureAttempts,
586
673
  uploadError: void 0,
587
674
  permissionResult: void 0,
@@ -608,7 +695,6 @@ const _selfieMachine = setup({
608
695
  }, {
609
696
  id: "loadingInitDeepsight",
610
697
  src: "initializeDeepsightSession",
611
- input: ({ context }) => ({ config: context.config }),
612
698
  onDone: { actions: assign({ deepsightService: ({ event }) => event.output }) },
613
699
  onError: { actions: () => void 0 }
614
700
  }] },
@@ -629,62 +715,67 @@ const _selfieMachine = setup({
629
715
  }]
630
716
  } },
631
717
  initializingCamera: {
632
- initial: "booting",
633
- invoke: [{
634
- id: "tutorialInitCamera",
635
- src: "initializeCamera",
636
- input: ({ context }) => context.config,
637
- onDone: { actions: "setStreamAndCapturer" },
638
- onError: [{
639
- target: "ready",
640
- guard: "isPermissionDeniedError",
641
- actions: assign({ permissionResult: () => "denied" })
642
- }, {
643
- target: "ready",
644
- actions: assign({ error: ({ event }) => String(event.error) })
645
- }]
646
- }, {
647
- id: "tutorialInitDeepsight",
648
- src: "initializeDeepsightSession",
649
- input: ({ context }) => ({ config: context.config }),
650
- onDone: { actions: assign({ deepsightService: ({ event }) => event.output }) },
651
- onError: { actions: () => void 0 }
652
- }],
718
+ type: "parallel",
653
719
  states: {
654
- booting: {
655
- always: [{
656
- target: "#tutorialCameraReady",
657
- guard: "isCameraAndDeepsightReady"
658
- }],
659
- on: { NEXT_STEP: {
660
- target: "waitingForStream",
661
- actions: "trackContinue"
662
- } }
720
+ cameraInit: {
721
+ initial: "initializingDeepsight",
722
+ states: {
723
+ initializingDeepsight: { invoke: {
724
+ id: "tutorialInitDeepsight",
725
+ src: "initializeDeepsightSession",
726
+ onDone: {
727
+ target: "initializingStream",
728
+ actions: assign({ deepsightService: ({ event }) => event.output })
729
+ },
730
+ onError: { target: "#selfie.tutorial.ready" }
731
+ } },
732
+ initializingStream: { invoke: {
733
+ id: "tutorialInitCamera",
734
+ src: "initializeCamera",
735
+ input: ({ context }) => ({
736
+ config: context.config,
737
+ dependencies: context.dependencies,
738
+ deepsightService: context.deepsightService
739
+ }),
740
+ onDone: {
741
+ target: "ready",
742
+ actions: "setStreamAndCapturer"
743
+ },
744
+ onError: [{
745
+ target: "#selfie.tutorial.ready",
746
+ guard: "isPermissionDeniedError",
747
+ actions: assign({ permissionResult: () => "denied" })
748
+ }, {
749
+ target: "#selfie.tutorial.ready",
750
+ actions: assign({ error: ({ event }) => String(event.error) })
751
+ }]
752
+ } },
753
+ ready: { type: "final" }
754
+ }
663
755
  },
664
- waitingForStream: { always: [{
665
- target: "#selfie.capture",
666
- guard: "isCameraAndDeepsightReady"
667
- }] }
668
- }
669
- },
670
- cameraReady: {
671
- id: "tutorialCameraReady",
672
- on: { NEXT_STEP: {
673
- target: "#selfie.capture",
674
- actions: "trackContinue"
675
- } }
756
+ userIntent: {
757
+ initial: "waiting",
758
+ states: {
759
+ waiting: { on: { NEXT_STEP: {
760
+ target: "clicked",
761
+ actions: "trackContinue"
762
+ } } },
763
+ clicked: { type: "final" }
764
+ }
765
+ }
766
+ },
767
+ onDone: { target: "#selfie.capture" }
676
768
  },
677
769
  ready: {
678
770
  initial: "idle",
679
771
  states: {
680
772
  idle: { always: [{
681
773
  target: "initializingDeepsight",
682
- guard: ({ context }) => context.config.deepsightLiveness === "VIDEOLIVENESS"
774
+ guard: ({ context }) => context.deepsightService === void 0
683
775
  }, { target: "readyForNext" }] },
684
776
  initializingDeepsight: { invoke: {
685
777
  id: "initializeDeepsightTutorial",
686
778
  src: "initializeDeepsightSession",
687
- input: ({ context }) => ({ config: context.config }),
688
779
  onDone: {
689
780
  target: "readyForNext",
690
781
  actions: assign({ deepsightService: ({ event }) => event.output })
@@ -716,12 +807,11 @@ const _selfieMachine = setup({
716
807
  states: {
717
808
  checkingDeepsight: { always: [{
718
809
  target: "initializingDeepsight",
719
- guard: ({ context }) => context.config.deepsightLiveness === "VIDEOLIVENESS" && context.deepsightService === void 0
810
+ guard: ({ context }) => context.deepsightService === void 0
720
811
  }, { target: "idle" }] },
721
812
  initializingDeepsight: { invoke: {
722
813
  id: "initializeDeepsightPerms",
723
814
  src: "initializeDeepsightSession",
724
- input: ({ context }) => ({ config: context.config }),
725
815
  onDone: {
726
816
  target: "idle",
727
817
  actions: assign({ deepsightService: ({ event }) => event.output })
@@ -778,35 +868,43 @@ const _selfieMachine = setup({
778
868
  capture: {
779
869
  initial: "checkingDeepsight",
780
870
  exit: [
781
- "stopMediaRecording",
782
- "stopRecordingStream",
783
- "clearRecordingSession",
784
871
  "stopMediaStream",
785
- "cleanupDeepsight"
872
+ "cleanup",
873
+ "clearRecordingService"
786
874
  ],
787
875
  states: {
788
876
  checkingDeepsight: { always: [{
789
877
  target: "initializingDeepsight",
790
- guard: ({ context }) => context.config.deepsightLiveness === "VIDEOLIVENESS" && context.deepsightService === void 0
878
+ guard: ({ context }) => context.deepsightService === void 0
791
879
  }, { target: "checkingStream" }] },
792
880
  initializingDeepsight: { invoke: {
793
881
  id: "initializeDeepsightCapture",
794
882
  src: "initializeDeepsightSession",
795
- input: ({ context }) => ({ config: context.config }),
796
883
  onDone: {
797
884
  target: "checkingStream",
798
885
  actions: [assign({ deepsightService: ({ event }) => event.output })]
799
886
  },
800
- onError: { target: "checkingStream" }
887
+ onError: { target: "#selfie.permissions" }
801
888
  } },
802
- checkingStream: { always: [{
803
- target: "detecting",
804
- guard: "hasStream"
805
- }, { target: "initializing" }] },
889
+ checkingStream: { always: [
890
+ {
891
+ target: "initializingDeepsight",
892
+ guard: ({ context }) => context.deepsightService === void 0
893
+ },
894
+ {
895
+ target: "detecting",
896
+ guard: "hasStream"
897
+ },
898
+ { target: "initializing" }
899
+ ] },
806
900
  initializing: { invoke: {
807
901
  id: "initializeCamera",
808
902
  src: "initializeCamera",
809
- input: ({ context }) => context.config,
903
+ input: ({ context }) => ({
904
+ config: context.config,
905
+ dependencies: context.dependencies,
906
+ deepsightService: context.deepsightService
907
+ }),
810
908
  onDone: {
811
909
  target: "detecting",
812
910
  actions: ["setStreamAndCapturer"]
@@ -821,33 +919,48 @@ const _selfieMachine = setup({
821
919
  }]
822
920
  } },
823
921
  detecting: {
824
- entry: [
825
- assign({ detectionStatus: () => "detecting" }),
826
- "createRecordingStream",
827
- "checkVirtualCamera",
828
- "startDeepsightRecording"
922
+ entry: [assign({ detectionStatus: () => "detecting" })],
923
+ invoke: [
924
+ {
925
+ id: "checkVirtualCamera",
926
+ src: "checkVirtualCamera",
927
+ input: ({ context }) => ({
928
+ stream: context.stream,
929
+ deepsightService: context.deepsightService
930
+ }),
931
+ onDone: [{
932
+ target: "#selfie.processing",
933
+ guard: ({ event }) => event.output === true,
934
+ actions: () => {
935
+ sendLabelInspectionEvent();
936
+ }
937
+ }],
938
+ onError: { actions: () => void 0 }
939
+ },
940
+ {
941
+ id: "startRecording",
942
+ src: "startRecording",
943
+ input: ({ context }) => ({
944
+ config: context.config,
945
+ dependencies: context.dependencies,
946
+ recordingService: context.recordingService,
947
+ stream: context.stream
948
+ }),
949
+ onDone: { actions: assign({ recordingService: ({ context, event }) => {
950
+ return event.output ?? context.recordingService;
951
+ } }) },
952
+ onError: { actions: () => void 0 }
953
+ },
954
+ {
955
+ id: "runDetection",
956
+ src: "runDetection",
957
+ input: ({ context }) => ({
958
+ frameCapturer: context.frameCapturer,
959
+ provider: context.provider,
960
+ config: context.config
961
+ })
962
+ }
829
963
  ],
830
- invoke: [{
831
- id: "startRecording",
832
- src: "startRecording",
833
- input: ({ context }) => ({
834
- config: context.config,
835
- clonedStream: context.recordingStream,
836
- existing: context.recordingSession
837
- }),
838
- onDone: { actions: assign({ recordingSession: ({ context, event }) => {
839
- return event.output ?? context.recordingSession;
840
- } }) },
841
- onError: { actions: () => void 0 }
842
- }, {
843
- id: "runDetection",
844
- src: "runDetection",
845
- input: ({ context }) => ({
846
- frameCapturer: context.frameCapturer,
847
- provider: context.provider,
848
- config: context.config
849
- })
850
- }],
851
964
  on: {
852
965
  DETECTION_UPDATE: { actions: assign({ detectionStatus: ({ event }) => event.status }) },
853
966
  DETECTION_FRAME: { actions: assign({ debugFrame: ({ event }) => event.frame }) },
@@ -897,7 +1010,9 @@ const _selfieMachine = setup({
897
1010
  return {
898
1011
  canvas,
899
1012
  faceCoordinates: context.faceCoordinates,
900
- deepsightService: context.deepsightService
1013
+ deepsightService: context.deepsightService,
1014
+ dependencies: context.dependencies,
1015
+ recordingService: context.recordingService
901
1016
  };
902
1017
  },
903
1018
  onDone: {
@@ -918,12 +1033,16 @@ const _selfieMachine = setup({
918
1033
  actions: ["setUploadErrorFromUploadValidation", "decrementAttemptsRemaining"]
919
1034
  }, { target: "success" }] },
920
1035
  uploadError: { on: { RETRY_CAPTURE: {
921
- target: "detecting",
1036
+ target: "checkingStream",
922
1037
  guard: "hasAttemptsRemaining",
923
- actions: ["resetDetection", "clearUploadFailure"]
1038
+ actions: [
1039
+ "resetDetection",
1040
+ "clearUploadFailure",
1041
+ "clearStreamForRetry"
1042
+ ]
924
1043
  } } },
925
1044
  success: {
926
- entry: "stopMediaRecording",
1045
+ entry: "cleanup",
927
1046
  after: { 3e3: { target: "#selfie.processing" } }
928
1047
  }
929
1048
  }
@@ -939,10 +1058,7 @@ const _selfieMachine = setup({
939
1058
  } },
940
1059
  finished: {
941
1060
  entry: "stopMediaStream",
942
- on: { RESET: {
943
- target: "idle",
944
- actions: "resetContext"
945
- } }
1061
+ type: "final"
946
1062
  },
947
1063
  closed: {
948
1064
  entry: "stopMediaStream",
@@ -968,7 +1084,14 @@ const selfieMachine = _selfieMachine;
968
1084
  //#endregion
969
1085
  //#region src/modules/selfie/selfieActor.ts
970
1086
  function createSelfieActor(options) {
971
- return createActor(selfieMachine, { input: { config: options.config } }).start();
1087
+ const dependencies = options.dependencies ?? {
1088
+ storage: new BrowserStorageProvider(),
1089
+ getWasmUtil: () => WasmUtilProvider.getInstance()
1090
+ };
1091
+ return createActor(selfieMachine, { input: {
1092
+ config: options.config,
1093
+ dependencies
1094
+ } }).start();
972
1095
  }
973
1096
 
974
1097
  //#endregion