@incodetech/core 0.0.0-dev-20260402-682edb5 → 0.0.0-dev-20260402-7cf9db4
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-phIcsUhv.d.ts +2 -0
- package/dist/BaseWasmProvider-BFXU7jj8.esm.js +1536 -0
- package/dist/BrowserEnvironmentProvider-DApG6lNu.esm.js +89 -0
- package/dist/BrowserTimerProvider-CRhCvln7.esm.js +22 -0
- package/dist/Manager-BndLda4_.d.ts +19 -0
- package/dist/{events-Cc1xUUgF.esm.js → Manager-D_DMzMWz.esm.js} +114 -11
- package/dist/{warmup-CzfSiaMj.d.ts → StateMachine-CGAi8x_b.d.ts} +4 -1
- package/dist/StreamCanvasCapture-9VAzOfOv.esm.js +410 -0
- package/dist/WasmUtilProvider-DctESPCy.esm.js +114 -0
- package/dist/{addressSearch-DzOdaNEA.esm.js → addressSearch-CYGzuJJ3.esm.js} +3 -3
- package/dist/authentication.d.ts +9 -7
- package/dist/authentication.esm.js +12 -10
- package/dist/{authenticationManager-TaI12wf3.d.ts → authenticationManager-B5Yv9bDw.d.ts} +2 -2
- package/dist/{authenticationManager-CBSPCdJc.esm.js → authenticationManager-C9iQ1d2a.esm.js} +5 -5
- package/dist/{backCameraStream-BGAbuvw1.esm.js → backCameraStream-BJwEXNl4.esm.js} +2 -1
- package/dist/camera-D-MPXRbZ.esm.js +22 -0
- package/dist/camera-Dv2WEhGe.d.ts +4 -0
- package/dist/consent.d.ts +55 -54
- package/dist/consent.esm.js +2 -3
- package/dist/curp-validation.d.ts +5 -3
- package/dist/curp-validation.esm.js +2 -3
- package/dist/deepsightLoader-D2MKmB5z.esm.js +48 -0
- package/dist/{deepsightService-DxA--87N.d.ts → deepsightService-CWnhwXLw.d.ts} +223 -17
- package/dist/document-capture.d.ts +58 -56
- package/dist/document-capture.esm.js +5 -4
- package/dist/document-upload.d.ts +47 -45
- package/dist/document-upload.esm.js +5 -4
- package/dist/ekyb.d.ts +3 -2
- package/dist/ekyb.esm.js +8 -7
- package/dist/ekyc.d.ts +3 -2
- package/dist/ekyc.esm.js +133 -123
- package/dist/email.d.ts +3 -2
- package/dist/email.esm.js +4 -4
- package/dist/{emailManager-DN_q_zxy.d.ts → emailManager-BIq6pJa8.d.ts} +11 -4
- package/dist/{emailManager-DSR9gQLX.esm.js → emailManager-C5GCSw78.esm.js} +43 -23
- package/dist/extensibility.d.ts +45 -43
- package/dist/extensibility.esm.js +26 -15
- package/dist/face-match.d.ts +1 -1
- package/dist/face-match.esm.js +2 -3
- package/dist/{faceCaptureManagerFactory-CGpkO_S3.d.ts → faceCaptureManagerFactory-CN5-GRxP.d.ts} +89 -142
- package/dist/{faceCaptureSetup-Rr7LUbBm.esm.js → faceCaptureSetup-DYRykM5Y.esm.js} +413 -7
- package/dist/flow.d.ts +6 -5
- package/dist/flow.esm.js +7 -7
- package/dist/{flowCompletionService-Bkaerugt.esm.js → flowCompletionService-CBvXiMKa.esm.js} +1 -1
- package/dist/{flowServices-Bt6lMLUI.esm.js → flowServices-CQ3rTJLE.esm.js} +2 -2
- package/dist/geolocation.d.ts +2 -1
- package/dist/geolocation.esm.js +16 -3
- package/dist/government-validation.d.ts +2 -1
- package/dist/government-validation.esm.js +3 -3
- package/dist/id.d.ts +9 -6
- package/dist/id.esm.js +14 -11
- package/dist/{idCaptureManager-Dc2NJMy_.d.ts → idCaptureManager-B1RWflj0.d.ts} +15 -12
- package/dist/{idCaptureManager-QyM4nIKM.esm.js → idCaptureManager-D5rjCu9r.esm.js} +178 -8
- package/dist/index.d.ts +68 -21
- package/dist/index.esm.js +440 -11
- package/dist/mandatory-consent.d.ts +58 -56
- package/dist/mandatory-consent.esm.js +2 -3
- package/dist/phone.d.ts +3 -2
- package/dist/phone.esm.js +4 -4
- package/dist/{phoneManager-D2A0hXXq.d.ts → phoneManager-Ba66ysK2.d.ts} +9 -2
- package/dist/{phoneManager-D2nZtu-b.esm.js → phoneManager-CQJim-Ky.esm.js} +32 -21
- package/dist/platform-B3nGssGZ.esm.js +83 -0
- package/dist/redirect-to-mobile.d.ts +2 -1
- package/dist/redirect-to-mobile.esm.js +3 -3
- package/dist/selfie.d.ts +9 -7
- package/dist/selfie.esm.js +12 -10
- package/dist/{selfieManager-B4Nnp7ws.d.ts → selfieManager-BnfnTPcx.d.ts} +2 -2
- package/dist/{selfieManager-CvE35L72.esm.js → selfieManager-DYW1C2GP.esm.js} +4 -3
- package/dist/session-TBPhHmyy.esm.js +3130 -0
- package/dist/session.d.ts +1 -1
- package/dist/session.esm.js +2 -2
- package/dist/signature.d.ts +3 -3
- package/dist/signature.esm.js +3 -4
- package/dist/{stats-D0m3TvIg.esm.js → stats-D4C7iDy1.esm.js} +1 -1
- package/dist/stats.esm.js +2 -2
- package/dist/{types-oveF7RrS.d.ts → types-BWGxcjiZ.d.ts} +1 -1
- package/dist/{types-mQLzH6uw.d.ts → types-BX1ZlbSR.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/deepsightLoader-B93Oa9pS.esm.js +0 -24
- package/dist/deepsightService-CLUMQ5ee.esm.js +0 -235
- package/dist/index-BTaLQSj9.d.ts +0 -219
- package/dist/recordingsRepository-Djt_In2b.esm.js +0 -122
- package/dist/session-CUy9-Yzi.esm.js +0 -250
- package/dist/src-8rn6DoH7.esm.js +0 -6554
- /package/dist/{api-G4JA8CXK.esm.js → api-3fZO5bmj.esm.js} +0 -0
- /package/dist/{browserSimulation-C8gNnn5p.esm.js → browserSimulation-zWJAZ1vA.esm.js} +0 -0
- /package/dist/{displayErrors-BgtBHbfb.d.ts → displayErrors-DzzB3fcR.d.ts} +0 -0
- /package/dist/{flowCompletionService-De8JDo87.d.ts → flowCompletionService-C_CShl_d.d.ts} +0 -0
- /package/dist/{id-B30uqGbp.esm.js → id-Dv0it9CY.esm.js} +0 -0
- /package/dist/{index-LKrIp3Oo.d.ts → index-CuY8tqBC.d.ts} +0 -0
- /package/dist/{lib-qeMam2F_.esm.js → lib-B5byelWf.esm.js} +0 -0
|
@@ -0,0 +1,1536 @@
|
|
|
1
|
+
import { t as isBrowserSimulation } from "./browserSimulation-zWJAZ1vA.esm.js";
|
|
2
|
+
import { t as api } from "./api-3fZO5bmj.esm.js";
|
|
3
|
+
import { i as stopCameraStream, r as requestCameraAccess } from "./camera-D-MPXRbZ.esm.js";
|
|
4
|
+
import { t as addDeviceStats } from "./stats-D4C7iDy1.esm.js";
|
|
5
|
+
|
|
6
|
+
//#region ../infra/src/wasm/IdCaptureModelType.ts
|
|
7
|
+
let IdCaptureModelType = /* @__PURE__ */ function(IdCaptureModelType$1) {
|
|
8
|
+
IdCaptureModelType$1[IdCaptureModelType$1["IdCaptureV1x"] = 0] = "IdCaptureV1x";
|
|
9
|
+
IdCaptureModelType$1[IdCaptureModelType$1["IdCaptureV2x"] = 1] = "IdCaptureV2x";
|
|
10
|
+
IdCaptureModelType$1[IdCaptureModelType$1["IdCaptureV3x"] = 2] = "IdCaptureV3x";
|
|
11
|
+
return IdCaptureModelType$1;
|
|
12
|
+
}({});
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region ../infra/src/wasm/Mutex.ts
|
|
16
|
+
var Semaphore = class {
|
|
17
|
+
constructor(maxConcurrent = 1) {
|
|
18
|
+
this.maxConcurrent = maxConcurrent;
|
|
19
|
+
this.current = 0;
|
|
20
|
+
this.queue = [];
|
|
21
|
+
}
|
|
22
|
+
async acquire() {
|
|
23
|
+
if (this.current < this.maxConcurrent) {
|
|
24
|
+
this.current++;
|
|
25
|
+
return Promise.resolve();
|
|
26
|
+
}
|
|
27
|
+
return new Promise((resolve) => {
|
|
28
|
+
this.queue.push(resolve);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
release() {
|
|
32
|
+
this.current = Math.max(0, this.current - 1);
|
|
33
|
+
if (this.queue.length > 0 && this.current < this.maxConcurrent) {
|
|
34
|
+
this.current++;
|
|
35
|
+
const next = this.queue.shift();
|
|
36
|
+
if (next) next();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var Mutex = class {
|
|
41
|
+
constructor() {
|
|
42
|
+
this.semaphore = new Semaphore(1);
|
|
43
|
+
}
|
|
44
|
+
async lock() {
|
|
45
|
+
return this.semaphore.acquire();
|
|
46
|
+
}
|
|
47
|
+
unlock() {
|
|
48
|
+
this.semaphore.release();
|
|
49
|
+
}
|
|
50
|
+
async withLock(fn, ...args) {
|
|
51
|
+
await this.lock();
|
|
52
|
+
try {
|
|
53
|
+
return await fn(...args);
|
|
54
|
+
} finally {
|
|
55
|
+
this.unlock();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region ../infra/src/wasm/WasmPipelineType.ts
|
|
62
|
+
let WasmPipelineType = /* @__PURE__ */ function(WasmPipelineType$1) {
|
|
63
|
+
WasmPipelineType$1[WasmPipelineType$1["IdBlurGlarePipeline"] = 0] = "IdBlurGlarePipeline";
|
|
64
|
+
WasmPipelineType$1[WasmPipelineType$1["IdBarcodeAndTextQualityPipeline"] = 1] = "IdBarcodeAndTextQualityPipeline";
|
|
65
|
+
WasmPipelineType$1[WasmPipelineType$1["IdVideoSelfiePipeline"] = 2] = "IdVideoSelfiePipeline";
|
|
66
|
+
WasmPipelineType$1[WasmPipelineType$1["SelfieWithAggregationMetrics"] = 3] = "SelfieWithAggregationMetrics";
|
|
67
|
+
WasmPipelineType$1[WasmPipelineType$1["SelfieWithQualityMetrics"] = 4] = "SelfieWithQualityMetrics";
|
|
68
|
+
WasmPipelineType$1[WasmPipelineType$1["IdFaceDetectionPipeline"] = 5] = "IdFaceDetectionPipeline";
|
|
69
|
+
return WasmPipelineType$1;
|
|
70
|
+
}({});
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region ../infra/src/wasm/mlWasmJSApi.ts
|
|
74
|
+
window.wasmArrayBuffer = null;
|
|
75
|
+
var MlWasmJSApi = class MlWasmJSApi {
|
|
76
|
+
constructor() {
|
|
77
|
+
this.versionsFile = null;
|
|
78
|
+
this.modelsBuffers = null;
|
|
79
|
+
this.inputImageBuffer = null;
|
|
80
|
+
this.wasmModule = null;
|
|
81
|
+
this.pipelineApiUtilities = null;
|
|
82
|
+
this.utilityApi = null;
|
|
83
|
+
this.idCaptureWasmApi = null;
|
|
84
|
+
this.faceDetectionWasmApi = null;
|
|
85
|
+
this.imageWidth_ = null;
|
|
86
|
+
this.imageHeight_ = null;
|
|
87
|
+
this.pipelines_ = null;
|
|
88
|
+
this.isInitialized_ = false;
|
|
89
|
+
this.inspectorOpened_ = false;
|
|
90
|
+
this.wasmCallMutex = new Mutex();
|
|
91
|
+
this.Module = null;
|
|
92
|
+
this.loadModule = async (glueCodePath) => {
|
|
93
|
+
this.Module = (await import(
|
|
94
|
+
/* @vite-ignore */
|
|
95
|
+
/* webpackIgnore: true */
|
|
96
|
+
glueCodePath
|
|
97
|
+
)).Module;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Initiallization method, use it when the application starts
|
|
102
|
+
* TODO: this method can return the list of promises to be awaited together with other initialization code
|
|
103
|
+
* @param {string} webLibPath - The path to the webassembly binary
|
|
104
|
+
* @param {string} webLibPathSimd - The path to the SIMD version webassembly binary
|
|
105
|
+
* @param {boolean} useSimd - Indicates whether SIMD optimizations should be used
|
|
106
|
+
* @param {string} versionsFile - The path to the file containing versioning information
|
|
107
|
+
* @param {Map.<WasmPipelineType, Array<string>>} pipelines - pipelines for initialization and corresponding models paths
|
|
108
|
+
* @returns {Promise<boolean>} A promise that resolves to a boolean indicating whether SIMD is enabled once the initialization is complete.
|
|
109
|
+
* @throws {Error} Throws an error if the initialization fails.
|
|
110
|
+
*/
|
|
111
|
+
async initialize(webLibPath, webLibPathSimd, glueCodePath, useSimd, versionsFile, pipelines) {
|
|
112
|
+
await this.freeResources();
|
|
113
|
+
this.pipelines_ = pipelines;
|
|
114
|
+
this.versionsFile = versionsFile;
|
|
115
|
+
await this.loadModule(glueCodePath);
|
|
116
|
+
const simdIsEnabled = await this.loadWasm(useSimd, webLibPath, webLibPathSimd);
|
|
117
|
+
this.pipelineApiUtilities = new this.wasmModule.PipelineApiUtilities();
|
|
118
|
+
this.utilityApi = new this.wasmModule.UtilityApi();
|
|
119
|
+
this.idCaptureWasmApi = new this.wasmModule.IdCaptureApi();
|
|
120
|
+
this.faceDetectionWasmApi = new this.wasmModule.FaceDetectionApi();
|
|
121
|
+
this.isInitialized_ = true;
|
|
122
|
+
return simdIsEnabled;
|
|
123
|
+
}
|
|
124
|
+
static getInstance() {
|
|
125
|
+
if (!MlWasmJSApi.instance) MlWasmJSApi.instance = new MlWasmJSApi();
|
|
126
|
+
return MlWasmJSApi.instance;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Returns initialization status
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
132
|
+
isInitialized() {
|
|
133
|
+
return this.pipelineApiUtilities != null && this.utilityApi != null && this.idCaptureWasmApi != null && this.faceDetectionWasmApi != null && this.isInitialized_;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Allocate shared memory for image buffers (RGBA format)
|
|
137
|
+
* Use it every time when the frame dimentions changes
|
|
138
|
+
* @param {number} imageWidth - image width
|
|
139
|
+
* @param {number} imageHeight - image height
|
|
140
|
+
*/
|
|
141
|
+
async allocateImageBuffers(imageWidth, imageHeight) {
|
|
142
|
+
this.checkWasmInitialization("Unable to allocate image buffers, cpp API hasn't been initialized");
|
|
143
|
+
if (imageWidth && imageHeight && imageWidth == this.imageWidth_ && imageHeight == this.imageHeight_ && this.inputImageBuffer && imageWidth * imageHeight * 4 === this.inputImageBuffer.length) return;
|
|
144
|
+
this.imageWidth_ = imageWidth;
|
|
145
|
+
this.imageHeight_ = imageHeight;
|
|
146
|
+
this.inputImageBuffer = this.pipelineApiUtilities.allocateInputImageBuffer(imageWidth, imageHeight, 4);
|
|
147
|
+
}
|
|
148
|
+
async handleDetectionCallAndUpdateState(type) {
|
|
149
|
+
this.checkWasmInitialization("Unable to update pipeline state, cpp API hasn't been initialized");
|
|
150
|
+
this.pipelineApiUtilities.handleDetectionCallAndUpdateState(this.pipelineTypeToWasmEnum(type));
|
|
151
|
+
}
|
|
152
|
+
ens(image) {
|
|
153
|
+
this.checkWasmInitialization("Unable to encrypt the image, cpp API hasn't been initialized");
|
|
154
|
+
return this.utilityApi.ens(image);
|
|
155
|
+
}
|
|
156
|
+
isVirtualCamera(label) {
|
|
157
|
+
this.checkWasmInitialization("Unable to check if the camera is virtual, cpp API hasn't been initialized");
|
|
158
|
+
if (label) return this.utilityApi.isVirtualCamera(label);
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
estimatePerformance() {
|
|
162
|
+
this.checkWasmInitialization("Unable to estimate performance, cpp API hasn't been initialized");
|
|
163
|
+
return this.utilityApi.estimatePerformance();
|
|
164
|
+
}
|
|
165
|
+
async analyzeFrame(image) {
|
|
166
|
+
this.checkWasmInitialization("Unable to analyze the frame, cpp API hasn't been initialized");
|
|
167
|
+
await this.allocateImageBuffers(image.width, image.height);
|
|
168
|
+
this.inputImageBuffer.set(image.data);
|
|
169
|
+
this.utilityApi.analyzeFrame();
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Free allocated memory
|
|
173
|
+
*/
|
|
174
|
+
async freeResources() {
|
|
175
|
+
this.versionsFile = null;
|
|
176
|
+
this.modelsBuffers = null;
|
|
177
|
+
this.inputImageBuffer = null;
|
|
178
|
+
this.imageWidth_ = null;
|
|
179
|
+
this.imageHeight_ = null;
|
|
180
|
+
this.pipelines_ = null;
|
|
181
|
+
window.wasmArrayBuffer = null;
|
|
182
|
+
if (this.pipelineApiUtilities && typeof this.pipelineApiUtilities.delete === "function") {
|
|
183
|
+
this.pipelineApiUtilities.delete();
|
|
184
|
+
this.pipelineApiUtilities = null;
|
|
185
|
+
}
|
|
186
|
+
if (this.utilityApi && typeof this.utilityApi.delete === "function") {
|
|
187
|
+
this.utilityApi.delete();
|
|
188
|
+
this.utilityApi = null;
|
|
189
|
+
}
|
|
190
|
+
if (this.idCaptureWasmApi && typeof this.idCaptureWasmApi.delete === "function") {
|
|
191
|
+
this.idCaptureWasmApi.delete();
|
|
192
|
+
this.idCaptureWasmApi = null;
|
|
193
|
+
}
|
|
194
|
+
if (this.faceDetectionWasmApi && typeof this.faceDetectionWasmApi.delete === "function") {
|
|
195
|
+
this.faceDetectionWasmApi.delete();
|
|
196
|
+
this.faceDetectionWasmApi = null;
|
|
197
|
+
}
|
|
198
|
+
this.wasmModule = null;
|
|
199
|
+
this.isInitialized_ = false;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Clear pipeline state
|
|
203
|
+
*/
|
|
204
|
+
resetPipeline(type) {
|
|
205
|
+
this.checkWasmInitialization("Unable to reset pipeline, cpp API hasn't been initialized");
|
|
206
|
+
this.pipelineApiUtilities.resetPipeline(this.pipelineTypeToWasmEnum(type));
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Clear all pipelines states
|
|
210
|
+
*/
|
|
211
|
+
resetAllPipelines() {
|
|
212
|
+
this.checkWasmInitialization("Unable to reset pipelines, cpp API hasn't been initialized");
|
|
213
|
+
for (const [type, model] of this.pipelines_) this.resetPipeline(type);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Clear all states, not related to ml pipelines
|
|
217
|
+
*/
|
|
218
|
+
resetOther() {
|
|
219
|
+
this.checkWasmInitialization("Unable to reset other states, cpp API hasn't been initialized");
|
|
220
|
+
this.utilityApi.resetOther();
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Full reset
|
|
224
|
+
*/
|
|
225
|
+
reset() {
|
|
226
|
+
this.resetAllPipelines();
|
|
227
|
+
this.resetOther();
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Process one frame using one of the pipelines
|
|
231
|
+
* @param {ImageData} image - input image
|
|
232
|
+
* @param {WasmPipelineType} type - pipeline type
|
|
233
|
+
* @returns
|
|
234
|
+
*/
|
|
235
|
+
async process(image, type) {
|
|
236
|
+
this.checkWasmInitialization("Unable to process the image, cpp API hasn't been initialized");
|
|
237
|
+
if (this.inputImageBuffer === null) throw new Error("Unable to process the image, buffers haven't been allocated!");
|
|
238
|
+
this.inputImageBuffer.set(image.data);
|
|
239
|
+
switch (type) {
|
|
240
|
+
case WasmPipelineType.IdBlurGlarePipeline:
|
|
241
|
+
case WasmPipelineType.IdBarcodeAndTextQualityPipeline: return this.idCaptureWasmApi.runIdCapturePipeline(this.pipelineTypeToWasmEnum(type));
|
|
242
|
+
case WasmPipelineType.IdFaceDetectionPipeline: return this.faceDetectionWasmApi.runIdFaceDetectionPipeline();
|
|
243
|
+
case WasmPipelineType.IdVideoSelfiePipeline: return this.idCaptureWasmApi.runIdVideoSelfiePipeline();
|
|
244
|
+
case WasmPipelineType.SelfieWithAggregationMetrics:
|
|
245
|
+
case WasmPipelineType.SelfieWithQualityMetrics: return this.faceDetectionWasmApi.runSelfieFaceDetectionPipeline(this.pipelineTypeToWasmEnum(type));
|
|
246
|
+
default: throw new Error("Unknown pipeline type");
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
async runIdCapture(image) {
|
|
250
|
+
this.checkWasmInitialization("Unable to run Id Capture, cpp API hasn't been initialized");
|
|
251
|
+
if (this.inputImageBuffer === null) throw new Error("Unable to process the image, buffers haven't been allocated!");
|
|
252
|
+
this.inputImageBuffer.set(image.data);
|
|
253
|
+
return this.idCaptureWasmApi.runIdCapture();
|
|
254
|
+
}
|
|
255
|
+
async runSelfieCapture(image) {
|
|
256
|
+
this.checkWasmInitialization("Unable to run Selfie Capture, cpp API hasn't been initialized");
|
|
257
|
+
if (this.inputImageBuffer === null) throw new Error("Unable to process the image, buffers haven't been allocated!");
|
|
258
|
+
this.inputImageBuffer.set(image.data);
|
|
259
|
+
return this.faceDetectionWasmApi.runSelfieCapture();
|
|
260
|
+
}
|
|
261
|
+
async setFacePositionConstraints(type, minX, minY, maxX, maxY) {
|
|
262
|
+
this.checkWasmInitialization("Unable to set face position constraints, cpp API hasn't been initialized");
|
|
263
|
+
this.faceDetectionWasmApi.setFacePositionConstraints(this.pipelineTypeToWasmEnum(type), minX, minY, maxX, maxY);
|
|
264
|
+
}
|
|
265
|
+
async setFaceDetectionThresholds(type, brightnessThreshold, blurrinessThreshold, tiltRotationAngleThreshold, minMagicCropSize, autocaptureInterval, minFaceQualityScore, faceOcclusionThreshold) {
|
|
266
|
+
this.checkWasmInitialization("Unable to set face detection thresholds, cpp API hasn't been initialized");
|
|
267
|
+
this.faceDetectionWasmApi.setFaceDetectionThresholds(this.pipelineTypeToWasmEnum(type), brightnessThreshold, blurrinessThreshold, tiltRotationAngleThreshold, minMagicCropSize, autocaptureInterval, minFaceQualityScore, faceOcclusionThreshold);
|
|
268
|
+
}
|
|
269
|
+
async setFaceAttributesThresholds(type, headwearThreshold, lensesThreshold, closedEyesThreshold, maskThreshold) {
|
|
270
|
+
this.checkWasmInitialization("Unable to set face attributes thresholds, cpp API hasn't been initialized");
|
|
271
|
+
this.faceDetectionWasmApi.setFaceAttributesThresholds(this.pipelineTypeToWasmEnum(type), headwearThreshold, lensesThreshold, closedEyesThreshold, maskThreshold);
|
|
272
|
+
}
|
|
273
|
+
async setFaceChecksEnabled(type, isLensesCheckEnabled, isMaskCheckEnabled, isClosedEyesCheckEnabled, isHeadWearCheckEnabled, isOcclusionCheckEnabled) {
|
|
274
|
+
this.checkWasmInitialization("Unable to set face checks enabled flags, cpp API hasn't been initialized");
|
|
275
|
+
this.faceDetectionWasmApi.setFaceChecksEnabled(this.pipelineTypeToWasmEnum(type), isLensesCheckEnabled, isMaskCheckEnabled, isClosedEyesCheckEnabled, isHeadWearCheckEnabled, isOcclusionCheckEnabled);
|
|
276
|
+
}
|
|
277
|
+
async setFaceDetectionMode(type, isVideoSelfie) {
|
|
278
|
+
this.checkWasmInitialization("Unable to set face detection mode, cpp API hasn't been initialized");
|
|
279
|
+
this.faceDetectionWasmApi.setFaceDetectionMode(this.pipelineTypeToWasmEnum(type), isVideoSelfie);
|
|
280
|
+
}
|
|
281
|
+
async setFaceDetectionCallbacks(type, onFarAway, onTooClose, onTooManyFaces, onNoFace, onCapture, onGetReady, onGetReadyFinished, onCenterFace, onDark, onBlur, onFaceAngle, onBestShot, onLenses, onMask, onEyesClosed, onHeadWear, onSwitchToManualCapture, onFaceOccluded) {
|
|
282
|
+
this.checkWasmInitialization("Unable to set face detection callbacks, cpp API hasn't been initialized");
|
|
283
|
+
this.faceDetectionWasmApi.setFaceDetectionCallbacks(this.pipelineTypeToWasmEnum(type), onFarAway, onTooClose, onTooManyFaces, onNoFace, onCapture, onGetReady, onGetReadyFinished, onCenterFace, onDark, onBlur, onFaceAngle, onBestShot, onLenses, onMask, onEyesClosed, onHeadWear, onSwitchToManualCapture, onFaceOccluded);
|
|
284
|
+
}
|
|
285
|
+
async setIdCaptureThresholds(type, blurThreshold, blurChangeThreshold, glareThreshold, clsThreshold, sideThreshold, iouThreshold, idDetectedTimeout, autocaptureTimeout, framesAggregationInterval, minFaceIdQualityScore) {
|
|
286
|
+
this.checkWasmInitialization("Unable to set thresholds, cpp API hasn't been initialized");
|
|
287
|
+
this.idCaptureWasmApi.setIdCaptureThresholds(this.pipelineTypeToWasmEnum(type), blurThreshold, blurChangeThreshold, glareThreshold, clsThreshold, sideThreshold, iouThreshold, idDetectedTimeout, autocaptureTimeout, framesAggregationInterval, minFaceIdQualityScore);
|
|
288
|
+
}
|
|
289
|
+
async setIdCaptureCallbacks(type, onFarAway, onDetectionStarted, onMaskChange, onBlur, onGlare, onCapturing, onCapture, onBestFrame, onIDNotDetected, onSwitchToManualCapture, onIDTypeChange, onIDSideChange, onCapturingCounterValueChange) {
|
|
290
|
+
this.checkWasmInitialization("Unable to set callbacks, cpp API hasn't been initialized");
|
|
291
|
+
this.idCaptureWasmApi.setIdCaptureCallbacks(this.pipelineTypeToWasmEnum(type), onFarAway, onDetectionStarted, onMaskChange, onBlur, onGlare, onCapturing, onCapture, onBestFrame, onIDNotDetected, onSwitchToManualCapture, onIDTypeChange, onIDSideChange, onCapturingCounterValueChange);
|
|
292
|
+
}
|
|
293
|
+
async setIdCaptureGeometryParams(type, areaDown, areaUp, areaIOSPassportUp, areaIOSPassportDown, widthIOSUp, widthIOSDown, widthDown, widthUp, windowOuterWidth, windowOuterHeight, windowInnerWidth, windowInnerHeight) {
|
|
294
|
+
this.checkWasmInitialization("Unable to set geometry params, cpp API hasn't been initialized");
|
|
295
|
+
this.idCaptureWasmApi.setIdCaptureGeometryParams(this.pipelineTypeToWasmEnum(type), areaDown, areaUp, areaIOSPassportUp, areaIOSPassportDown, widthIOSUp, widthIOSDown, widthDown, widthUp, windowOuterWidth, windowOuterHeight, windowInnerWidth, windowInnerHeight);
|
|
296
|
+
}
|
|
297
|
+
async setIdCaptureConfigParams(type, isFixedMask, isIPhone14OrHigher, idType, isBlurCheckEnabled, isGlareCheckEnabled, isIdFaceQualityCheckEnabled, isIouCheckEnabled, isFPSLimitEnabled) {
|
|
298
|
+
this.checkWasmInitialization("Unable to set config params, cpp API hasn't been initialized");
|
|
299
|
+
this.idCaptureWasmApi.setIdCaptureConfigParams(this.pipelineTypeToWasmEnum(type), isFixedMask, isIPhone14OrHigher, idType, isBlurCheckEnabled, isGlareCheckEnabled, isIdFaceQualityCheckEnabled, isIouCheckEnabled, isFPSLimitEnabled);
|
|
300
|
+
}
|
|
301
|
+
setIdCaptureModelType(pipelineType, modelType) {
|
|
302
|
+
this.checkWasmInitialization("Unable to set model type, cpp API hasn't been initialized");
|
|
303
|
+
this.idCaptureWasmApi.setIdCaptureModelType(this.pipelineTypeToWasmEnum(pipelineType), this.IdCaptureModelTypeToWasmEnum(modelType));
|
|
304
|
+
}
|
|
305
|
+
IdPerspectiveTransform(image, frameRect) {
|
|
306
|
+
this.checkWasmInitialization("Unable to perform perspective transform, cpp API hasn't been initialized");
|
|
307
|
+
return this.idCaptureWasmApi.IdPerspectiveTransform(image, frameRect);
|
|
308
|
+
}
|
|
309
|
+
async getVersions() {
|
|
310
|
+
const text = await (await fetch(this.versionsFile)).text();
|
|
311
|
+
return JSON.parse(text);
|
|
312
|
+
}
|
|
313
|
+
async loadWasm(useSimd, webLibPath, webLibPathSimd) {
|
|
314
|
+
const libPath = useSimd ? webLibPathSimd : webLibPath;
|
|
315
|
+
try {
|
|
316
|
+
window.wasmArrayBuffer = await fetch(libPath).then((response) => response.arrayBuffer()).then((buffer) => new Uint8Array(buffer));
|
|
317
|
+
this.wasmModule = await this.Module();
|
|
318
|
+
} catch (e) {
|
|
319
|
+
if (useSimd) return await this.loadWasm(false, webLibPath, webLibPathSimd);
|
|
320
|
+
else throw e;
|
|
321
|
+
}
|
|
322
|
+
return useSimd;
|
|
323
|
+
}
|
|
324
|
+
async loadModels() {
|
|
325
|
+
this.checkWasmInitialization("Unable load the models, cpp API hasn't been initialized");
|
|
326
|
+
const buffSizes = new this.wasmModule.PipelineTypeToIntMap();
|
|
327
|
+
const modelData = /* @__PURE__ */ new Map();
|
|
328
|
+
const loadedModels = /* @__PURE__ */ new Map();
|
|
329
|
+
for (const [type, modelsPaths] of this.pipelines_) {
|
|
330
|
+
const wasmType = this.pipelineTypeToWasmEnum(type);
|
|
331
|
+
const pipelineBuffers = [];
|
|
332
|
+
const sizes = new this.wasmModule.VectorInt();
|
|
333
|
+
for (const path of modelsPaths) {
|
|
334
|
+
if (!loadedModels.has(path)) {
|
|
335
|
+
const model$1 = await fetch(path).then((response) => response.arrayBuffer()).then((buffer) => new Uint8Array(buffer));
|
|
336
|
+
loadedModels.set(path, model$1);
|
|
337
|
+
}
|
|
338
|
+
const model = loadedModels.get(path);
|
|
339
|
+
sizes.push_back(model.byteLength);
|
|
340
|
+
pipelineBuffers.push(model);
|
|
341
|
+
}
|
|
342
|
+
buffSizes.set(wasmType, sizes);
|
|
343
|
+
modelData.set(wasmType, pipelineBuffers);
|
|
344
|
+
}
|
|
345
|
+
this.modelsBuffers = this.pipelineApiUtilities.allocateModelsBuffers(buffSizes);
|
|
346
|
+
for (const [type, data] of modelData) {
|
|
347
|
+
const buffers = this.modelsBuffers?.get(type);
|
|
348
|
+
for (let k = 0; k < buffers.size(); k++) {
|
|
349
|
+
const buffer = buffers?.get(k);
|
|
350
|
+
if (buffer) buffer.set(data[k]);
|
|
351
|
+
else throw new Error("Unable to get model buffer from shared memory!");
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
async initializePipelines() {
|
|
356
|
+
this.checkWasmInitialization("Unable to initialize pipelines, cpp API hasn't been initialized");
|
|
357
|
+
if (!this.modelsBuffers) await this.loadModels();
|
|
358
|
+
this.pipelineApiUtilities.initializePipelines();
|
|
359
|
+
}
|
|
360
|
+
async setProductionMode(productionMode) {
|
|
361
|
+
this.checkWasmInitialization("Unable to set production mode, cpp API hasn't been initialized");
|
|
362
|
+
this.utilityApi.setProductionMode(productionMode);
|
|
363
|
+
}
|
|
364
|
+
getPipelineState() {
|
|
365
|
+
this.checkWasmInitialization("Unable to get pipeline state, cpp API hasn't been initialized");
|
|
366
|
+
return this.pipelineApiUtilities.getPipelineState();
|
|
367
|
+
}
|
|
368
|
+
getCurrentPipeline() {
|
|
369
|
+
this.checkWasmInitialization("Unable to get current pipeline, cpp API hasn't been initialized");
|
|
370
|
+
return this.pipelineTypeFromWasmEnum(this.pipelineApiUtilities.getCurrentPipeline());
|
|
371
|
+
}
|
|
372
|
+
setSdkVersion(sdkVersion) {
|
|
373
|
+
this.checkWasmInitialization("Unable to set sdk version, cpp API hasn't been initialized");
|
|
374
|
+
this.utilityApi.setSdkVersion(sdkVersion);
|
|
375
|
+
}
|
|
376
|
+
setSdkPlatform(sdkPlatform) {
|
|
377
|
+
this.checkWasmInitialization("Unable to set device type, cpp API hasn't been initialized");
|
|
378
|
+
this.utilityApi.setSdkPlatform(sdkPlatform);
|
|
379
|
+
}
|
|
380
|
+
setDeviceInfo(deviceInfo, overrideExisting = true) {
|
|
381
|
+
this.checkWasmInitialization("Unable to set device info, cpp API hasn't been initialized");
|
|
382
|
+
this.utilityApi.setDeviceInfo(deviceInfo, overrideExisting);
|
|
383
|
+
}
|
|
384
|
+
setBrowserInfo(browserInfo, overrideExisting = true) {
|
|
385
|
+
this.checkWasmInitialization("Unable to set browser info, cpp API hasn't been initialized");
|
|
386
|
+
this.utilityApi.setBrowserInfo(browserInfo, overrideExisting);
|
|
387
|
+
}
|
|
388
|
+
setCameraInfo(cameraInfo, overrideExisting = true) {
|
|
389
|
+
this.checkWasmInitialization("Unable to set camera info, cpp API hasn't been initialized");
|
|
390
|
+
this.utilityApi.setCameraInfo(cameraInfo, overrideExisting);
|
|
391
|
+
}
|
|
392
|
+
setZc(zc) {
|
|
393
|
+
this.checkWasmInitialization("Unable to set zc, cpp API hasn't been initialized");
|
|
394
|
+
this.utilityApi.setZc(zc);
|
|
395
|
+
}
|
|
396
|
+
setMotionStatus(motionStatus) {
|
|
397
|
+
this.checkWasmInitialization("Unable to set motion status, cpp API hasn't been initialized");
|
|
398
|
+
this.utilityApi.setMotionStatus(motionStatus);
|
|
399
|
+
}
|
|
400
|
+
setMetadataField(key, value) {
|
|
401
|
+
this.checkWasmInitialization("Unable to set metadata field, cpp API hasn't been initialized");
|
|
402
|
+
this.utilityApi.setMetadataField(key, value);
|
|
403
|
+
}
|
|
404
|
+
setInspectorOpened(inspectorOpened) {
|
|
405
|
+
this.inspectorOpened_ = inspectorOpened;
|
|
406
|
+
}
|
|
407
|
+
setBackgroundMode(backgroundMode) {
|
|
408
|
+
this.checkWasmInitialization("Unable to set background mode, cpp API hasn't been initialized");
|
|
409
|
+
this.utilityApi.setBackgroundMode(backgroundMode);
|
|
410
|
+
}
|
|
411
|
+
getCheck() {
|
|
412
|
+
this.checkWasmInitialization("Unable to get check, cpp API hasn't been initialized");
|
|
413
|
+
return this.utilityApi.getCheck();
|
|
414
|
+
}
|
|
415
|
+
getMetadata() {
|
|
416
|
+
this.checkWasmInitialization("Unable to get metadata, cpp API hasn't been initialized");
|
|
417
|
+
this.utilityApi.setInspectorOpened(this.inspectorOpened_);
|
|
418
|
+
return this.utilityApi.getMetadata();
|
|
419
|
+
}
|
|
420
|
+
async prc() {
|
|
421
|
+
this.checkWasmInitialization("Unable to prc, cpp API hasn't been initialized");
|
|
422
|
+
return await this.wasmCallWrapper(this.utilityApi.prc.bind(this.utilityApi), []);
|
|
423
|
+
}
|
|
424
|
+
async poc(output) {
|
|
425
|
+
this.checkWasmInitialization("Unable to poc, cpp API hasn't been initialized");
|
|
426
|
+
await this.wasmCallWrapper(this.utilityApi.poc.bind(this.utilityApi), [output]);
|
|
427
|
+
}
|
|
428
|
+
async pc(deviceId) {
|
|
429
|
+
this.checkWasmInitialization("Unable to pc, cpp API hasn't been initialized");
|
|
430
|
+
await this.wasmCallWrapper(this.utilityApi.pc.bind(this.utilityApi), [deviceId]);
|
|
431
|
+
}
|
|
432
|
+
ckvcks(data) {
|
|
433
|
+
this.checkWasmInitialization("Unable to ckvcks, cpp API hasn't been initialized");
|
|
434
|
+
this.utilityApi.ckvcks(data);
|
|
435
|
+
}
|
|
436
|
+
pipelineTypeToWasmEnum(type) {
|
|
437
|
+
switch (type) {
|
|
438
|
+
case WasmPipelineType.IdBlurGlarePipeline: return this.wasmModule.PipelineType.IdBlurGlarePipeline;
|
|
439
|
+
case WasmPipelineType.IdBarcodeAndTextQualityPipeline: return this.wasmModule.PipelineType.IdBarcodeAndTextQualityPipeline;
|
|
440
|
+
case WasmPipelineType.IdFaceDetectionPipeline: return this.wasmModule.PipelineType.IdFaceDetectionPipeline;
|
|
441
|
+
case WasmPipelineType.IdVideoSelfiePipeline: return this.wasmModule.PipelineType.IdVideoSelfiePipeline;
|
|
442
|
+
case WasmPipelineType.SelfieWithAggregationMetrics: return this.wasmModule.PipelineType.SelfieWithAggregationMetrics;
|
|
443
|
+
case WasmPipelineType.SelfieWithQualityMetrics: return this.wasmModule.PipelineType.SelfieWithQualityMetrics;
|
|
444
|
+
default: throw new Error("Unknown pipeline type");
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
pipelineTypeFromWasmEnum(type) {
|
|
448
|
+
switch (type) {
|
|
449
|
+
case this.wasmModule.PipelineType.IdBlurGlarePipeline: return WasmPipelineType.IdBlurGlarePipeline;
|
|
450
|
+
case this.wasmModule.IdBarcodeAndTextQualityPipeline: return WasmPipelineType.IdBarcodeAndTextQualityPipeline;
|
|
451
|
+
case this.wasmModule.PipelineType.IdFaceDetectionPipeline: return WasmPipelineType.IdFaceDetectionPipeline;
|
|
452
|
+
case this.wasmModule.PipelineType.IdVideoSelfiePipeline: return WasmPipelineType.IdVideoSelfiePipeline;
|
|
453
|
+
case this.wasmModule.PipelineType.SelfieWithAggregationMetrics: return WasmPipelineType.SelfieWithAggregationMetrics;
|
|
454
|
+
case this.wasmModule.PipelineType.SelfieWithQualityMetrics: return WasmPipelineType.SelfieWithQualityMetrics;
|
|
455
|
+
default: throw new Error("Unknown pipeline type");
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
IdCaptureModelTypeToWasmEnum(type) {
|
|
459
|
+
switch (type) {
|
|
460
|
+
case IdCaptureModelType.IdCaptureV1x: return this.wasmModule.IdCaptureModelType.IdCaptureV1x;
|
|
461
|
+
case IdCaptureModelType.IdCaptureV2x: return this.wasmModule.IdCaptureModelType.IdCaptureV2x;
|
|
462
|
+
case IdCaptureModelType.IdCaptureV3x: return this.wasmModule.IdCaptureModelType.IdCaptureV3x;
|
|
463
|
+
default: throw new Error("Unknown Id Capture model type");
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
IdCaptureModelTypeFromWasmEnum(type) {
|
|
467
|
+
switch (type) {
|
|
468
|
+
case this.wasmModule.IdCaptureModelType.IdCaptureV1x: return IdCaptureModelType.IdCaptureV1x;
|
|
469
|
+
case this.wasmModule.IdCaptureModelType.IdCaptureV2x: return IdCaptureModelType.IdCaptureV2x;
|
|
470
|
+
case this.wasmModule.IdCaptureModelType.IdCaptureV3x: return IdCaptureModelType.IdCaptureV3x;
|
|
471
|
+
default: throw new Error("Unknown Id Capture model type");
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
checkWasmInitialization(message) {
|
|
475
|
+
if (!this.isInitialized()) throw new Error(message);
|
|
476
|
+
}
|
|
477
|
+
async wasmCallWrapper(wasmMethod, args = []) {
|
|
478
|
+
return await this.wasmCallMutex.withLock(async (...args$1) => {
|
|
479
|
+
let isFinished = false;
|
|
480
|
+
try {
|
|
481
|
+
while (true) {
|
|
482
|
+
isFinished = wasmMethod(...args$1);
|
|
483
|
+
if (isFinished) return;
|
|
484
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
485
|
+
}
|
|
486
|
+
} catch (e) {
|
|
487
|
+
console.log("Error in wasmCallWrapper:", e);
|
|
488
|
+
}
|
|
489
|
+
}, ...args);
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
var mlWasmJSApi_default = MlWasmJSApi.getInstance();
|
|
493
|
+
|
|
494
|
+
//#endregion
|
|
495
|
+
//#region ../infra/src/wasm/warmup.ts
|
|
496
|
+
/** Array of all available pipelines */
|
|
497
|
+
const WASM_PIPELINES = ["selfie", "idCapture"];
|
|
498
|
+
/**
|
|
499
|
+
* Default model files for each pipeline.
|
|
500
|
+
* These are the ONNX model files required by each ML pipeline.
|
|
501
|
+
*/
|
|
502
|
+
const DEFAULT_PIPELINE_MODELS = {
|
|
503
|
+
selfie: [
|
|
504
|
+
"selfie_bf_angles_192x192_opset9_fp16.ortmodelv2",
|
|
505
|
+
"face_attributes_v1_3_fp16.ortmodelv2",
|
|
506
|
+
"mls_regressor_4773007c657b4f05a460321456740d0f_fp16.ortmodelv2",
|
|
507
|
+
"face_occlusion_v0_1_fp16.ortmodelv2"
|
|
508
|
+
],
|
|
509
|
+
idCapture: ["id_capture_2_01_fp16.ortmodelv2", "id_fiqa_19a81a0b9bf6492eb03b4667f6db4c85_fp16.ortmodelv2"]
|
|
510
|
+
};
|
|
511
|
+
let state = "idle";
|
|
512
|
+
let loadingPromise = null;
|
|
513
|
+
let wasmError = null;
|
|
514
|
+
let loadedPipelines = [];
|
|
515
|
+
let lastConfig = null;
|
|
516
|
+
function mapPipelineToWasmType(pipeline) {
|
|
517
|
+
switch (pipeline) {
|
|
518
|
+
case "selfie": return WasmPipelineType.SelfieWithQualityMetrics;
|
|
519
|
+
case "idCapture": return WasmPipelineType.IdBlurGlarePipeline;
|
|
520
|
+
default: throw new Error(`Unknown pipeline: ${pipeline}`);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Derives the models base path from the WASM path.
|
|
525
|
+
* Assumes models are in a 'models' subdirectory relative to the WASM binary location.
|
|
526
|
+
* e.g., '/wasm/v2/binary.wasm' -> '/wasm/v2/models'
|
|
527
|
+
*/
|
|
528
|
+
function deriveModelsBasePath(wasmPath) {
|
|
529
|
+
const lastSlashIndex = wasmPath.lastIndexOf("/");
|
|
530
|
+
if (lastSlashIndex === -1) return "models";
|
|
531
|
+
return `${wasmPath.substring(0, lastSlashIndex)}/models`;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Builds the pipelines map with model paths for WASM initialization.
|
|
535
|
+
* @param pipelines - Array of pipeline types to initialize
|
|
536
|
+
* @param modelsBasePath - Base path where model files are located
|
|
537
|
+
* @param customModels - Optional custom model files per pipeline
|
|
538
|
+
*/
|
|
539
|
+
function buildPipelinesMap(pipelines, modelsBasePath, customModels) {
|
|
540
|
+
const pipelinesMap = /* @__PURE__ */ new Map();
|
|
541
|
+
for (const pipeline of pipelines) {
|
|
542
|
+
const wasmType = mapPipelineToWasmType(pipeline);
|
|
543
|
+
if (!pipelinesMap.has(wasmType)) {
|
|
544
|
+
const modelPaths = (customModels?.[pipeline] ?? DEFAULT_PIPELINE_MODELS[pipeline]).map((modelFile) => `${modelsBasePath}/${modelFile}`);
|
|
545
|
+
pipelinesMap.set(wasmType, modelPaths);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return pipelinesMap;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Preloads WASM binary and ML models at app startup.
|
|
552
|
+
* Runs asynchronously - app can continue while WASM loads in background.
|
|
553
|
+
*
|
|
554
|
+
* Model files are automatically loaded based on the pipeline type.
|
|
555
|
+
* By default, models are expected in a 'models' subdirectory relative to the WASM binary.
|
|
556
|
+
*
|
|
557
|
+
* @param config - Configuration for WASM warmup
|
|
558
|
+
* @returns Promise that resolves when WASM is ready
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* ```ts
|
|
562
|
+
* // Basic usage - models loaded from /wasm/v2/models/
|
|
563
|
+
* warmupWasm({
|
|
564
|
+
* wasmPath: '/wasm/v2/ml-wasm.wasm',
|
|
565
|
+
* glueCodePath: '/wasm/v2/ml-wasm.js',
|
|
566
|
+
* pipelines: ['selfie', 'idCapture'],
|
|
567
|
+
* });
|
|
568
|
+
*
|
|
569
|
+
* // With explicit models path
|
|
570
|
+
* warmupWasm({
|
|
571
|
+
* wasmPath: '/wasm/v2/ml-wasm.wasm',
|
|
572
|
+
* glueCodePath: '/wasm/v2/ml-wasm.js',
|
|
573
|
+
* modelsBasePath: 'https://cdn.example.com/wasm/v2/models',
|
|
574
|
+
* pipelines: ['selfie'],
|
|
575
|
+
* });
|
|
576
|
+
* ```
|
|
577
|
+
*/
|
|
578
|
+
async function warmupWasm(config) {
|
|
579
|
+
const pipelines = config.pipelines ?? [...WASM_PIPELINES];
|
|
580
|
+
const modelsBasePath = config.modelsBasePath ?? deriveModelsBasePath(config.wasmPath);
|
|
581
|
+
if (state === "loading" && loadingPromise) return loadingPromise;
|
|
582
|
+
if (state === "ready") {
|
|
583
|
+
if (pipelines.filter((p) => !loadedPipelines.includes(p)).length === 0) return;
|
|
584
|
+
if (!lastConfig) throw new Error("Cannot add pipelines: original warmup config not available");
|
|
585
|
+
if (lastConfig.wasmPath !== config.wasmPath || lastConfig.glueCodePath !== config.glueCodePath || (lastConfig.wasmSimdPath ?? lastConfig.wasmPath) !== (config.wasmSimdPath ?? config.wasmPath) || (lastConfig.useSimd ?? true) !== (config.useSimd ?? true)) throw new Error("Cannot add pipelines: WASM config mismatch. Use same wasmPath, glueCodePath, and useSimd settings.");
|
|
586
|
+
const combinedPipelines = [...new Set([...loadedPipelines, ...pipelines])];
|
|
587
|
+
state = "loading";
|
|
588
|
+
wasmError = null;
|
|
589
|
+
loadingPromise = (async () => {
|
|
590
|
+
try {
|
|
591
|
+
const pipelinesMap = buildPipelinesMap(combinedPipelines, lastConfig.modelsBasePath ?? deriveModelsBasePath(lastConfig.wasmPath), lastConfig.pipelineModels);
|
|
592
|
+
await mlWasmJSApi_default.initialize(lastConfig.wasmPath, lastConfig.wasmSimdPath ?? lastConfig.wasmPath, lastConfig.glueCodePath, lastConfig.useSimd ?? true, "", pipelinesMap);
|
|
593
|
+
await mlWasmJSApi_default.loadModels();
|
|
594
|
+
await mlWasmJSApi_default.initializePipelines();
|
|
595
|
+
state = "ready";
|
|
596
|
+
loadedPipelines = combinedPipelines;
|
|
597
|
+
lastConfig = {
|
|
598
|
+
...lastConfig,
|
|
599
|
+
pipelines: combinedPipelines
|
|
600
|
+
};
|
|
601
|
+
loadingPromise = null;
|
|
602
|
+
} catch (error) {
|
|
603
|
+
state = "error";
|
|
604
|
+
wasmError = error instanceof Error ? error : new Error(String(error));
|
|
605
|
+
loadingPromise = null;
|
|
606
|
+
throw wasmError;
|
|
607
|
+
}
|
|
608
|
+
})();
|
|
609
|
+
return loadingPromise;
|
|
610
|
+
}
|
|
611
|
+
state = "loading";
|
|
612
|
+
wasmError = null;
|
|
613
|
+
loadingPromise = (async () => {
|
|
614
|
+
try {
|
|
615
|
+
const pipelinesMap = buildPipelinesMap(pipelines, modelsBasePath, config.pipelineModels);
|
|
616
|
+
await mlWasmJSApi_default.initialize(config.wasmPath, config.wasmSimdPath ?? config.wasmPath, config.glueCodePath, config.useSimd ?? true, "", pipelinesMap);
|
|
617
|
+
await mlWasmJSApi_default.loadModels();
|
|
618
|
+
await mlWasmJSApi_default.initializePipelines();
|
|
619
|
+
state = "ready";
|
|
620
|
+
loadedPipelines = [...pipelines];
|
|
621
|
+
lastConfig = {
|
|
622
|
+
...config,
|
|
623
|
+
pipelines
|
|
624
|
+
};
|
|
625
|
+
loadingPromise = null;
|
|
626
|
+
} catch (error) {
|
|
627
|
+
state = "error";
|
|
628
|
+
wasmError = error instanceof Error ? error : new Error(String(error));
|
|
629
|
+
loadingPromise = null;
|
|
630
|
+
throw wasmError;
|
|
631
|
+
}
|
|
632
|
+
})();
|
|
633
|
+
return loadingPromise;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Returns the current warmup status.
|
|
637
|
+
* Useful for showing loading indicators.
|
|
638
|
+
*
|
|
639
|
+
* @returns Current warmup status
|
|
640
|
+
*/
|
|
641
|
+
function getWasmStatus() {
|
|
642
|
+
return {
|
|
643
|
+
isReady: state === "ready",
|
|
644
|
+
isLoading: state === "loading",
|
|
645
|
+
error: wasmError ?? void 0,
|
|
646
|
+
loadedPipelines: [...loadedPipelines]
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Returns true if WASM is fully initialized and ready.
|
|
651
|
+
*
|
|
652
|
+
* @returns True if WASM is ready
|
|
653
|
+
*/
|
|
654
|
+
function isWasmReady() {
|
|
655
|
+
return state === "ready";
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Returns a promise that resolves when WASM is ready.
|
|
659
|
+
* - If ready: resolves immediately
|
|
660
|
+
* - If loading: waits for completion, then resolves
|
|
661
|
+
* - If not started: rejects with error
|
|
662
|
+
*
|
|
663
|
+
* @returns Promise that resolves when WASM is ready
|
|
664
|
+
* @throws Error if WASM is in error state or was never started
|
|
665
|
+
*/
|
|
666
|
+
function waitForWasm() {
|
|
667
|
+
if (state === "ready") return Promise.resolve();
|
|
668
|
+
if (state === "loading" && loadingPromise) return loadingPromise;
|
|
669
|
+
if (state === "error") return Promise.reject(wasmError ?? /* @__PURE__ */ new Error("WASM initialization failed"));
|
|
670
|
+
return Promise.reject(/* @__PURE__ */ new Error("WASM warmup was not started. Call warmupWasm() first."));
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
//#endregion
|
|
674
|
+
//#region ../infra/src/device/getBrowser.ts
|
|
675
|
+
function getUserAgent() {
|
|
676
|
+
if (typeof navigator === "undefined") return "";
|
|
677
|
+
return navigator.userAgent;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
//#endregion
|
|
681
|
+
//#region ../infra/src/device/getDeviceClass.ts
|
|
682
|
+
function getDeviceInfo() {
|
|
683
|
+
if (typeof navigator === "undefined") return {
|
|
684
|
+
userAgent: "",
|
|
685
|
+
platform: "",
|
|
686
|
+
maxTouchPoints: 0
|
|
687
|
+
};
|
|
688
|
+
return {
|
|
689
|
+
userAgent: navigator.userAgent,
|
|
690
|
+
platform: navigator.platform,
|
|
691
|
+
maxTouchPoints: navigator.maxTouchPoints
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Gets the current window dimensions.
|
|
696
|
+
* Returns default values (1280x720) in non-browser environments.
|
|
697
|
+
*/
|
|
698
|
+
function getWindowDimensions(defaultWidth = 1280, defaultHeight = 720) {
|
|
699
|
+
if (typeof window === "undefined") return {
|
|
700
|
+
outerWidth: defaultWidth,
|
|
701
|
+
outerHeight: defaultHeight,
|
|
702
|
+
innerWidth: defaultWidth,
|
|
703
|
+
innerHeight: defaultHeight
|
|
704
|
+
};
|
|
705
|
+
return {
|
|
706
|
+
outerWidth: window.outerWidth,
|
|
707
|
+
outerHeight: window.outerHeight,
|
|
708
|
+
innerWidth: window.innerWidth,
|
|
709
|
+
innerHeight: window.innerHeight
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
//#endregion
|
|
714
|
+
//#region ../infra/src/media/canvas.ts
|
|
715
|
+
/**
|
|
716
|
+
* Class representing a canvas element for image capture and manipulation.
|
|
717
|
+
*/
|
|
718
|
+
var IncodeCanvas = class IncodeCanvas {
|
|
719
|
+
/**
|
|
720
|
+
* Creates an {@link IncodeCanvas} from a raw {@link ImageData} frame.
|
|
721
|
+
* @param imageData - Frame pixels in RGBA format
|
|
722
|
+
* @returns An {@link IncodeCanvas} containing the provided pixels
|
|
723
|
+
*/
|
|
724
|
+
static fromImageData(imageData) {
|
|
725
|
+
const canvas = document.createElement("canvas");
|
|
726
|
+
canvas.width = imageData.width;
|
|
727
|
+
canvas.height = imageData.height;
|
|
728
|
+
const context = canvas.getContext("2d", { willReadFrequently: true });
|
|
729
|
+
if (!context) return new IncodeCanvas(canvas);
|
|
730
|
+
if ("putImageData" in context) context.putImageData(imageData, 0, 0);
|
|
731
|
+
return new IncodeCanvas(canvas);
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Create a new canvas element.
|
|
735
|
+
* @param canvas_ - The canvas element to clone.
|
|
736
|
+
*/
|
|
737
|
+
constructor(canvas_) {
|
|
738
|
+
this.base64Image = null;
|
|
739
|
+
this.blobData = null;
|
|
740
|
+
this.canvas = document.createElement("canvas");
|
|
741
|
+
this.canvas.width = canvas_.width;
|
|
742
|
+
this.canvas.height = canvas_.height;
|
|
743
|
+
const context = this.canvas.getContext("2d");
|
|
744
|
+
if (context) context.drawImage(canvas_, 0, 0);
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Check if the current canvas is valid.
|
|
748
|
+
*/
|
|
749
|
+
checkCanvas() {
|
|
750
|
+
return this.canvas && this.canvas.width > 1 && this.canvas.height > 1;
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Disposes of resources, including revoking object URLs to prevent memory leaks.
|
|
754
|
+
*/
|
|
755
|
+
dispose() {
|
|
756
|
+
if (this.blobData?.url) {
|
|
757
|
+
URL.revokeObjectURL(this.blobData.url);
|
|
758
|
+
this.blobData = null;
|
|
759
|
+
}
|
|
760
|
+
this.base64Image = null;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Release the data stored by IncodeCanvas.
|
|
764
|
+
*/
|
|
765
|
+
release() {
|
|
766
|
+
if (!this.checkCanvas()) return;
|
|
767
|
+
this.canvas.width = 1;
|
|
768
|
+
this.canvas.height = 1;
|
|
769
|
+
this.canvas.getContext("2d")?.clearRect(0, 0, 1, 1);
|
|
770
|
+
this.base64Image = null;
|
|
771
|
+
if (this.blobData?.url) URL.revokeObjectURL(this.blobData.url);
|
|
772
|
+
this.blobData = null;
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* Revokes the object URL if one exists, preventing memory leaks.
|
|
776
|
+
* Use this when you no longer need the preview image URL.
|
|
777
|
+
*/
|
|
778
|
+
revokeObjectURL() {
|
|
779
|
+
if (this.blobData?.url) {
|
|
780
|
+
URL.revokeObjectURL(this.blobData.url);
|
|
781
|
+
this.blobData = {
|
|
782
|
+
...this.blobData,
|
|
783
|
+
url: ""
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Get the width of the canvas.
|
|
789
|
+
*/
|
|
790
|
+
width() {
|
|
791
|
+
if (!this.checkCanvas()) return null;
|
|
792
|
+
return this.canvas.width;
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Get the height of the canvas.
|
|
796
|
+
*/
|
|
797
|
+
height() {
|
|
798
|
+
if (!this.checkCanvas()) return null;
|
|
799
|
+
return this.canvas.height;
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Set the width of the canvas.
|
|
803
|
+
*/
|
|
804
|
+
setWidth(width) {
|
|
805
|
+
if (!this.checkCanvas()) return;
|
|
806
|
+
this.canvas.width = width;
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Set the height of the canvas.
|
|
810
|
+
*/
|
|
811
|
+
setHeight(height) {
|
|
812
|
+
if (!this.checkCanvas()) return;
|
|
813
|
+
this.canvas.height = height;
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Clone the current canvas.
|
|
817
|
+
*/
|
|
818
|
+
clone() {
|
|
819
|
+
if (!this.checkCanvas()) return null;
|
|
820
|
+
const cloned = new IncodeCanvas(this.canvas);
|
|
821
|
+
cloned.setBase64Image(this.base64Image);
|
|
822
|
+
return cloned;
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* Deep clone the current IncodeCanvas including blob data.
|
|
826
|
+
*/
|
|
827
|
+
async deepClone() {
|
|
828
|
+
const cloned = this.clone();
|
|
829
|
+
if (!cloned) return null;
|
|
830
|
+
if (this.blobData) await cloned.setBlobData(this.blobData);
|
|
831
|
+
return cloned;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Returns the drawing context on the canvas.
|
|
835
|
+
*/
|
|
836
|
+
getContext(contextId, contextAttributes) {
|
|
837
|
+
if (!this.checkCanvas()) return null;
|
|
838
|
+
const context = this.canvas.getContext(contextId, contextAttributes);
|
|
839
|
+
return context instanceof CanvasRenderingContext2D ? context : null;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Retrieves the image data from the canvas.
|
|
843
|
+
*/
|
|
844
|
+
getImageData() {
|
|
845
|
+
if (!this.checkCanvas()) return null;
|
|
846
|
+
const context = this.canvas.getContext("2d", { willReadFrequently: true });
|
|
847
|
+
if (!context) return null;
|
|
848
|
+
return context.getImageData(0, 0, this.canvas.width, this.canvas.height);
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Updates the base64 representation of the current canvas image.
|
|
852
|
+
*/
|
|
853
|
+
updateBase64Image(jpegQuality = 1) {
|
|
854
|
+
if (!this.checkCanvas()) return;
|
|
855
|
+
this.base64Image = this.canvas.toDataURL("image/jpeg", jpegQuality);
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* Converts the current canvas element to a base64 string.
|
|
859
|
+
*/
|
|
860
|
+
getBase64Image(jpegQuality = 1, includeDataURLPrefix = false) {
|
|
861
|
+
if (!this.checkCanvas()) return null;
|
|
862
|
+
if (this.base64Image === null) this.updateBase64Image(jpegQuality);
|
|
863
|
+
const base64Image = this.base64Image;
|
|
864
|
+
if (base64Image === null) return null;
|
|
865
|
+
if (includeDataURLPrefix) return base64Image;
|
|
866
|
+
const commaIndex = base64Image.indexOf(",");
|
|
867
|
+
if (commaIndex === -1) return base64Image;
|
|
868
|
+
return base64Image.slice(commaIndex + 1);
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* Sets the base64 representation of the current canvas image.
|
|
872
|
+
*/
|
|
873
|
+
setBase64Image(base64Image) {
|
|
874
|
+
this.base64Image = base64Image;
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Updates the Blob representation of the current canvas image.
|
|
878
|
+
*/
|
|
879
|
+
updateBlob(jpegQuality = 1, includeDataURLPrefix = false) {
|
|
880
|
+
if (!this.checkCanvas()) return;
|
|
881
|
+
if (this.base64Image === null) this.updateBase64Image(jpegQuality);
|
|
882
|
+
const base64 = this.getBase64Image(jpegQuality, includeDataURLPrefix);
|
|
883
|
+
if (base64) this.blobData = IncodeCanvas.base64ToBlob(base64);
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
886
|
+
* Converts a base64 string to a Blob and creates a URL for it.
|
|
887
|
+
*/
|
|
888
|
+
static base64ToBlob(base64) {
|
|
889
|
+
try {
|
|
890
|
+
const binary = atob(base64);
|
|
891
|
+
const array = [];
|
|
892
|
+
for (let i = 0; i < binary.length; i++) array.push(binary.charCodeAt(i));
|
|
893
|
+
const blob = new Blob([new Uint8Array(array)]);
|
|
894
|
+
return {
|
|
895
|
+
blob,
|
|
896
|
+
url: URL.createObjectURL(blob)
|
|
897
|
+
};
|
|
898
|
+
} catch (error) {
|
|
899
|
+
console.error("Failed to convert base64 string to Blob:", error);
|
|
900
|
+
}
|
|
901
|
+
return null;
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Retrieves the Blob data and its URL from the current canvas.
|
|
905
|
+
*/
|
|
906
|
+
getBlobData(jpegQuality = 1, includeDataURLPrefix = false) {
|
|
907
|
+
if (!this.checkCanvas()) return null;
|
|
908
|
+
if (this.blobData === null) this.updateBlob(jpegQuality, includeDataURLPrefix);
|
|
909
|
+
return this.blobData;
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* Sets the Blob data of the current canvas image.
|
|
913
|
+
*/
|
|
914
|
+
async setBlobData(blobData) {
|
|
915
|
+
const blobDataArrayBuffer = await blobData.blob.arrayBuffer();
|
|
916
|
+
this.blobData = {
|
|
917
|
+
blob: new Blob([blobDataArrayBuffer], { type: blobData.blob.type }),
|
|
918
|
+
url: blobData.url
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* Returns a resized canvas according to video element size.
|
|
923
|
+
*/
|
|
924
|
+
getResizedCanvas(videoElementWidth, videoElementHeight) {
|
|
925
|
+
if (!this.checkCanvas()) return null;
|
|
926
|
+
const cameraOffsetX = Math.abs(videoElementWidth - window.innerWidth);
|
|
927
|
+
const resized = new IncodeCanvas(document.createElement("canvas"));
|
|
928
|
+
const canvasHeight = this.height();
|
|
929
|
+
if (!canvasHeight) return null;
|
|
930
|
+
const ratio = canvasHeight / videoElementHeight;
|
|
931
|
+
const newWidth = window.innerWidth;
|
|
932
|
+
const newHeight = window.innerHeight;
|
|
933
|
+
resized.setWidth(newWidth);
|
|
934
|
+
resized.setHeight(newHeight);
|
|
935
|
+
const context = resized.getContext("2d");
|
|
936
|
+
if (!context) return null;
|
|
937
|
+
context.drawImage(this.canvas, ratio * cameraOffsetX / 2, 0, ratio * newWidth, ratio * newHeight, 0, 0, newWidth, newHeight);
|
|
938
|
+
return resized;
|
|
939
|
+
}
|
|
940
|
+
};
|
|
941
|
+
|
|
942
|
+
//#endregion
|
|
943
|
+
//#region ../infra/src/media/video.ts
|
|
944
|
+
/**
|
|
945
|
+
* Creates a hidden video element for a stream and appends it to document.body.
|
|
946
|
+
*/
|
|
947
|
+
function createHiddenVideoElement(stream) {
|
|
948
|
+
if (typeof document === "undefined") throw new Error("Document not available");
|
|
949
|
+
const video = document.createElement("video");
|
|
950
|
+
video.autoplay = true;
|
|
951
|
+
video.playsInline = true;
|
|
952
|
+
video.muted = true;
|
|
953
|
+
video.srcObject = stream;
|
|
954
|
+
video.style.width = "0px";
|
|
955
|
+
video.style.height = "0px";
|
|
956
|
+
video.style.position = "absolute";
|
|
957
|
+
video.style.top = "0";
|
|
958
|
+
video.style.left = "0";
|
|
959
|
+
video.style.zIndex = "-1";
|
|
960
|
+
document.body.appendChild(video);
|
|
961
|
+
return {
|
|
962
|
+
element: video,
|
|
963
|
+
dispose: () => {
|
|
964
|
+
video.srcObject = null;
|
|
965
|
+
if (video.parentElement) video.parentElement.removeChild(video);
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
//#endregion
|
|
971
|
+
//#region src/internal/deepsight/metadataService.ts
|
|
972
|
+
const IP_PROVIDER_URL = "https://api.ipify.org?format=json";
|
|
973
|
+
async function fetchPublicIp(browserEnv) {
|
|
974
|
+
return (await browserEnv.fetchJson(IP_PROVIDER_URL, 3e3))?.ip || "";
|
|
975
|
+
}
|
|
976
|
+
function createMetadataService(wasmUtil, visibility, browserEnv) {
|
|
977
|
+
return {
|
|
978
|
+
async initialize(sdkVersion, disableIpify = false) {
|
|
979
|
+
wasmUtil.setSdkPlatform("WEBAPP");
|
|
980
|
+
wasmUtil.setSdkVersion(sdkVersion);
|
|
981
|
+
const ua = getUserAgent();
|
|
982
|
+
const isMobile = /Android|iPhone|iPad|iPod/i.test(ua);
|
|
983
|
+
const deviceInfo = getDeviceInfo();
|
|
984
|
+
const visitorId = browserEnv.generateCanvasFingerprint();
|
|
985
|
+
const ip = disableIpify ? "" : await fetchPublicIp(browserEnv);
|
|
986
|
+
const screenDimensions = browserEnv.getScreenDimensions();
|
|
987
|
+
const deviceMetadata = {
|
|
988
|
+
kind: isMobile ? "mobile" : "desktop",
|
|
989
|
+
model: "",
|
|
990
|
+
os: void 0,
|
|
991
|
+
osVersion: void 0,
|
|
992
|
+
screenDimensions,
|
|
993
|
+
numTouchPoints: deviceInfo.maxTouchPoints,
|
|
994
|
+
fingerprintHash: visitorId,
|
|
995
|
+
ip,
|
|
996
|
+
backgroundMode: false
|
|
997
|
+
};
|
|
998
|
+
wasmUtil.setDeviceInfo(deviceMetadata);
|
|
999
|
+
const navigatorPrefixes = browserEnv.getNavigatorPrefixes();
|
|
1000
|
+
const browserInfo = {
|
|
1001
|
+
userAgent: ua,
|
|
1002
|
+
getUserMediaAvailability: {
|
|
1003
|
+
webkit: navigatorPrefixes.webkit,
|
|
1004
|
+
moz: navigatorPrefixes.moz,
|
|
1005
|
+
o: navigatorPrefixes.o,
|
|
1006
|
+
ms: navigatorPrefixes.ms
|
|
1007
|
+
},
|
|
1008
|
+
webglFingerprint: browserEnv.getWebGLRenderer(),
|
|
1009
|
+
inspectorOpened: false,
|
|
1010
|
+
isMockedBrowser: isBrowserSimulation(browserEnv)
|
|
1011
|
+
};
|
|
1012
|
+
wasmUtil.setBrowserInfo(browserInfo, false);
|
|
1013
|
+
},
|
|
1014
|
+
updateCameraInfo(videoTrack) {
|
|
1015
|
+
const settings = videoTrack.getSettings();
|
|
1016
|
+
const capabilities = videoTrack.getCapabilities?.() ?? {};
|
|
1017
|
+
const labels = videoTrack.label ? [videoTrack.label] : [];
|
|
1018
|
+
const cameraInfo = {
|
|
1019
|
+
facingMode: settings.facingMode === "user" ? "frontal" : settings.facingMode === "environment" ? "back" : settings.facingMode || "unknown",
|
|
1020
|
+
settings,
|
|
1021
|
+
capabilities,
|
|
1022
|
+
labels
|
|
1023
|
+
};
|
|
1024
|
+
wasmUtil.setCameraInfo(cameraInfo);
|
|
1025
|
+
},
|
|
1026
|
+
async checkForVirtualCameraByLabel(videoTrack = null) {
|
|
1027
|
+
try {
|
|
1028
|
+
if (!videoTrack) {
|
|
1029
|
+
const labels = await browserEnv.enumerateVideoDeviceLabels();
|
|
1030
|
+
for (const label of labels) if (wasmUtil.isVirtualCamera(label)) return true;
|
|
1031
|
+
}
|
|
1032
|
+
if (videoTrack && wasmUtil.isVirtualCamera(videoTrack.label)) return true;
|
|
1033
|
+
return false;
|
|
1034
|
+
} catch {
|
|
1035
|
+
return false;
|
|
1036
|
+
}
|
|
1037
|
+
},
|
|
1038
|
+
async analyzeFrame(imageData) {
|
|
1039
|
+
await wasmUtil.analyzeFrame(imageData);
|
|
1040
|
+
},
|
|
1041
|
+
setMotionStatus(status) {
|
|
1042
|
+
wasmUtil.setMotionStatus(status);
|
|
1043
|
+
},
|
|
1044
|
+
setBackgroundMode(backgroundMode) {
|
|
1045
|
+
wasmUtil.setBackgroundMode(backgroundMode || visibility.wasBackgrounded);
|
|
1046
|
+
visibility.reset();
|
|
1047
|
+
},
|
|
1048
|
+
estimatePerformance() {
|
|
1049
|
+
return wasmUtil.estimatePerformance();
|
|
1050
|
+
},
|
|
1051
|
+
getMetadata() {
|
|
1052
|
+
return wasmUtil.getMetadata();
|
|
1053
|
+
},
|
|
1054
|
+
getCheck() {
|
|
1055
|
+
return wasmUtil.getCheck();
|
|
1056
|
+
},
|
|
1057
|
+
getPipelineState() {
|
|
1058
|
+
return wasmUtil.getPipelineState();
|
|
1059
|
+
},
|
|
1060
|
+
preparePipelineState() {
|
|
1061
|
+
wasmUtil.getPipelineState();
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
//#endregion
|
|
1067
|
+
//#region src/internal/deepsight/motionStatusService.ts
|
|
1068
|
+
function createMotionStatusService(motionSensor) {
|
|
1069
|
+
return {
|
|
1070
|
+
async requestPermission() {
|
|
1071
|
+
return motionSensor.requestPermission();
|
|
1072
|
+
},
|
|
1073
|
+
async start() {
|
|
1074
|
+
await motionSensor.start();
|
|
1075
|
+
},
|
|
1076
|
+
stop() {
|
|
1077
|
+
motionSensor.stop();
|
|
1078
|
+
},
|
|
1079
|
+
check() {
|
|
1080
|
+
return motionSensor.check();
|
|
1081
|
+
},
|
|
1082
|
+
get isRunning() {
|
|
1083
|
+
return motionSensor.isRunning;
|
|
1084
|
+
},
|
|
1085
|
+
get hasPermission() {
|
|
1086
|
+
return motionSensor.hasPermission;
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
//#endregion
|
|
1092
|
+
//#region src/internal/virtualCameraCheck.ts
|
|
1093
|
+
/**
|
|
1094
|
+
* Sends the analyzed frame image to the backend for logging.
|
|
1095
|
+
*/
|
|
1096
|
+
async function logFrame({ source, base64Image, token }) {
|
|
1097
|
+
try {
|
|
1098
|
+
return (await api.post("/omni/log/frame/v2", { base64Image }, {
|
|
1099
|
+
query: { source },
|
|
1100
|
+
headers: { "X-Incode-Hardware-Id": token }
|
|
1101
|
+
})).data;
|
|
1102
|
+
} catch {
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Runs the WASM virtual camera check and handles logging and stats.
|
|
1108
|
+
*/
|
|
1109
|
+
async function runVirtualCameraCheck({ wasmUtil, source, token }) {
|
|
1110
|
+
const output = {
|
|
1111
|
+
canvas: null,
|
|
1112
|
+
itr: null,
|
|
1113
|
+
skipped: null
|
|
1114
|
+
};
|
|
1115
|
+
await wasmUtil.poc(output);
|
|
1116
|
+
if (output.skipped !== false) return;
|
|
1117
|
+
if (output.canvas && token) {
|
|
1118
|
+
const base64Image = new IncodeCanvas(output.canvas).getBase64Image();
|
|
1119
|
+
if (base64Image) await logFrame({
|
|
1120
|
+
source,
|
|
1121
|
+
base64Image,
|
|
1122
|
+
token
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
if (output.itr === true) {
|
|
1126
|
+
addDeviceStats({ virtualCameraDetected: true });
|
|
1127
|
+
wasmUtil.setZc("FAIL");
|
|
1128
|
+
} else if (output.itr === false) wasmUtil.setZc("PASS");
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
//#endregion
|
|
1132
|
+
//#region src/internal/deepsight/deepsightService.ts
|
|
1133
|
+
function createDeepsightService(config) {
|
|
1134
|
+
const metadata = createMetadataService(config.wasmUtil, config.visibility, config.browserEnv);
|
|
1135
|
+
const motion = createMotionStatusService(config.motionSensor);
|
|
1136
|
+
return {
|
|
1137
|
+
metadata,
|
|
1138
|
+
motion,
|
|
1139
|
+
async initialize(disableIpify = false) {
|
|
1140
|
+
await metadata.initialize(config.sdkVersion, disableIpify);
|
|
1141
|
+
metadata.estimatePerformance();
|
|
1142
|
+
},
|
|
1143
|
+
async requestMotionPermission() {
|
|
1144
|
+
return motion.requestPermission();
|
|
1145
|
+
},
|
|
1146
|
+
async startMotionSensors() {
|
|
1147
|
+
await motion.start();
|
|
1148
|
+
},
|
|
1149
|
+
stopMotionSensors() {
|
|
1150
|
+
motion.stop();
|
|
1151
|
+
},
|
|
1152
|
+
async checkVirtualCamera(videoTrack) {
|
|
1153
|
+
metadata.updateCameraInfo(videoTrack);
|
|
1154
|
+
return metadata.checkForVirtualCameraByLabel(videoTrack);
|
|
1155
|
+
},
|
|
1156
|
+
async performVirtualCameraCheck(sessionToken, source) {
|
|
1157
|
+
await runVirtualCameraCheck({
|
|
1158
|
+
wasmUtil: config.wasmUtil,
|
|
1159
|
+
source,
|
|
1160
|
+
token: sessionToken
|
|
1161
|
+
});
|
|
1162
|
+
},
|
|
1163
|
+
async performPrcCheck(params) {
|
|
1164
|
+
const prcStream = await requestCameraAccess(params.constraints);
|
|
1165
|
+
const hiddenVideo = createHiddenVideoElement(prcStream);
|
|
1166
|
+
try {
|
|
1167
|
+
await config.wasmUtil.prc();
|
|
1168
|
+
} finally {
|
|
1169
|
+
hiddenVideo.dispose();
|
|
1170
|
+
stopCameraStream(prcStream);
|
|
1171
|
+
}
|
|
1172
|
+
},
|
|
1173
|
+
async analyzeFrame(imageData) {
|
|
1174
|
+
await metadata.analyzeFrame(imageData);
|
|
1175
|
+
metadata.preparePipelineState();
|
|
1176
|
+
const motionStatus = motion.check();
|
|
1177
|
+
metadata.setMotionStatus(motionStatus);
|
|
1178
|
+
metadata.getCheck();
|
|
1179
|
+
metadata.setBackgroundMode(false);
|
|
1180
|
+
},
|
|
1181
|
+
getMetadata() {
|
|
1182
|
+
return metadata.getMetadata();
|
|
1183
|
+
},
|
|
1184
|
+
getMotionStatus() {
|
|
1185
|
+
return motion.check();
|
|
1186
|
+
},
|
|
1187
|
+
getAnalysisStatus() {
|
|
1188
|
+
return metadata.getCheck();
|
|
1189
|
+
},
|
|
1190
|
+
getPipelineState() {
|
|
1191
|
+
return metadata.getPipelineState();
|
|
1192
|
+
},
|
|
1193
|
+
cleanup() {
|
|
1194
|
+
motion.stop();
|
|
1195
|
+
}
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
//#endregion
|
|
1200
|
+
//#region ../infra/src/providers/browser/MotionSensorProvider.ts
|
|
1201
|
+
var MotionSensorProvider = class {
|
|
1202
|
+
constructor(thresholds) {
|
|
1203
|
+
this._isRunning = false;
|
|
1204
|
+
this._hasPermission = true;
|
|
1205
|
+
this.acl = null;
|
|
1206
|
+
this.gyro = null;
|
|
1207
|
+
this.minNumberOfFrames = 3;
|
|
1208
|
+
this.maxFrequency = 60;
|
|
1209
|
+
this.emptyParams = {
|
|
1210
|
+
meanX: 0,
|
|
1211
|
+
meanY: 0,
|
|
1212
|
+
meanZ: 0,
|
|
1213
|
+
m2X: 0,
|
|
1214
|
+
m2Y: 0,
|
|
1215
|
+
m2Z: 0,
|
|
1216
|
+
cumulativeAbsErrorX: 0,
|
|
1217
|
+
cumulativeAbsErrorY: 0,
|
|
1218
|
+
cumulativeAbsErrorZ: 0,
|
|
1219
|
+
ptsNum: 0
|
|
1220
|
+
};
|
|
1221
|
+
this.paramsAcc = { ...this.emptyParams };
|
|
1222
|
+
this.paramsGyro = { ...this.emptyParams };
|
|
1223
|
+
this.paramsAccGrOld = { ...this.emptyParams };
|
|
1224
|
+
this.paramsAccOld = { ...this.emptyParams };
|
|
1225
|
+
this.paramsGyroscopeOld = { ...this.emptyParams };
|
|
1226
|
+
this.paramsOrientationOld = { ...this.emptyParams };
|
|
1227
|
+
this.deviceMotionListener = (event) => {
|
|
1228
|
+
if (event.accelerationIncludingGravity) {
|
|
1229
|
+
const accGrVal = {
|
|
1230
|
+
x: event.accelerationIncludingGravity.x,
|
|
1231
|
+
y: event.accelerationIncludingGravity.y,
|
|
1232
|
+
z: event.accelerationIncludingGravity.z
|
|
1233
|
+
};
|
|
1234
|
+
if (this.checkFields(accGrVal)) {
|
|
1235
|
+
this.paramsAccGrOld.ptsNum += 1;
|
|
1236
|
+
this.updateParams(this.paramsAccGrOld, accGrVal);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
if (event.acceleration) {
|
|
1240
|
+
const accVal = {
|
|
1241
|
+
x: event.acceleration.x,
|
|
1242
|
+
y: event.acceleration.y,
|
|
1243
|
+
z: event.acceleration.z
|
|
1244
|
+
};
|
|
1245
|
+
if (this.checkFields(accVal)) {
|
|
1246
|
+
this.paramsAccOld.ptsNum += 1;
|
|
1247
|
+
this.updateParams(this.paramsAccOld, accVal);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
if (event.rotationRate) {
|
|
1251
|
+
const gyroVal = {
|
|
1252
|
+
x: event.rotationRate.alpha,
|
|
1253
|
+
y: event.rotationRate.beta,
|
|
1254
|
+
z: event.rotationRate.gamma
|
|
1255
|
+
};
|
|
1256
|
+
if (this.checkFields(gyroVal)) {
|
|
1257
|
+
this.paramsGyroscopeOld.ptsNum += 1;
|
|
1258
|
+
this.updateParams(this.paramsGyroscopeOld, gyroVal);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
};
|
|
1262
|
+
this.deviceOrientationListener = (event) => {
|
|
1263
|
+
const orientationVal = {
|
|
1264
|
+
x: event.alpha,
|
|
1265
|
+
y: event.beta,
|
|
1266
|
+
z: event.gamma
|
|
1267
|
+
};
|
|
1268
|
+
if (this.checkFields(orientationVal)) {
|
|
1269
|
+
this.paramsOrientationOld.ptsNum += 1;
|
|
1270
|
+
this.updateParams(this.paramsOrientationOld, orientationVal);
|
|
1271
|
+
}
|
|
1272
|
+
};
|
|
1273
|
+
this.thresholds = {
|
|
1274
|
+
accThreshold: thresholds?.accThreshold ?? .3,
|
|
1275
|
+
gyroThreshold: thresholds?.gyroThreshold ?? .3,
|
|
1276
|
+
accGrOldThreshold: thresholds?.accGrOldThreshold ?? .3,
|
|
1277
|
+
accOldThreshold: thresholds?.accOldThreshold ?? .3,
|
|
1278
|
+
gyroscopeOldThreshold: thresholds?.gyroscopeOldThreshold ?? 10,
|
|
1279
|
+
orientationOldThreshold: thresholds?.orientationOldThreshold ?? 10,
|
|
1280
|
+
maeAccThreshold: thresholds?.maeAccThreshold ?? .3,
|
|
1281
|
+
maeGyroThreshold: thresholds?.maeGyroThreshold ?? .3,
|
|
1282
|
+
maeAccGrOldThreshold: thresholds?.maeAccGrOldThreshold ?? .3,
|
|
1283
|
+
maeAccOldThreshold: thresholds?.maeAccOldThreshold ?? .3,
|
|
1284
|
+
maeGyroscopeOldThreshold: thresholds?.maeGyroscopeOldThreshold ?? 10,
|
|
1285
|
+
maeOrientationOldThreshold: thresholds?.maeOrientationOldThreshold ?? 10
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
get isRunning() {
|
|
1289
|
+
return this._isRunning;
|
|
1290
|
+
}
|
|
1291
|
+
get hasPermission() {
|
|
1292
|
+
return this._hasPermission;
|
|
1293
|
+
}
|
|
1294
|
+
async requestPermission() {
|
|
1295
|
+
if (typeof DeviceMotionEvent !== "undefined" && typeof DeviceMotionEvent.requestPermission === "function") {
|
|
1296
|
+
sessionStorage.setItem("motionSensorsPermissionsRequested", String(true));
|
|
1297
|
+
try {
|
|
1298
|
+
if (await DeviceMotionEvent.requestPermission() !== "granted") {
|
|
1299
|
+
this._hasPermission = false;
|
|
1300
|
+
return "denied";
|
|
1301
|
+
}
|
|
1302
|
+
return "granted";
|
|
1303
|
+
} catch {
|
|
1304
|
+
this._hasPermission = false;
|
|
1305
|
+
return "denied";
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
return "not-required";
|
|
1309
|
+
}
|
|
1310
|
+
initializeAccelerometer() {
|
|
1311
|
+
if (!("Accelerometer" in window)) return;
|
|
1312
|
+
try {
|
|
1313
|
+
const AccelerometerConstructor = window.Accelerometer;
|
|
1314
|
+
if (AccelerometerConstructor) {
|
|
1315
|
+
this.acl = new AccelerometerConstructor({ frequency: this.maxFrequency });
|
|
1316
|
+
this.acl.addEventListener("reading", () => this.updateAcc());
|
|
1317
|
+
}
|
|
1318
|
+
} catch {}
|
|
1319
|
+
}
|
|
1320
|
+
initializeGyroscope() {
|
|
1321
|
+
if (!("Gyroscope" in window)) return;
|
|
1322
|
+
try {
|
|
1323
|
+
const GyroscopeConstructor = window.Gyroscope;
|
|
1324
|
+
if (GyroscopeConstructor) {
|
|
1325
|
+
this.gyro = new GyroscopeConstructor({ frequency: this.maxFrequency });
|
|
1326
|
+
this.gyro.addEventListener("reading", () => this.updateGyro());
|
|
1327
|
+
}
|
|
1328
|
+
} catch {}
|
|
1329
|
+
}
|
|
1330
|
+
async start() {
|
|
1331
|
+
if (this._isRunning || !this._hasPermission) return;
|
|
1332
|
+
try {
|
|
1333
|
+
this.initializeAccelerometer();
|
|
1334
|
+
if (this.acl) this.acl.start();
|
|
1335
|
+
} catch {}
|
|
1336
|
+
try {
|
|
1337
|
+
this.initializeGyroscope();
|
|
1338
|
+
if (this.gyro) this.gyro.start();
|
|
1339
|
+
} catch {}
|
|
1340
|
+
window.addEventListener("devicemotion", this.deviceMotionListener);
|
|
1341
|
+
window.addEventListener("deviceorientation", this.deviceOrientationListener);
|
|
1342
|
+
this._isRunning = true;
|
|
1343
|
+
}
|
|
1344
|
+
stop() {
|
|
1345
|
+
this._isRunning = false;
|
|
1346
|
+
if (this.acl) this.acl.stop();
|
|
1347
|
+
if (this.gyro) this.gyro.stop();
|
|
1348
|
+
window.removeEventListener("devicemotion", this.deviceMotionListener);
|
|
1349
|
+
window.removeEventListener("deviceorientation", this.deviceOrientationListener);
|
|
1350
|
+
this.paramsAcc = { ...this.emptyParams };
|
|
1351
|
+
this.paramsGyro = { ...this.emptyParams };
|
|
1352
|
+
this.paramsAccGrOld = { ...this.emptyParams };
|
|
1353
|
+
this.paramsAccOld = { ...this.emptyParams };
|
|
1354
|
+
this.paramsGyroscopeOld = { ...this.emptyParams };
|
|
1355
|
+
this.paramsOrientationOld = { ...this.emptyParams };
|
|
1356
|
+
}
|
|
1357
|
+
updateAcc() {
|
|
1358
|
+
if (!this._isRunning || !this.acl) return;
|
|
1359
|
+
this.paramsAcc.ptsNum += 1;
|
|
1360
|
+
const val = {
|
|
1361
|
+
x: this.acl.x,
|
|
1362
|
+
y: this.acl.y,
|
|
1363
|
+
z: this.acl.z
|
|
1364
|
+
};
|
|
1365
|
+
if (this.checkFields(val)) this.updateParams(this.paramsAcc, val);
|
|
1366
|
+
}
|
|
1367
|
+
updateGyro() {
|
|
1368
|
+
if (!this._isRunning || !this.gyro) return;
|
|
1369
|
+
this.paramsGyro.ptsNum += 1;
|
|
1370
|
+
const val = {
|
|
1371
|
+
x: this.gyro.x,
|
|
1372
|
+
y: this.gyro.y,
|
|
1373
|
+
z: this.gyro.z
|
|
1374
|
+
};
|
|
1375
|
+
if (this.checkFields(val)) this.updateParams(this.paramsGyro, val);
|
|
1376
|
+
}
|
|
1377
|
+
check() {
|
|
1378
|
+
if (!this._hasPermission) return "UNCLEAR";
|
|
1379
|
+
const result = this.checkStability();
|
|
1380
|
+
return result === null ? "UNCLEAR" : result ? "FAIL" : "PASS";
|
|
1381
|
+
}
|
|
1382
|
+
checkStability() {
|
|
1383
|
+
if (!this._isRunning) return null;
|
|
1384
|
+
const filteredStdChecks = [
|
|
1385
|
+
this.gyro ? this.isBelowStdThreshold(this.paramsGyro, this.thresholds.gyroThreshold) : null,
|
|
1386
|
+
this.acl ? this.isBelowStdThreshold(this.paramsAcc, this.thresholds.accThreshold) : null,
|
|
1387
|
+
this.isBelowStdThreshold(this.paramsAccGrOld, this.thresholds.accGrOldThreshold),
|
|
1388
|
+
this.isBelowStdThreshold(this.paramsAccOld, this.thresholds.accOldThreshold),
|
|
1389
|
+
this.isBelowStdThreshold(this.paramsGyroscopeOld, this.thresholds.gyroscopeOldThreshold),
|
|
1390
|
+
this.isBelowStdThreshold(this.paramsOrientationOld, this.thresholds.orientationOldThreshold)
|
|
1391
|
+
].filter((check) => check !== null);
|
|
1392
|
+
const finalStdCheck = filteredStdChecks.length > 0 ? filteredStdChecks.every((check) => check) : null;
|
|
1393
|
+
const filteredMaeChecks = [
|
|
1394
|
+
this.gyro ? this.isBelowMaeThreshold(this.paramsGyro, this.thresholds.maeGyroThreshold) : null,
|
|
1395
|
+
this.acl ? this.isBelowMaeThreshold(this.paramsAcc, this.thresholds.maeAccThreshold) : null,
|
|
1396
|
+
this.isBelowMaeThreshold(this.paramsAccGrOld, this.thresholds.maeAccGrOldThreshold),
|
|
1397
|
+
this.isBelowMaeThreshold(this.paramsAccOld, this.thresholds.maeAccOldThreshold),
|
|
1398
|
+
this.isBelowMaeThreshold(this.paramsGyroscopeOld, this.thresholds.maeGyroscopeOldThreshold),
|
|
1399
|
+
this.isBelowMaeThreshold(this.paramsOrientationOld, this.thresholds.maeOrientationOldThreshold)
|
|
1400
|
+
].filter((check) => check !== null);
|
|
1401
|
+
const finalMaeCheck = filteredMaeChecks.length > 0 ? filteredMaeChecks.every((check) => check) : null;
|
|
1402
|
+
return finalStdCheck === null ? finalMaeCheck === null ? null : finalMaeCheck : finalMaeCheck !== null ? finalStdCheck && finalMaeCheck : finalStdCheck;
|
|
1403
|
+
}
|
|
1404
|
+
updateParams(params, val) {
|
|
1405
|
+
const deltaX = val.x - params.meanX;
|
|
1406
|
+
const deltaY = val.y - params.meanY;
|
|
1407
|
+
const deltaZ = val.z - params.meanZ;
|
|
1408
|
+
params.meanX += deltaX / params.ptsNum;
|
|
1409
|
+
params.meanY += deltaY / params.ptsNum;
|
|
1410
|
+
params.meanZ += deltaZ / params.ptsNum;
|
|
1411
|
+
params.m2X += deltaX * (val.x - params.meanX);
|
|
1412
|
+
params.m2Y += deltaY * (val.y - params.meanY);
|
|
1413
|
+
params.m2Z += deltaZ * (val.z - params.meanZ);
|
|
1414
|
+
params.cumulativeAbsErrorX += Math.abs(val.x - params.meanX);
|
|
1415
|
+
params.cumulativeAbsErrorY += Math.abs(val.y - params.meanY);
|
|
1416
|
+
params.cumulativeAbsErrorZ += Math.abs(val.z - params.meanZ);
|
|
1417
|
+
}
|
|
1418
|
+
calculateStd(params) {
|
|
1419
|
+
const variance = {
|
|
1420
|
+
x: params.m2X / params.ptsNum,
|
|
1421
|
+
y: params.m2Y / params.ptsNum,
|
|
1422
|
+
z: params.m2Z / params.ptsNum
|
|
1423
|
+
};
|
|
1424
|
+
return {
|
|
1425
|
+
x: Math.sqrt(variance.x),
|
|
1426
|
+
y: Math.sqrt(variance.y),
|
|
1427
|
+
z: Math.sqrt(variance.z)
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
calculateMae(params) {
|
|
1431
|
+
return {
|
|
1432
|
+
x: params.cumulativeAbsErrorX / params.ptsNum,
|
|
1433
|
+
y: params.cumulativeAbsErrorY / params.ptsNum,
|
|
1434
|
+
z: params.cumulativeAbsErrorZ / params.ptsNum
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
checkFields(point) {
|
|
1438
|
+
return point.x !== null && point.y !== null && point.z !== null;
|
|
1439
|
+
}
|
|
1440
|
+
isBelowStdThreshold(params, threshold) {
|
|
1441
|
+
if (params.ptsNum < this.minNumberOfFrames) return null;
|
|
1442
|
+
const std = this.calculateStd(params);
|
|
1443
|
+
return std.x < threshold && std.y < threshold && std.z < threshold;
|
|
1444
|
+
}
|
|
1445
|
+
isBelowMaeThreshold(params, threshold) {
|
|
1446
|
+
if (params.ptsNum < this.minNumberOfFrames) return null;
|
|
1447
|
+
const mae = this.calculateMae(params);
|
|
1448
|
+
return mae.x < threshold && mae.y < threshold && mae.z < threshold;
|
|
1449
|
+
}
|
|
1450
|
+
};
|
|
1451
|
+
|
|
1452
|
+
//#endregion
|
|
1453
|
+
//#region ../infra/src/providers/wasm/BaseWasmProvider.ts
|
|
1454
|
+
/**
|
|
1455
|
+
* Base provider class that abstracts common WASM functionality.
|
|
1456
|
+
* This serves as a foundation for specific ML capability providers
|
|
1457
|
+
* like FaceDetectionProvider and IdCaptureProvider.
|
|
1458
|
+
*/
|
|
1459
|
+
var BaseWasmProvider = class {
|
|
1460
|
+
/**
|
|
1461
|
+
* Creates a new BaseWasmProvider
|
|
1462
|
+
* @param pipelineType - The WASM pipeline type this provider uses
|
|
1463
|
+
*/
|
|
1464
|
+
constructor(pipelineType) {
|
|
1465
|
+
this._isInitialized = false;
|
|
1466
|
+
this.pipelineType = pipelineType;
|
|
1467
|
+
}
|
|
1468
|
+
/**
|
|
1469
|
+
* Returns whether this provider has been initialized.
|
|
1470
|
+
*/
|
|
1471
|
+
get initialized() {
|
|
1472
|
+
return this._isInitialized;
|
|
1473
|
+
}
|
|
1474
|
+
getPipelineType() {
|
|
1475
|
+
if (this.pipelineType === void 0) throw new Error(`${this.constructor.name} has no pipeline type configured.`);
|
|
1476
|
+
return this.pipelineType;
|
|
1477
|
+
}
|
|
1478
|
+
/**
|
|
1479
|
+
* Initializes the provider by ensuring WASM is loaded
|
|
1480
|
+
* @param config - Provider configuration
|
|
1481
|
+
* @param pipeline - The pipeline type to warm up ('selfie', 'idCapture', etc.)
|
|
1482
|
+
*/
|
|
1483
|
+
async initializeBase(config, pipeline) {
|
|
1484
|
+
if (this._isInitialized) return;
|
|
1485
|
+
if (getWasmStatus().isLoading || isWasmReady()) await waitForWasm();
|
|
1486
|
+
else {
|
|
1487
|
+
if (!config.wasmPath || !config.glueCodePath) throw new Error("WASM path and glue code path are required. Call warmupWasm() first.");
|
|
1488
|
+
await warmupWasm({
|
|
1489
|
+
wasmPath: config.wasmPath,
|
|
1490
|
+
wasmSimdPath: config.wasmSimdPath,
|
|
1491
|
+
glueCodePath: config.glueCodePath,
|
|
1492
|
+
useSimd: config.useSimd,
|
|
1493
|
+
modelsBasePath: config.modelsBasePath,
|
|
1494
|
+
pipelines: [pipeline]
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
this._isInitialized = true;
|
|
1498
|
+
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Ensures the provider is initialized before performing operations.
|
|
1501
|
+
* @throws Error if not initialized
|
|
1502
|
+
*/
|
|
1503
|
+
ensureInitialized() {
|
|
1504
|
+
if (!this._isInitialized) throw new Error(`${this.constructor.name} not initialized. Call initialize() first.`);
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Processes a frame through the WASM pipeline
|
|
1508
|
+
* @param image - Image data to process
|
|
1509
|
+
* @returns The pipeline result (type depends on pipeline - WASM returns any)
|
|
1510
|
+
*/
|
|
1511
|
+
async processFrameWasm(image) {
|
|
1512
|
+
this.ensureInitialized();
|
|
1513
|
+
const pipelineType = this.getPipelineType();
|
|
1514
|
+
await mlWasmJSApi_default.allocateImageBuffers(image.width, image.height);
|
|
1515
|
+
await mlWasmJSApi_default.handleDetectionCallAndUpdateState(pipelineType);
|
|
1516
|
+
return await mlWasmJSApi_default.process(image, pipelineType);
|
|
1517
|
+
}
|
|
1518
|
+
/**
|
|
1519
|
+
* Resets the pipeline to its initial state.
|
|
1520
|
+
* Safe to call even if not initialized (no-op in that case).
|
|
1521
|
+
*/
|
|
1522
|
+
reset() {
|
|
1523
|
+
if (this._isInitialized && this.pipelineType !== void 0) mlWasmJSApi_default.resetPipeline(this.pipelineType);
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
* Disposes of resources and resets initialization state.
|
|
1527
|
+
* Safe to call even if not initialized.
|
|
1528
|
+
*/
|
|
1529
|
+
async dispose() {
|
|
1530
|
+
this.reset();
|
|
1531
|
+
this._isInitialized = false;
|
|
1532
|
+
}
|
|
1533
|
+
};
|
|
1534
|
+
|
|
1535
|
+
//#endregion
|
|
1536
|
+
export { getDeviceInfo as a, warmupWasm as c, IdCaptureModelType as d, IncodeCanvas as i, mlWasmJSApi_default as l, MotionSensorProvider as n, getWindowDimensions as o, createDeepsightService as r, getUserAgent as s, BaseWasmProvider as t, WasmPipelineType as u };
|