@incodetech/core 2.0.0-alpha.1 → 2.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Manager-Cy9-TMC9.d.ts +19 -0
- package/dist/OpenViduLogger-20ZYS-mT.esm.js +3 -0
- package/dist/OpenViduLogger-5b7KqNTo.esm.js +803 -0
- package/dist/StateMachine-BqPpBhOz.d.ts +2 -0
- package/dist/addEvent-s2Za-pK3.esm.js +16 -0
- package/dist/chunk-C_Yo44FK.esm.js +49 -0
- package/dist/deepsightLoader-Bn2D0REl.esm.js +25 -0
- package/dist/email.d.ts +264 -0
- package/dist/email.esm.js +479 -0
- package/dist/endpoints-B0ltwtb5.esm.js +2335 -0
- package/dist/flow.d.ts +578 -0
- package/dist/flow.esm.js +628 -0
- package/dist/getBrowser-CLEzz0Hi.esm.js +8 -0
- package/dist/index.d.ts +226 -0
- package/dist/index.esm.js +156 -0
- package/dist/lib-CykGFCEr.esm.js +11700 -0
- package/dist/permissionServices-BhD0KxsO.esm.js +66 -0
- package/dist/phone.d.ts +292 -0
- package/dist/phone.esm.js +550 -0
- package/dist/recordingsRepository-CTjaf-ER.esm.js +256 -0
- package/dist/selfie.d.ts +821 -0
- package/dist/selfie.esm.js +1087 -0
- package/dist/types-Dif6MQmX.d.ts +5 -0
- package/dist/warmup-Cijuyvoc.d.ts +55 -0
- package/dist/xstate.esm-2T5fOCTq.esm.js +3261 -0
- package/package.json +14 -11
- package/src/camera/cameraActor.ts +0 -21
- package/src/camera/cameraService.test.ts +0 -437
- package/src/camera/cameraService.ts +0 -165
- package/src/camera/cameraServices.test.ts +0 -66
- package/src/camera/cameraServices.ts +0 -26
- package/src/camera/cameraStateMachine.test.ts +0 -602
- package/src/camera/cameraStateMachine.ts +0 -264
- package/src/camera/index.ts +0 -5
- package/src/camera/types.ts +0 -17
- package/src/device/getBrowser.ts +0 -31
- package/src/device/getDeviceClass.ts +0 -29
- package/src/device/index.ts +0 -2
- package/src/email/__mocks__/emailMocks.ts +0 -59
- package/src/email/emailActor.ts +0 -15
- package/src/email/emailManager.test.ts +0 -573
- package/src/email/emailManager.ts +0 -427
- package/src/email/emailServices.ts +0 -66
- package/src/email/emailStateMachine.test.ts +0 -741
- package/src/email/emailStateMachine.ts +0 -367
- package/src/email/index.ts +0 -39
- package/src/email/types.ts +0 -60
- package/src/events/addEvent.ts +0 -20
- package/src/events/types.ts +0 -7
- package/src/flow/__mocks__/flowMocks.ts +0 -84
- package/src/flow/flowActor.ts +0 -13
- package/src/flow/flowAnalyzer.test.ts +0 -266
- package/src/flow/flowAnalyzer.ts +0 -37
- package/src/flow/flowCompletionService.ts +0 -21
- package/src/flow/flowManager.test.ts +0 -560
- package/src/flow/flowManager.ts +0 -235
- package/src/flow/flowServices.test.ts +0 -109
- package/src/flow/flowServices.ts +0 -13
- package/src/flow/flowStateMachine.test.ts +0 -334
- package/src/flow/flowStateMachine.ts +0 -182
- package/src/flow/index.ts +0 -21
- package/src/flow/moduleLoader.test.ts +0 -136
- package/src/flow/moduleLoader.ts +0 -73
- package/src/flow/orchestratedFlowManager.test.ts +0 -240
- package/src/flow/orchestratedFlowManager.ts +0 -231
- package/src/flow/orchestratedFlowStateMachine.test.ts +0 -199
- package/src/flow/orchestratedFlowStateMachine.ts +0 -325
- package/src/flow/types.ts +0 -434
- package/src/http/__mocks__/api.ts +0 -88
- package/src/http/api.test.ts +0 -231
- package/src/http/api.ts +0 -90
- package/src/http/endpoints.ts +0 -17
- package/src/index.ts +0 -33
- package/src/permissions/index.ts +0 -2
- package/src/permissions/permissionServices.ts +0 -31
- package/src/permissions/types.ts +0 -3
- package/src/phone/__mocks__/phoneMocks.ts +0 -71
- package/src/phone/index.ts +0 -39
- package/src/phone/phoneActor.ts +0 -15
- package/src/phone/phoneManager.test.ts +0 -393
- package/src/phone/phoneManager.ts +0 -458
- package/src/phone/phoneServices.ts +0 -98
- package/src/phone/phoneStateMachine.test.ts +0 -918
- package/src/phone/phoneStateMachine.ts +0 -422
- package/src/phone/types.ts +0 -83
- package/src/recordings/recordingsRepository.test.ts +0 -87
- package/src/recordings/recordingsRepository.ts +0 -48
- package/src/recordings/streamingEvents.ts +0 -10
- package/src/selfie/__mocks__/selfieMocks.ts +0 -26
- package/src/selfie/index.ts +0 -14
- package/src/selfie/selfieActor.ts +0 -17
- package/src/selfie/selfieErrorUtils.test.ts +0 -116
- package/src/selfie/selfieErrorUtils.ts +0 -66
- package/src/selfie/selfieManager.test.ts +0 -297
- package/src/selfie/selfieManager.ts +0 -301
- package/src/selfie/selfieServices.ts +0 -362
- package/src/selfie/selfieStateMachine.test.ts +0 -283
- package/src/selfie/selfieStateMachine.ts +0 -804
- package/src/selfie/selfieUploadService.test.ts +0 -90
- package/src/selfie/selfieUploadService.ts +0 -81
- package/src/selfie/types.ts +0 -103
- package/src/session/index.ts +0 -5
- package/src/session/sessionService.ts +0 -78
- package/src/setup.test.ts +0 -61
- package/src/setup.ts +0 -171
- package/tsconfig.json +0 -13
- package/tsdown.config.ts +0 -22
- package/vitest.config.ts +0 -37
- package/vitest.setup.ts +0 -135
|
@@ -0,0 +1,2335 @@
|
|
|
1
|
+
import { a as __toDynamicImportESM } from "./chunk-C_Yo44FK.esm.js";
|
|
2
|
+
|
|
3
|
+
//#region ../infra/src/capabilities/platform.ts
|
|
4
|
+
function isIOS(userAgent) {
|
|
5
|
+
const ua = userAgent || (typeof navigator !== "undefined" ? navigator.userAgent : "");
|
|
6
|
+
const hasTouchPoints = typeof navigator !== "undefined" ? navigator.maxTouchPoints > 0 : false;
|
|
7
|
+
return /iPad|iPhone|iPod/.test(ua) || /Mac OS/.test(ua) && hasTouchPoints || /iPadOS/.test(ua);
|
|
8
|
+
}
|
|
9
|
+
function isAndroid(userAgent) {
|
|
10
|
+
const ua = userAgent || (typeof navigator !== "undefined" ? navigator.userAgent : "");
|
|
11
|
+
return /Android/i.test(ua);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region ../infra/src/http/createApi.ts
|
|
16
|
+
var FetchHttpError = class extends Error {
|
|
17
|
+
constructor(status, statusText, url, method, headers, data) {
|
|
18
|
+
super(`HTTP ${status} ${statusText}`);
|
|
19
|
+
this.ok = false;
|
|
20
|
+
this.status = status;
|
|
21
|
+
this.statusText = statusText;
|
|
22
|
+
this.url = url;
|
|
23
|
+
this.method = method;
|
|
24
|
+
this.headers = headers;
|
|
25
|
+
this.data = data;
|
|
26
|
+
this.name = "FetchHttpError";
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const buildQueryString = (query) => {
|
|
30
|
+
if (!query) return "";
|
|
31
|
+
const params = new URLSearchParams();
|
|
32
|
+
Object.entries(query).forEach(([key, value]) => {
|
|
33
|
+
if (value !== void 0 && value !== null) params.append(key, String(value));
|
|
34
|
+
});
|
|
35
|
+
const str = params.toString();
|
|
36
|
+
return str ? `?${str}` : "";
|
|
37
|
+
};
|
|
38
|
+
const buildUrl = (baseURL, url, query) => {
|
|
39
|
+
const queryString = buildQueryString(query);
|
|
40
|
+
if (url.startsWith("http://") || url.startsWith("https://")) return `${url}${queryString}`;
|
|
41
|
+
return `${baseURL.endsWith("/") ? baseURL.slice(0, -1) : baseURL}${url.startsWith("/") ? url : `/${url}`}${queryString}`;
|
|
42
|
+
};
|
|
43
|
+
const prepareBody = (body) => {
|
|
44
|
+
if (body === null || body === void 0) return null;
|
|
45
|
+
if (body instanceof FormData || body instanceof Blob || body instanceof ArrayBuffer) return body;
|
|
46
|
+
if (typeof body === "object") return JSON.stringify(body);
|
|
47
|
+
return String(body);
|
|
48
|
+
};
|
|
49
|
+
const parseResponse = async (response, parseType) => {
|
|
50
|
+
if (parseType === "response") return response;
|
|
51
|
+
if (parseType === "blob") return await response.blob();
|
|
52
|
+
if (parseType === "arrayBuffer") return await response.arrayBuffer();
|
|
53
|
+
if (parseType === "text") return await response.text();
|
|
54
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
55
|
+
if (parseType === "json" || contentType.includes("application/json")) try {
|
|
56
|
+
return await response.json();
|
|
57
|
+
} catch {
|
|
58
|
+
return await response.text();
|
|
59
|
+
}
|
|
60
|
+
return await response.text();
|
|
61
|
+
};
|
|
62
|
+
const DEFAULT_TIMEOUT = 3e4;
|
|
63
|
+
const createApi = (config) => {
|
|
64
|
+
const headers = {
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
Accept: "application/json",
|
|
67
|
+
"api-version": "1.0",
|
|
68
|
+
...config.customHeaders ?? {}
|
|
69
|
+
};
|
|
70
|
+
const defaults = {
|
|
71
|
+
baseURL: config.apiURL,
|
|
72
|
+
headers
|
|
73
|
+
};
|
|
74
|
+
const client$1 = {
|
|
75
|
+
defaults,
|
|
76
|
+
async request(requestConfig) {
|
|
77
|
+
const { method = "GET", url, headers: headers$1 = {}, query, params, body, signal, timeout = config.timeout ?? DEFAULT_TIMEOUT, parse } = requestConfig;
|
|
78
|
+
const fullUrl = buildUrl(defaults.baseURL, url, params ?? query);
|
|
79
|
+
const mergedHeaders = {
|
|
80
|
+
...defaults.headers,
|
|
81
|
+
...headers$1
|
|
82
|
+
};
|
|
83
|
+
const controller = new AbortController();
|
|
84
|
+
const abortSignal = signal ?? controller.signal;
|
|
85
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
86
|
+
try {
|
|
87
|
+
const requestBody = prepareBody(body);
|
|
88
|
+
let finalHeaders = mergedHeaders;
|
|
89
|
+
if (requestBody === null && (method === "POST" || method === "PUT" || method === "PATCH")) {
|
|
90
|
+
const { "Content-Type": _, ...headersWithoutContentType } = mergedHeaders;
|
|
91
|
+
finalHeaders = headersWithoutContentType;
|
|
92
|
+
}
|
|
93
|
+
const response = await fetch(fullUrl, {
|
|
94
|
+
method,
|
|
95
|
+
headers: finalHeaders,
|
|
96
|
+
body: requestBody,
|
|
97
|
+
signal: abortSignal
|
|
98
|
+
});
|
|
99
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
100
|
+
const responseHeaders = {};
|
|
101
|
+
response.headers.forEach((value, key) => {
|
|
102
|
+
responseHeaders[key] = value;
|
|
103
|
+
});
|
|
104
|
+
const data = await parseResponse(response, parse);
|
|
105
|
+
if (!response.ok) throw new FetchHttpError(response.status, response.statusText, fullUrl, method, responseHeaders, data);
|
|
106
|
+
return {
|
|
107
|
+
ok: true,
|
|
108
|
+
status: response.status,
|
|
109
|
+
statusText: response.statusText,
|
|
110
|
+
url: fullUrl,
|
|
111
|
+
headers: responseHeaders,
|
|
112
|
+
data
|
|
113
|
+
};
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
116
|
+
if (error instanceof FetchHttpError) throw error;
|
|
117
|
+
if (error instanceof Error && error.name === "AbortError") throw new FetchHttpError(0, "Request timeout", fullUrl, method, {}, null);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
get(url, config$1) {
|
|
122
|
+
return client$1.request({
|
|
123
|
+
...config$1,
|
|
124
|
+
url,
|
|
125
|
+
method: "GET"
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
post(url, body, config$1) {
|
|
129
|
+
return client$1.request({
|
|
130
|
+
...config$1,
|
|
131
|
+
url,
|
|
132
|
+
body,
|
|
133
|
+
method: "POST"
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
put(url, body, config$1) {
|
|
137
|
+
return client$1.request({
|
|
138
|
+
...config$1,
|
|
139
|
+
url,
|
|
140
|
+
body,
|
|
141
|
+
method: "PUT"
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
patch(url, body, config$1) {
|
|
145
|
+
return client$1.request({
|
|
146
|
+
...config$1,
|
|
147
|
+
url,
|
|
148
|
+
body,
|
|
149
|
+
method: "PATCH"
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
delete(url, config$1) {
|
|
153
|
+
return client$1.request({
|
|
154
|
+
...config$1,
|
|
155
|
+
url,
|
|
156
|
+
method: "DELETE"
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
head(url, config$1) {
|
|
160
|
+
return client$1.request({
|
|
161
|
+
...config$1,
|
|
162
|
+
url,
|
|
163
|
+
method: "HEAD"
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
options(url, config$1) {
|
|
167
|
+
return client$1.request({
|
|
168
|
+
...config$1,
|
|
169
|
+
url,
|
|
170
|
+
method: "OPTIONS"
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
setHeader(name, value) {
|
|
174
|
+
defaults.headers[name] = value;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
return client$1;
|
|
178
|
+
};
|
|
179
|
+
var createApi_default = createApi;
|
|
180
|
+
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region ../infra/src/manager/Manager.ts
|
|
183
|
+
/**
|
|
184
|
+
* Creates a manager that wraps a state machine actor with a clean public API.
|
|
185
|
+
*
|
|
186
|
+
* The manager provides:
|
|
187
|
+
* - `getState()` - Returns the mapped public state
|
|
188
|
+
* - `subscribe()` - Listen to state changes
|
|
189
|
+
* - `stop()` - Stop the actor
|
|
190
|
+
* - Plus any custom API methods from `createApi`
|
|
191
|
+
*
|
|
192
|
+
* @template TMachine - The state machine type
|
|
193
|
+
* @template TMapState - Function type that maps raw snapshot to public state
|
|
194
|
+
* @template TCreateApi - Function type that creates the custom API
|
|
195
|
+
*
|
|
196
|
+
* @param options - Configuration options
|
|
197
|
+
* @param options.actor - The started actor instance
|
|
198
|
+
* @param options.mapState - Function to transform raw snapshot into public state
|
|
199
|
+
* @param options.createApi - Factory function to create custom API methods
|
|
200
|
+
*
|
|
201
|
+
* @returns Combined manager with base methods and custom API
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* const manager = createManager({
|
|
206
|
+
* actor: createActor(myMachine).start(),
|
|
207
|
+
* mapState: (snapshot) => ({ status: snapshot.value }),
|
|
208
|
+
* createApi: ({ actor }) => ({
|
|
209
|
+
* doSomething() { actor.send({ type: 'DO_IT' }); }
|
|
210
|
+
* }),
|
|
211
|
+
* });
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
function createManager(options) {
|
|
215
|
+
const { actor, mapState, createApi: createApi$1 } = options;
|
|
216
|
+
function getSnapshot() {
|
|
217
|
+
return actor.getSnapshot();
|
|
218
|
+
}
|
|
219
|
+
function getState() {
|
|
220
|
+
return mapState(getSnapshot());
|
|
221
|
+
}
|
|
222
|
+
function subscribe(listener) {
|
|
223
|
+
const subscription = actor.subscribe(() => {
|
|
224
|
+
listener(getState());
|
|
225
|
+
});
|
|
226
|
+
return () => subscription.unsubscribe();
|
|
227
|
+
}
|
|
228
|
+
const api$1 = createApi$1({
|
|
229
|
+
actor,
|
|
230
|
+
getSnapshot
|
|
231
|
+
});
|
|
232
|
+
const base = {
|
|
233
|
+
getState,
|
|
234
|
+
subscribe,
|
|
235
|
+
stop() {
|
|
236
|
+
actor.stop();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
return Object.defineProperties(base, Object.getOwnPropertyDescriptors(api$1));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region ../infra/src/media/camera.ts
|
|
244
|
+
async function requestCameraAccess(constraints) {
|
|
245
|
+
if (typeof navigator === "undefined" || !navigator.mediaDevices) throw new Error("MediaDevices API not available");
|
|
246
|
+
return navigator.mediaDevices.getUserMedia(constraints);
|
|
247
|
+
}
|
|
248
|
+
function stopCameraStream(stream) {
|
|
249
|
+
for (const track of stream.getTracks()) track.stop();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region ../infra/src/media/canvas.ts
|
|
254
|
+
/**
|
|
255
|
+
* Class representing a canvas element for image capture and manipulation.
|
|
256
|
+
*/
|
|
257
|
+
var IncodeCanvas = class IncodeCanvas {
|
|
258
|
+
/**
|
|
259
|
+
* Creates an {@link IncodeCanvas} from a raw {@link ImageData} frame.
|
|
260
|
+
* @param imageData - Frame pixels in RGBA format
|
|
261
|
+
* @returns An {@link IncodeCanvas} containing the provided pixels
|
|
262
|
+
*/
|
|
263
|
+
static fromImageData(imageData) {
|
|
264
|
+
const canvas = document.createElement("canvas");
|
|
265
|
+
canvas.width = imageData.width;
|
|
266
|
+
canvas.height = imageData.height;
|
|
267
|
+
const context = canvas.getContext("2d", { willReadFrequently: true });
|
|
268
|
+
if (!context) return new IncodeCanvas(canvas);
|
|
269
|
+
if ("putImageData" in context) context.putImageData(imageData, 0, 0);
|
|
270
|
+
return new IncodeCanvas(canvas);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Create a new canvas element.
|
|
274
|
+
* @param canvas_ - The canvas element to clone.
|
|
275
|
+
*/
|
|
276
|
+
constructor(canvas_) {
|
|
277
|
+
this.base64Image = null;
|
|
278
|
+
this.blobData = null;
|
|
279
|
+
this.canvas = document.createElement("canvas");
|
|
280
|
+
this.canvas.width = canvas_.width;
|
|
281
|
+
this.canvas.height = canvas_.height;
|
|
282
|
+
const context = this.canvas.getContext("2d");
|
|
283
|
+
if (context) context.drawImage(canvas_, 0, 0);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Check if the current canvas is valid.
|
|
287
|
+
*/
|
|
288
|
+
checkCanvas() {
|
|
289
|
+
return this.canvas && this.canvas.width > 1 && this.canvas.height > 1;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Release the data stored by IncodeCanvas.
|
|
293
|
+
*/
|
|
294
|
+
release() {
|
|
295
|
+
if (!this.checkCanvas()) return;
|
|
296
|
+
this.canvas.width = 1;
|
|
297
|
+
this.canvas.height = 1;
|
|
298
|
+
this.canvas.getContext("2d")?.clearRect(0, 0, 1, 1);
|
|
299
|
+
this.base64Image = null;
|
|
300
|
+
this.blobData = null;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Get the width of the canvas.
|
|
304
|
+
*/
|
|
305
|
+
width() {
|
|
306
|
+
if (!this.checkCanvas()) return null;
|
|
307
|
+
return this.canvas.width;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Get the height of the canvas.
|
|
311
|
+
*/
|
|
312
|
+
height() {
|
|
313
|
+
if (!this.checkCanvas()) return null;
|
|
314
|
+
return this.canvas.height;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Set the width of the canvas.
|
|
318
|
+
*/
|
|
319
|
+
setWidth(width) {
|
|
320
|
+
if (!this.checkCanvas()) return;
|
|
321
|
+
this.canvas.width = width;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Set the height of the canvas.
|
|
325
|
+
*/
|
|
326
|
+
setHeight(height) {
|
|
327
|
+
if (!this.checkCanvas()) return;
|
|
328
|
+
this.canvas.height = height;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Clone the current canvas.
|
|
332
|
+
*/
|
|
333
|
+
clone() {
|
|
334
|
+
if (!this.checkCanvas()) return null;
|
|
335
|
+
const cloned = new IncodeCanvas(this.canvas);
|
|
336
|
+
cloned.setBase64Image(this.base64Image);
|
|
337
|
+
return cloned;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Deep clone the current IncodeCanvas including blob data.
|
|
341
|
+
*/
|
|
342
|
+
async deepClone() {
|
|
343
|
+
const cloned = this.clone();
|
|
344
|
+
if (!cloned) return null;
|
|
345
|
+
if (this.blobData) await cloned.setBlobData(this.blobData);
|
|
346
|
+
return cloned;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Returns the drawing context on the canvas.
|
|
350
|
+
*/
|
|
351
|
+
getContext(contextId, contextAttributes) {
|
|
352
|
+
if (!this.checkCanvas()) return null;
|
|
353
|
+
const context = this.canvas.getContext(contextId, contextAttributes);
|
|
354
|
+
return context instanceof CanvasRenderingContext2D ? context : null;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Retrieves the image data from the canvas.
|
|
358
|
+
*/
|
|
359
|
+
getImageData() {
|
|
360
|
+
if (!this.checkCanvas()) return null;
|
|
361
|
+
const context = this.canvas.getContext("2d", { willReadFrequently: true });
|
|
362
|
+
if (!context) return null;
|
|
363
|
+
return context.getImageData(0, 0, this.canvas.width, this.canvas.height);
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Updates the base64 representation of the current canvas image.
|
|
367
|
+
*/
|
|
368
|
+
updateBase64Image(jpegQuality = 1) {
|
|
369
|
+
if (!this.checkCanvas()) return;
|
|
370
|
+
this.base64Image = this.canvas.toDataURL("image/jpeg", jpegQuality);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Converts the current canvas element to a base64 string.
|
|
374
|
+
*/
|
|
375
|
+
getBase64Image(jpegQuality = 1, includeDataURLPrefix = false) {
|
|
376
|
+
if (!this.checkCanvas()) return null;
|
|
377
|
+
if (this.base64Image === null) this.updateBase64Image(jpegQuality);
|
|
378
|
+
const base64Image = this.base64Image;
|
|
379
|
+
if (base64Image === null) return null;
|
|
380
|
+
if (includeDataURLPrefix) return base64Image;
|
|
381
|
+
const commaIndex = base64Image.indexOf(",");
|
|
382
|
+
if (commaIndex === -1) return base64Image;
|
|
383
|
+
return base64Image.slice(commaIndex + 1);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Sets the base64 representation of the current canvas image.
|
|
387
|
+
*/
|
|
388
|
+
setBase64Image(base64Image) {
|
|
389
|
+
this.base64Image = base64Image;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Updates the Blob representation of the current canvas image.
|
|
393
|
+
*/
|
|
394
|
+
updateBlob(jpegQuality = 1, includeDataURLPrefix = false) {
|
|
395
|
+
if (!this.checkCanvas()) return;
|
|
396
|
+
if (this.base64Image === null) this.updateBase64Image(jpegQuality);
|
|
397
|
+
const base64 = this.getBase64Image(jpegQuality, includeDataURLPrefix);
|
|
398
|
+
if (base64) this.blobData = IncodeCanvas.base64ToBlob(base64);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Converts a base64 string to a Blob and creates a URL for it.
|
|
402
|
+
*/
|
|
403
|
+
static base64ToBlob(base64) {
|
|
404
|
+
try {
|
|
405
|
+
const binary = atob(base64);
|
|
406
|
+
const array = [];
|
|
407
|
+
for (let i = 0; i < binary.length; i++) array.push(binary.charCodeAt(i));
|
|
408
|
+
const blob = new Blob([new Uint8Array(array)]);
|
|
409
|
+
return {
|
|
410
|
+
blob,
|
|
411
|
+
url: URL.createObjectURL(blob)
|
|
412
|
+
};
|
|
413
|
+
} catch (error) {
|
|
414
|
+
console.error("Failed to convert base64 string to Blob:", error);
|
|
415
|
+
}
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Retrieves the Blob data and its URL from the current canvas.
|
|
420
|
+
*/
|
|
421
|
+
getBlobData(jpegQuality = 1, includeDataURLPrefix = false) {
|
|
422
|
+
if (!this.checkCanvas()) return null;
|
|
423
|
+
if (this.blobData === null) this.updateBlob(jpegQuality, includeDataURLPrefix);
|
|
424
|
+
return this.blobData;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Sets the Blob data of the current canvas image.
|
|
428
|
+
*/
|
|
429
|
+
async setBlobData(blobData) {
|
|
430
|
+
const blobDataArrayBuffer = await blobData.blob.arrayBuffer();
|
|
431
|
+
this.blobData = {
|
|
432
|
+
blob: new Blob([blobDataArrayBuffer], { type: blobData.blob.type }),
|
|
433
|
+
url: blobData.url
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Returns a resized canvas according to video element size.
|
|
438
|
+
*/
|
|
439
|
+
getResizedCanvas(videoElementWidth, videoElementHeight) {
|
|
440
|
+
if (!this.checkCanvas()) return null;
|
|
441
|
+
const cameraOffsetX = Math.abs(videoElementWidth - window.innerWidth);
|
|
442
|
+
const resized = new IncodeCanvas(document.createElement("canvas"));
|
|
443
|
+
const canvasHeight = this.height();
|
|
444
|
+
if (!canvasHeight) return null;
|
|
445
|
+
const ratio = canvasHeight / videoElementHeight;
|
|
446
|
+
const newWidth = window.innerWidth;
|
|
447
|
+
const newHeight = window.innerHeight;
|
|
448
|
+
resized.setWidth(newWidth);
|
|
449
|
+
resized.setHeight(newHeight);
|
|
450
|
+
const context = resized.getContext("2d");
|
|
451
|
+
if (!context) {
|
|
452
|
+
console.error("Failed to get 2d context in getResizedCanvas method.");
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
context.drawImage(this.canvas, ratio * cameraOffsetX / 2, 0, ratio * newWidth, ratio * newHeight, 0, 0, newWidth, newHeight);
|
|
456
|
+
return resized;
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
//#endregion
|
|
461
|
+
//#region ../infra/src/media/permissions.ts
|
|
462
|
+
async function queryPermission(name) {
|
|
463
|
+
try {
|
|
464
|
+
if (typeof navigator === "undefined" || !navigator.permissions) return "prompt";
|
|
465
|
+
return (await navigator.permissions.query({ name })).state;
|
|
466
|
+
} catch {
|
|
467
|
+
return "prompt";
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
async function queryCameraPermission() {
|
|
471
|
+
return queryPermission("camera");
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
//#endregion
|
|
475
|
+
//#region ../infra/src/media/StreamCanvasCapture.ts
|
|
476
|
+
var StreamCanvasCapture = class {
|
|
477
|
+
constructor(stream, options) {
|
|
478
|
+
this.hasFrame = false;
|
|
479
|
+
this.disposed = false;
|
|
480
|
+
this.eventTarget = new EventTarget();
|
|
481
|
+
this.video = document.createElement("video");
|
|
482
|
+
this.video.srcObject = stream;
|
|
483
|
+
this.video.autoplay = true;
|
|
484
|
+
this.video.playsInline = true;
|
|
485
|
+
this.video.muted = true;
|
|
486
|
+
const settings = stream.getVideoTracks()[0]?.getSettings();
|
|
487
|
+
const width = options?.width ?? settings?.width ?? 640;
|
|
488
|
+
const height = options?.height ?? settings?.height ?? 480;
|
|
489
|
+
this.canvas = document.createElement("canvas");
|
|
490
|
+
this.canvas.width = width;
|
|
491
|
+
this.canvas.height = height;
|
|
492
|
+
this.ctx = this.canvas.getContext("2d", { willReadFrequently: true });
|
|
493
|
+
const fps = options?.fps ?? 10;
|
|
494
|
+
const intervalMs = fps > 0 ? Math.max(16, Math.floor(1e3 / fps)) : 0;
|
|
495
|
+
try {
|
|
496
|
+
this.video.play();
|
|
497
|
+
} catch {}
|
|
498
|
+
this.rafLoop(intervalMs);
|
|
499
|
+
}
|
|
500
|
+
addEventListener(type, listener, options) {
|
|
501
|
+
this.eventTarget.addEventListener(type, listener, options);
|
|
502
|
+
}
|
|
503
|
+
removeEventListener(type, listener, options) {
|
|
504
|
+
this.eventTarget.removeEventListener(type, listener, options);
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Returns the latest cached frame as an {@link IncodeCanvas}.
|
|
508
|
+
*/
|
|
509
|
+
getLatestCanvas() {
|
|
510
|
+
if (!this.hasFrame) this.tick();
|
|
511
|
+
if (!this.hasFrame) return null;
|
|
512
|
+
return new IncodeCanvas(this.canvas);
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Returns the latest cached frame as raw {@link ImageData}.
|
|
516
|
+
*/
|
|
517
|
+
getLatestFrame() {
|
|
518
|
+
if (!this.ctx) return null;
|
|
519
|
+
if (!this.hasFrame) this.tick();
|
|
520
|
+
if (!this.hasFrame) return null;
|
|
521
|
+
try {
|
|
522
|
+
return this.ctx.getImageData(0, 0, this.canvas.width, this.canvas.height);
|
|
523
|
+
} catch {
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Disposes internal resources and stops the capture loop.
|
|
529
|
+
*/
|
|
530
|
+
dispose() {
|
|
531
|
+
if (this.disposed) return;
|
|
532
|
+
this.disposed = true;
|
|
533
|
+
if (this.rafId !== void 0) {
|
|
534
|
+
window.cancelAnimationFrame(this.rafId);
|
|
535
|
+
this.rafId = void 0;
|
|
536
|
+
}
|
|
537
|
+
this.video.srcObject = null;
|
|
538
|
+
this.canvas.width = 0;
|
|
539
|
+
this.canvas.height = 0;
|
|
540
|
+
this.hasFrame = false;
|
|
541
|
+
}
|
|
542
|
+
rafLoop(intervalMs) {
|
|
543
|
+
const loop = (timeMs) => {
|
|
544
|
+
if (this.disposed) return;
|
|
545
|
+
if (intervalMs <= 0 || this.lastTickTimeMs === void 0 || timeMs - this.lastTickTimeMs >= intervalMs) {
|
|
546
|
+
this.lastTickTimeMs = timeMs;
|
|
547
|
+
const previousFrameTimeSeconds = this.lastFrameTimeSeconds;
|
|
548
|
+
this.tick();
|
|
549
|
+
const currentFrameTimeSeconds = this.video.currentTime;
|
|
550
|
+
if (previousFrameTimeSeconds === void 0) {
|
|
551
|
+
if (this.hasFrame) {
|
|
552
|
+
this.lastFrameTimeSeconds = currentFrameTimeSeconds;
|
|
553
|
+
this.eventTarget.dispatchEvent(new Event("frame"));
|
|
554
|
+
}
|
|
555
|
+
} else if (this.hasFrame && currentFrameTimeSeconds !== previousFrameTimeSeconds) {
|
|
556
|
+
this.lastFrameTimeSeconds = currentFrameTimeSeconds;
|
|
557
|
+
this.eventTarget.dispatchEvent(new Event("frame"));
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
this.rafId = window.requestAnimationFrame(loop);
|
|
561
|
+
};
|
|
562
|
+
this.rafId = window.requestAnimationFrame(loop);
|
|
563
|
+
}
|
|
564
|
+
tick() {
|
|
565
|
+
if (!this.ctx) return;
|
|
566
|
+
if (this.video.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) return;
|
|
567
|
+
const videoWidth = this.video.videoWidth;
|
|
568
|
+
const videoHeight = this.video.videoHeight;
|
|
569
|
+
if (videoWidth === 0 || videoHeight === 0) return;
|
|
570
|
+
if (this.canvas.width !== videoWidth || this.canvas.height !== videoHeight) {
|
|
571
|
+
this.canvas.width = videoWidth;
|
|
572
|
+
this.canvas.height = videoHeight;
|
|
573
|
+
}
|
|
574
|
+
try {
|
|
575
|
+
this.ctx.drawImage(this.video, 0, 0);
|
|
576
|
+
this.hasFrame = true;
|
|
577
|
+
} catch {
|
|
578
|
+
this.hasFrame = false;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
//#endregion
|
|
584
|
+
//#region ../infra/src/media/StreamCanvasProcessingSession.ts
|
|
585
|
+
var StreamCanvasProcessingSession = class {
|
|
586
|
+
/**
|
|
587
|
+
* Creates a processing session that reacts to `StreamCanvasCapture` frame events
|
|
588
|
+
* and drives a provider's `processFrame()` method with backpressure.
|
|
589
|
+
*/
|
|
590
|
+
constructor(params) {
|
|
591
|
+
this.disposed = false;
|
|
592
|
+
this.isProcessing = false;
|
|
593
|
+
this.onFrameEvent = () => {
|
|
594
|
+
if (this.disposed || this.isProcessing) return;
|
|
595
|
+
const frame = this.capturer.getLatestFrame();
|
|
596
|
+
if (!frame) return;
|
|
597
|
+
this.onFrame?.(frame);
|
|
598
|
+
this.isProcessing = true;
|
|
599
|
+
this.provider.processFrame(frame).catch(() => {}).finally(() => {
|
|
600
|
+
this.isProcessing = false;
|
|
601
|
+
});
|
|
602
|
+
};
|
|
603
|
+
this.capturer = params.capturer;
|
|
604
|
+
this.provider = params.provider;
|
|
605
|
+
this.onFrame = params.onFrame;
|
|
606
|
+
this.capturer.addEventListener("frame", this.onFrameEvent);
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Unsubscribes from frame events and resets the provider.
|
|
610
|
+
*/
|
|
611
|
+
dispose() {
|
|
612
|
+
if (this.disposed) return;
|
|
613
|
+
this.disposed = true;
|
|
614
|
+
this.capturer.removeEventListener("frame", this.onFrameEvent);
|
|
615
|
+
this.provider.reset();
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Returns whether the session has been disposed.
|
|
619
|
+
*/
|
|
620
|
+
isDisposed() {
|
|
621
|
+
return this.disposed;
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
//#endregion
|
|
626
|
+
//#region ../infra/src/media/VideoTrimmer.ts
|
|
627
|
+
async function getDurationBySeek(videoBlob) {
|
|
628
|
+
const video = document.createElement("video");
|
|
629
|
+
video.preload = "metadata";
|
|
630
|
+
video.src = URL.createObjectURL(videoBlob);
|
|
631
|
+
try {
|
|
632
|
+
if (!Number.isFinite(video.duration)) {
|
|
633
|
+
video.currentTime = Number.MAX_SAFE_INTEGER;
|
|
634
|
+
await new Promise((resolve) => {
|
|
635
|
+
const onDurationChange = () => {
|
|
636
|
+
if (Number.isFinite(video.duration)) {
|
|
637
|
+
video.removeEventListener("durationchange", onDurationChange);
|
|
638
|
+
video.removeEventListener("timeupdate", onTimeUpdate);
|
|
639
|
+
resolve(video.duration);
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
const onTimeUpdate = () => {
|
|
643
|
+
if (Number.isFinite(video.duration)) {
|
|
644
|
+
video.removeEventListener("timeupdate", onTimeUpdate);
|
|
645
|
+
video.removeEventListener("durationchange", onDurationChange);
|
|
646
|
+
resolve(video.duration);
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
video.addEventListener("durationchange", onDurationChange);
|
|
650
|
+
video.addEventListener("timeupdate", onTimeUpdate);
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
const duration = video.duration;
|
|
654
|
+
return Number.isFinite(duration) ? duration : null;
|
|
655
|
+
} finally {
|
|
656
|
+
URL.revokeObjectURL(video.src);
|
|
657
|
+
video.src = "";
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
async function trimLastNSecondsUsingPlayback(videoBlob, seconds) {
|
|
661
|
+
console.log("[VideoTrimmer] Starting playback-based trimming...");
|
|
662
|
+
const video = document.createElement("video");
|
|
663
|
+
video.preload = "metadata";
|
|
664
|
+
video.playsInline = true;
|
|
665
|
+
video.muted = true;
|
|
666
|
+
const videoURL = URL.createObjectURL(videoBlob);
|
|
667
|
+
video.src = videoURL;
|
|
668
|
+
const duration = await getDurationBySeek(videoBlob);
|
|
669
|
+
console.log("[VideoTrimmer] Video duration:", duration);
|
|
670
|
+
if (!duration || duration < seconds) {
|
|
671
|
+
console.log("[VideoTrimmer] Video too short, returning original");
|
|
672
|
+
URL.revokeObjectURL(videoURL);
|
|
673
|
+
return videoBlob;
|
|
674
|
+
}
|
|
675
|
+
const startTime = Math.max(0, Math.floor(duration) - seconds);
|
|
676
|
+
console.log("[VideoTrimmer] Trimming from", startTime, "to", duration);
|
|
677
|
+
await new Promise((resolve) => {
|
|
678
|
+
if (video.readyState >= 2) resolve();
|
|
679
|
+
else video.addEventListener("loadedmetadata", () => resolve(), { once: true });
|
|
680
|
+
});
|
|
681
|
+
const canvas = document.createElement("canvas");
|
|
682
|
+
canvas.width = 230;
|
|
683
|
+
canvas.height = 320;
|
|
684
|
+
const captureFps = isAndroid() ? 15 : 24;
|
|
685
|
+
const stream = canvas.captureStream(captureFps);
|
|
686
|
+
const ctx = canvas.getContext("2d");
|
|
687
|
+
video.currentTime = startTime;
|
|
688
|
+
await new Promise((resolve) => {
|
|
689
|
+
video.addEventListener("seeked", () => resolve(), { once: true });
|
|
690
|
+
});
|
|
691
|
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
692
|
+
const mimeType = videoBlob.type || (MediaRecorder.isTypeSupported("video/webm") ? "video/webm" : "video/mp4");
|
|
693
|
+
const mediaRecorder = new MediaRecorder(stream.clone(), {
|
|
694
|
+
mimeType,
|
|
695
|
+
videoBitsPerSecond: 5e5,
|
|
696
|
+
bitsPerSecond: 5e5
|
|
697
|
+
});
|
|
698
|
+
const chunks = [];
|
|
699
|
+
mediaRecorder.ondataavailable = (event) => {
|
|
700
|
+
if (event.data.size > 0) chunks.push(event.data);
|
|
701
|
+
};
|
|
702
|
+
const recordingPromise = new Promise((resolve) => {
|
|
703
|
+
mediaRecorder.onstop = () => {
|
|
704
|
+
console.log("[VideoTrimmer] Recording stopped, chunks:", chunks.length);
|
|
705
|
+
const trimmedBlob = new Blob(chunks, { type: mimeType });
|
|
706
|
+
URL.revokeObjectURL(videoURL);
|
|
707
|
+
mediaRecorder.stream?.getTracks().forEach((track) => track.stop());
|
|
708
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
709
|
+
video.src = "";
|
|
710
|
+
console.log("[VideoTrimmer] Playback-based trimming complete, size:", trimmedBlob.size);
|
|
711
|
+
resolve(trimmedBlob);
|
|
712
|
+
};
|
|
713
|
+
});
|
|
714
|
+
video.addEventListener("play", () => {
|
|
715
|
+
console.log("[VideoTrimmer] Video playing, starting recording...");
|
|
716
|
+
function drawVideo() {
|
|
717
|
+
if (video.currentTime >= duration) {
|
|
718
|
+
console.log("[VideoTrimmer] Reached end, stopping...");
|
|
719
|
+
mediaRecorder.stop();
|
|
720
|
+
video.pause();
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
724
|
+
requestAnimationFrame(drawVideo);
|
|
725
|
+
}
|
|
726
|
+
drawVideo();
|
|
727
|
+
setTimeout(() => {
|
|
728
|
+
console.log("[VideoTrimmer] Starting MediaRecorder...");
|
|
729
|
+
mediaRecorder.start(100);
|
|
730
|
+
}, 500);
|
|
731
|
+
});
|
|
732
|
+
console.log("[VideoTrimmer] Starting video playback...");
|
|
733
|
+
video.play().catch((err) => {
|
|
734
|
+
console.error("[VideoTrimmer] Play failed:", err);
|
|
735
|
+
URL.revokeObjectURL(videoURL);
|
|
736
|
+
});
|
|
737
|
+
return await recordingPromise;
|
|
738
|
+
}
|
|
739
|
+
async function trimLastNSeconds(videoBlob, seconds) {
|
|
740
|
+
console.log(`[VideoTrimmer] trimLastNSeconds called (trim to ${seconds}s from ${videoBlob.size} bytes)`);
|
|
741
|
+
console.log("[VideoTrimmer] Using playback-based trimming");
|
|
742
|
+
return await trimLastNSecondsUsingPlayback(videoBlob, seconds);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
//#endregion
|
|
746
|
+
//#region ../infra/src/providers/browser/DeepsightRecordingProvider.ts
|
|
747
|
+
function toBase64(videoBlob) {
|
|
748
|
+
return new Promise((resolve, reject) => {
|
|
749
|
+
const reader = new FileReader();
|
|
750
|
+
reader.onloadend = () => {
|
|
751
|
+
const base64 = reader.result.split(",")[1];
|
|
752
|
+
resolve(base64);
|
|
753
|
+
};
|
|
754
|
+
reader.onerror = () => reject(reader.error ?? /* @__PURE__ */ new Error("FileReader error"));
|
|
755
|
+
reader.readAsDataURL(videoBlob);
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
function getSupportedMediaRecorderMimeType() {
|
|
759
|
+
const possibleTypes = isIOS() ? [
|
|
760
|
+
"video/mp4",
|
|
761
|
+
"video/webm",
|
|
762
|
+
"video/webm;codecs=vp9",
|
|
763
|
+
"video/webm;codecs=vp8"
|
|
764
|
+
] : [
|
|
765
|
+
"video/webm",
|
|
766
|
+
"video/webm;codecs=vp9",
|
|
767
|
+
"video/webm;codecs=vp8",
|
|
768
|
+
"video/mp4"
|
|
769
|
+
];
|
|
770
|
+
for (const type of possibleTypes) if (MediaRecorder.isTypeSupported(type)) return type;
|
|
771
|
+
return "";
|
|
772
|
+
}
|
|
773
|
+
function getAdaptiveMediaRecorderOptions() {
|
|
774
|
+
const mimeType = getSupportedMediaRecorderMimeType();
|
|
775
|
+
if (isIOS()) return {
|
|
776
|
+
mimeType,
|
|
777
|
+
videoBitsPerSecond: 1e6,
|
|
778
|
+
bitsPerSecond: 1e6
|
|
779
|
+
};
|
|
780
|
+
return {
|
|
781
|
+
mimeType,
|
|
782
|
+
videoBitsPerSecond: 5e5,
|
|
783
|
+
bitsPerSecond: 5e5
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
var DeepsightRecordingProvider = class {
|
|
787
|
+
constructor() {
|
|
788
|
+
this.mediaRecorder = null;
|
|
789
|
+
this._isRecording = false;
|
|
790
|
+
this._hasError = false;
|
|
791
|
+
this._error = null;
|
|
792
|
+
this.mimeType = "";
|
|
793
|
+
this.stream = null;
|
|
794
|
+
this.pauseRecordingBound = this.pauseRecording.bind(this);
|
|
795
|
+
}
|
|
796
|
+
get isRecording() {
|
|
797
|
+
return this._isRecording;
|
|
798
|
+
}
|
|
799
|
+
get hasError() {
|
|
800
|
+
return this._hasError;
|
|
801
|
+
}
|
|
802
|
+
get error() {
|
|
803
|
+
return this._error;
|
|
804
|
+
}
|
|
805
|
+
startRecording(stream) {
|
|
806
|
+
this.reset();
|
|
807
|
+
this.registerEventListeners();
|
|
808
|
+
this.stream = stream;
|
|
809
|
+
try {
|
|
810
|
+
const options = getAdaptiveMediaRecorderOptions();
|
|
811
|
+
this.mimeType = options.mimeType;
|
|
812
|
+
const recorder = new MediaRecorder(stream.clone(), options);
|
|
813
|
+
recorder.onerror = (event) => {
|
|
814
|
+
this._error = `Recording error: ${event}`;
|
|
815
|
+
this._isRecording = false;
|
|
816
|
+
this._hasError = true;
|
|
817
|
+
};
|
|
818
|
+
recorder.start();
|
|
819
|
+
this.mediaRecorder = recorder;
|
|
820
|
+
this._isRecording = true;
|
|
821
|
+
this._error = null;
|
|
822
|
+
this._hasError = false;
|
|
823
|
+
} catch (err) {
|
|
824
|
+
console.error(`Failed to start recording: ${err}`);
|
|
825
|
+
this._error = `Failed to start recording: ${err}`;
|
|
826
|
+
this._hasError = true;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
async stopRecording(trimSeconds, encrypt, generateChecksum) {
|
|
830
|
+
const recorder = this.mediaRecorder;
|
|
831
|
+
return new Promise((resolve, reject) => {
|
|
832
|
+
this.removeEventListeners();
|
|
833
|
+
if (recorder && this._isRecording) {
|
|
834
|
+
const chunks = [];
|
|
835
|
+
recorder.ondataavailable = (event) => {
|
|
836
|
+
if (event.data.size > 0) chunks.push(event.data);
|
|
837
|
+
};
|
|
838
|
+
recorder.onstop = async () => {
|
|
839
|
+
try {
|
|
840
|
+
const trimmedVideo = await trimLastNSeconds(new Blob(chunks, { type: this.mimeType }), trimSeconds);
|
|
841
|
+
const encryptedVideoBase64 = encrypt(await toBase64(trimmedVideo));
|
|
842
|
+
generateChecksum(await trimmedVideo.arrayBuffer());
|
|
843
|
+
this._isRecording = false;
|
|
844
|
+
resolve({
|
|
845
|
+
trimmedBlob: trimmedVideo,
|
|
846
|
+
encryptedVideo: encryptedVideoBase64
|
|
847
|
+
});
|
|
848
|
+
} catch (error) {
|
|
849
|
+
this._isRecording = false;
|
|
850
|
+
this._error = `Recording stop failed: ${error}`;
|
|
851
|
+
this._hasError = true;
|
|
852
|
+
reject(error);
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
recorder.stop();
|
|
856
|
+
this._isRecording = false;
|
|
857
|
+
} else resolve({
|
|
858
|
+
trimmedBlob: new Blob([], { type: this.mimeType }),
|
|
859
|
+
encryptedVideo: ""
|
|
860
|
+
});
|
|
861
|
+
recorder?.stream?.getTracks().forEach((track) => track.stop());
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
reset() {
|
|
865
|
+
this._isRecording = false;
|
|
866
|
+
this._error = null;
|
|
867
|
+
this._hasError = false;
|
|
868
|
+
}
|
|
869
|
+
pauseRecording() {
|
|
870
|
+
if (!this._isRecording) return;
|
|
871
|
+
if (this.mediaRecorder?.state === "recording") try {
|
|
872
|
+
this.mediaRecorder.pause();
|
|
873
|
+
} catch {}
|
|
874
|
+
}
|
|
875
|
+
registerEventListeners() {
|
|
876
|
+
document.addEventListener("visibilitychange", this.pauseRecordingBound);
|
|
877
|
+
}
|
|
878
|
+
removeEventListeners() {
|
|
879
|
+
document.removeEventListener("visibilitychange", this.pauseRecordingBound);
|
|
880
|
+
}
|
|
881
|
+
};
|
|
882
|
+
|
|
883
|
+
//#endregion
|
|
884
|
+
//#region ../infra/src/providers/browser/MotionSensorProvider.ts
|
|
885
|
+
var MotionSensorProvider = class {
|
|
886
|
+
constructor(thresholds) {
|
|
887
|
+
this._isRunning = false;
|
|
888
|
+
this._hasPermission = true;
|
|
889
|
+
this.acl = null;
|
|
890
|
+
this.gyro = null;
|
|
891
|
+
this.minNumberOfFrames = 3;
|
|
892
|
+
this.maxFrequency = 60;
|
|
893
|
+
this.emptyParams = {
|
|
894
|
+
meanX: 0,
|
|
895
|
+
meanY: 0,
|
|
896
|
+
meanZ: 0,
|
|
897
|
+
m2X: 0,
|
|
898
|
+
m2Y: 0,
|
|
899
|
+
m2Z: 0,
|
|
900
|
+
cumulativeAbsErrorX: 0,
|
|
901
|
+
cumulativeAbsErrorY: 0,
|
|
902
|
+
cumulativeAbsErrorZ: 0,
|
|
903
|
+
ptsNum: 0
|
|
904
|
+
};
|
|
905
|
+
this.paramsAcc = { ...this.emptyParams };
|
|
906
|
+
this.paramsGyro = { ...this.emptyParams };
|
|
907
|
+
this.paramsAccGrOld = { ...this.emptyParams };
|
|
908
|
+
this.paramsAccOld = { ...this.emptyParams };
|
|
909
|
+
this.paramsGyroscopeOld = { ...this.emptyParams };
|
|
910
|
+
this.paramsOrientationOld = { ...this.emptyParams };
|
|
911
|
+
this.deviceMotionListener = (event) => {
|
|
912
|
+
if (event.accelerationIncludingGravity) {
|
|
913
|
+
const accGrVal = {
|
|
914
|
+
x: event.accelerationIncludingGravity.x,
|
|
915
|
+
y: event.accelerationIncludingGravity.y,
|
|
916
|
+
z: event.accelerationIncludingGravity.z
|
|
917
|
+
};
|
|
918
|
+
if (this.checkFields(accGrVal)) {
|
|
919
|
+
this.paramsAccGrOld.ptsNum += 1;
|
|
920
|
+
this.updateParams(this.paramsAccGrOld, accGrVal);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
if (event.acceleration) {
|
|
924
|
+
const accVal = {
|
|
925
|
+
x: event.acceleration.x,
|
|
926
|
+
y: event.acceleration.y,
|
|
927
|
+
z: event.acceleration.z
|
|
928
|
+
};
|
|
929
|
+
if (this.checkFields(accVal)) {
|
|
930
|
+
this.paramsAccOld.ptsNum += 1;
|
|
931
|
+
this.updateParams(this.paramsAccOld, accVal);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
if (event.rotationRate) {
|
|
935
|
+
const gyroVal = {
|
|
936
|
+
x: event.rotationRate.alpha,
|
|
937
|
+
y: event.rotationRate.beta,
|
|
938
|
+
z: event.rotationRate.gamma
|
|
939
|
+
};
|
|
940
|
+
if (this.checkFields(gyroVal)) {
|
|
941
|
+
this.paramsGyroscopeOld.ptsNum += 1;
|
|
942
|
+
this.updateParams(this.paramsGyroscopeOld, gyroVal);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
this.deviceOrientationListener = (event) => {
|
|
947
|
+
const orientationVal = {
|
|
948
|
+
x: event.alpha,
|
|
949
|
+
y: event.beta,
|
|
950
|
+
z: event.gamma
|
|
951
|
+
};
|
|
952
|
+
if (this.checkFields(orientationVal)) {
|
|
953
|
+
this.paramsOrientationOld.ptsNum += 1;
|
|
954
|
+
this.updateParams(this.paramsOrientationOld, orientationVal);
|
|
955
|
+
}
|
|
956
|
+
};
|
|
957
|
+
this.thresholds = {
|
|
958
|
+
accThreshold: thresholds?.accThreshold ?? .3,
|
|
959
|
+
gyroThreshold: thresholds?.gyroThreshold ?? .3,
|
|
960
|
+
accGrOldThreshold: thresholds?.accGrOldThreshold ?? .3,
|
|
961
|
+
accOldThreshold: thresholds?.accOldThreshold ?? .3,
|
|
962
|
+
gyroscopeOldThreshold: thresholds?.gyroscopeOldThreshold ?? 10,
|
|
963
|
+
orientationOldThreshold: thresholds?.orientationOldThreshold ?? 10,
|
|
964
|
+
maeAccThreshold: thresholds?.maeAccThreshold ?? .3,
|
|
965
|
+
maeGyroThreshold: thresholds?.maeGyroThreshold ?? .3,
|
|
966
|
+
maeAccGrOldThreshold: thresholds?.maeAccGrOldThreshold ?? .3,
|
|
967
|
+
maeAccOldThreshold: thresholds?.maeAccOldThreshold ?? .3,
|
|
968
|
+
maeGyroscopeOldThreshold: thresholds?.maeGyroscopeOldThreshold ?? 10,
|
|
969
|
+
maeOrientationOldThreshold: thresholds?.maeOrientationOldThreshold ?? 10
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
get isRunning() {
|
|
973
|
+
return this._isRunning;
|
|
974
|
+
}
|
|
975
|
+
get hasPermission() {
|
|
976
|
+
return this._hasPermission;
|
|
977
|
+
}
|
|
978
|
+
async requestPermission() {
|
|
979
|
+
if (typeof DeviceMotionEvent !== "undefined" && typeof DeviceMotionEvent.requestPermission === "function") {
|
|
980
|
+
sessionStorage.setItem("motionSensorsPermissionsRequested", String(true));
|
|
981
|
+
try {
|
|
982
|
+
if (await DeviceMotionEvent.requestPermission() !== "granted") {
|
|
983
|
+
this._hasPermission = false;
|
|
984
|
+
return "denied";
|
|
985
|
+
}
|
|
986
|
+
return "granted";
|
|
987
|
+
} catch {
|
|
988
|
+
this._hasPermission = false;
|
|
989
|
+
return "denied";
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
return "not-required";
|
|
993
|
+
}
|
|
994
|
+
initializeAccelerometer() {
|
|
995
|
+
if (!("Accelerometer" in window)) return;
|
|
996
|
+
try {
|
|
997
|
+
const AccelerometerConstructor = window.Accelerometer;
|
|
998
|
+
if (AccelerometerConstructor) {
|
|
999
|
+
this.acl = new AccelerometerConstructor({ frequency: this.maxFrequency });
|
|
1000
|
+
this.acl.addEventListener("reading", () => this.updateAcc());
|
|
1001
|
+
}
|
|
1002
|
+
} catch {}
|
|
1003
|
+
}
|
|
1004
|
+
initializeGyroscope() {
|
|
1005
|
+
if (!("Gyroscope" in window)) return;
|
|
1006
|
+
try {
|
|
1007
|
+
const GyroscopeConstructor = window.Gyroscope;
|
|
1008
|
+
if (GyroscopeConstructor) {
|
|
1009
|
+
this.gyro = new GyroscopeConstructor({ frequency: this.maxFrequency });
|
|
1010
|
+
this.gyro.addEventListener("reading", () => this.updateGyro());
|
|
1011
|
+
}
|
|
1012
|
+
} catch {}
|
|
1013
|
+
}
|
|
1014
|
+
async start() {
|
|
1015
|
+
if (this._isRunning || !this._hasPermission) return;
|
|
1016
|
+
try {
|
|
1017
|
+
this.initializeAccelerometer();
|
|
1018
|
+
if (this.acl) this.acl.start();
|
|
1019
|
+
} catch {}
|
|
1020
|
+
try {
|
|
1021
|
+
this.initializeGyroscope();
|
|
1022
|
+
if (this.gyro) this.gyro.start();
|
|
1023
|
+
} catch {}
|
|
1024
|
+
window.addEventListener("devicemotion", this.deviceMotionListener);
|
|
1025
|
+
window.addEventListener("deviceorientation", this.deviceOrientationListener);
|
|
1026
|
+
this._isRunning = true;
|
|
1027
|
+
}
|
|
1028
|
+
stop() {
|
|
1029
|
+
this._isRunning = false;
|
|
1030
|
+
if (this.acl) this.acl.stop();
|
|
1031
|
+
if (this.gyro) this.gyro.stop();
|
|
1032
|
+
window.removeEventListener("devicemotion", this.deviceMotionListener);
|
|
1033
|
+
window.removeEventListener("deviceorientation", this.deviceOrientationListener);
|
|
1034
|
+
this.paramsAcc = { ...this.emptyParams };
|
|
1035
|
+
this.paramsGyro = { ...this.emptyParams };
|
|
1036
|
+
this.paramsAccGrOld = { ...this.emptyParams };
|
|
1037
|
+
this.paramsAccOld = { ...this.emptyParams };
|
|
1038
|
+
this.paramsGyroscopeOld = { ...this.emptyParams };
|
|
1039
|
+
this.paramsOrientationOld = { ...this.emptyParams };
|
|
1040
|
+
}
|
|
1041
|
+
updateAcc() {
|
|
1042
|
+
if (!this._isRunning || !this.acl) return;
|
|
1043
|
+
this.paramsAcc.ptsNum += 1;
|
|
1044
|
+
const val = {
|
|
1045
|
+
x: this.acl.x,
|
|
1046
|
+
y: this.acl.y,
|
|
1047
|
+
z: this.acl.z
|
|
1048
|
+
};
|
|
1049
|
+
if (this.checkFields(val)) this.updateParams(this.paramsAcc, val);
|
|
1050
|
+
}
|
|
1051
|
+
updateGyro() {
|
|
1052
|
+
if (!this._isRunning || !this.gyro) return;
|
|
1053
|
+
this.paramsGyro.ptsNum += 1;
|
|
1054
|
+
const val = {
|
|
1055
|
+
x: this.gyro.x,
|
|
1056
|
+
y: this.gyro.y,
|
|
1057
|
+
z: this.gyro.z
|
|
1058
|
+
};
|
|
1059
|
+
if (this.checkFields(val)) this.updateParams(this.paramsGyro, val);
|
|
1060
|
+
}
|
|
1061
|
+
check() {
|
|
1062
|
+
if (!this._hasPermission) return "UNCLEAR";
|
|
1063
|
+
const result = this.checkStability();
|
|
1064
|
+
return result === null ? "UNCLEAR" : result ? "FAIL" : "PASS";
|
|
1065
|
+
}
|
|
1066
|
+
checkStability() {
|
|
1067
|
+
if (!this._isRunning) return null;
|
|
1068
|
+
const filteredStdChecks = [
|
|
1069
|
+
this.gyro ? this.isBelowStdThreshold(this.paramsGyro, this.thresholds.gyroThreshold) : null,
|
|
1070
|
+
this.acl ? this.isBelowStdThreshold(this.paramsAcc, this.thresholds.accThreshold) : null,
|
|
1071
|
+
this.isBelowStdThreshold(this.paramsAccGrOld, this.thresholds.accGrOldThreshold),
|
|
1072
|
+
this.isBelowStdThreshold(this.paramsAccOld, this.thresholds.accOldThreshold),
|
|
1073
|
+
this.isBelowStdThreshold(this.paramsGyroscopeOld, this.thresholds.gyroscopeOldThreshold),
|
|
1074
|
+
this.isBelowStdThreshold(this.paramsOrientationOld, this.thresholds.orientationOldThreshold)
|
|
1075
|
+
].filter((check) => check !== null);
|
|
1076
|
+
const finalStdCheck = filteredStdChecks.length > 0 ? filteredStdChecks.every((check) => check) : null;
|
|
1077
|
+
const filteredMaeChecks = [
|
|
1078
|
+
this.gyro ? this.isBelowMaeThreshold(this.paramsGyro, this.thresholds.maeGyroThreshold) : null,
|
|
1079
|
+
this.acl ? this.isBelowMaeThreshold(this.paramsAcc, this.thresholds.maeAccThreshold) : null,
|
|
1080
|
+
this.isBelowMaeThreshold(this.paramsAccGrOld, this.thresholds.maeAccGrOldThreshold),
|
|
1081
|
+
this.isBelowMaeThreshold(this.paramsAccOld, this.thresholds.maeAccOldThreshold),
|
|
1082
|
+
this.isBelowMaeThreshold(this.paramsGyroscopeOld, this.thresholds.maeGyroscopeOldThreshold),
|
|
1083
|
+
this.isBelowMaeThreshold(this.paramsOrientationOld, this.thresholds.maeOrientationOldThreshold)
|
|
1084
|
+
].filter((check) => check !== null);
|
|
1085
|
+
const finalMaeCheck = filteredMaeChecks.length > 0 ? filteredMaeChecks.every((check) => check) : null;
|
|
1086
|
+
return finalStdCheck === null ? finalMaeCheck === null ? null : finalMaeCheck : finalMaeCheck !== null ? finalStdCheck && finalMaeCheck : finalStdCheck;
|
|
1087
|
+
}
|
|
1088
|
+
updateParams(params, val) {
|
|
1089
|
+
const deltaX = val.x - params.meanX;
|
|
1090
|
+
const deltaY = val.y - params.meanY;
|
|
1091
|
+
const deltaZ = val.z - params.meanZ;
|
|
1092
|
+
params.meanX += deltaX / params.ptsNum;
|
|
1093
|
+
params.meanY += deltaY / params.ptsNum;
|
|
1094
|
+
params.meanZ += deltaZ / params.ptsNum;
|
|
1095
|
+
params.m2X += deltaX * (val.x - params.meanX);
|
|
1096
|
+
params.m2Y += deltaY * (val.y - params.meanY);
|
|
1097
|
+
params.m2Z += deltaZ * (val.z - params.meanZ);
|
|
1098
|
+
params.cumulativeAbsErrorX += Math.abs(val.x - params.meanX);
|
|
1099
|
+
params.cumulativeAbsErrorY += Math.abs(val.y - params.meanY);
|
|
1100
|
+
params.cumulativeAbsErrorZ += Math.abs(val.z - params.meanZ);
|
|
1101
|
+
}
|
|
1102
|
+
calculateStd(params) {
|
|
1103
|
+
const variance = {
|
|
1104
|
+
x: params.m2X / params.ptsNum,
|
|
1105
|
+
y: params.m2Y / params.ptsNum,
|
|
1106
|
+
z: params.m2Z / params.ptsNum
|
|
1107
|
+
};
|
|
1108
|
+
return {
|
|
1109
|
+
x: Math.sqrt(variance.x),
|
|
1110
|
+
y: Math.sqrt(variance.y),
|
|
1111
|
+
z: Math.sqrt(variance.z)
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
calculateMae(params) {
|
|
1115
|
+
return {
|
|
1116
|
+
x: params.cumulativeAbsErrorX / params.ptsNum,
|
|
1117
|
+
y: params.cumulativeAbsErrorY / params.ptsNum,
|
|
1118
|
+
z: params.cumulativeAbsErrorZ / params.ptsNum
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
checkFields(point) {
|
|
1122
|
+
return point.x !== null && point.y !== null && point.z !== null;
|
|
1123
|
+
}
|
|
1124
|
+
isBelowStdThreshold(params, threshold) {
|
|
1125
|
+
if (params.ptsNum < this.minNumberOfFrames) return null;
|
|
1126
|
+
const std = this.calculateStd(params);
|
|
1127
|
+
return std.x < threshold && std.y < threshold && std.z < threshold;
|
|
1128
|
+
}
|
|
1129
|
+
isBelowMaeThreshold(params, threshold) {
|
|
1130
|
+
if (params.ptsNum < this.minNumberOfFrames) return null;
|
|
1131
|
+
const mae = this.calculateMae(params);
|
|
1132
|
+
return mae.x < threshold && mae.y < threshold && mae.z < threshold;
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1136
|
+
//#endregion
|
|
1137
|
+
//#region ../infra/src/providers/browser/openviduLazy.ts
|
|
1138
|
+
let openViduImport;
|
|
1139
|
+
async function enableProdModeBeforeLoad() {
|
|
1140
|
+
const { OpenViduLogger } = await import("./OpenViduLogger-20ZYS-mT.esm.js").then(__toDynamicImportESM(1));
|
|
1141
|
+
OpenViduLogger.getInstance().enableProdMode();
|
|
1142
|
+
}
|
|
1143
|
+
async function loadOpenVidu() {
|
|
1144
|
+
if (openViduImport) return openViduImport;
|
|
1145
|
+
await enableProdModeBeforeLoad();
|
|
1146
|
+
openViduImport = import("./lib-CykGFCEr.esm.js").then(__toDynamicImportESM(1));
|
|
1147
|
+
return openViduImport;
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
//#endregion
|
|
1151
|
+
//#region ../infra/src/providers/browser/OpenViduRecordingProvider.ts
|
|
1152
|
+
function createHiddenContainer() {
|
|
1153
|
+
const id = `inc_rec_${Math.random().toString(36).slice(2)}`;
|
|
1154
|
+
const existing = document.getElementById(id);
|
|
1155
|
+
if (existing) return {
|
|
1156
|
+
id,
|
|
1157
|
+
element: existing
|
|
1158
|
+
};
|
|
1159
|
+
const div = document.createElement("div");
|
|
1160
|
+
div.id = id;
|
|
1161
|
+
div.style.display = "none";
|
|
1162
|
+
document.body.appendChild(div);
|
|
1163
|
+
return {
|
|
1164
|
+
id,
|
|
1165
|
+
element: div
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
var OpenViduRecordingProvider = class {
|
|
1169
|
+
async connect(params) {
|
|
1170
|
+
const { OpenVidu } = await loadOpenVidu();
|
|
1171
|
+
const container = createHiddenContainer();
|
|
1172
|
+
const ov = new OpenVidu();
|
|
1173
|
+
const session = ov.initSession();
|
|
1174
|
+
const videoTrack = params.stream.getVideoTracks()[0];
|
|
1175
|
+
const audioTrack = params.stream.getAudioTracks()[0];
|
|
1176
|
+
const hasAudio = audioTrack !== void 0;
|
|
1177
|
+
const publisher = ov.initPublisher(container.id, {
|
|
1178
|
+
publishAudio: hasAudio,
|
|
1179
|
+
audioSource: hasAudio ? audioTrack : false,
|
|
1180
|
+
videoSource: videoTrack ?? false,
|
|
1181
|
+
frameRate: 30
|
|
1182
|
+
});
|
|
1183
|
+
session.on("exception", (event) => {
|
|
1184
|
+
const e = event;
|
|
1185
|
+
params.events?.onSessionException?.({
|
|
1186
|
+
name: e?.name,
|
|
1187
|
+
message: e?.message,
|
|
1188
|
+
sessionId: session.sessionId
|
|
1189
|
+
});
|
|
1190
|
+
});
|
|
1191
|
+
publisher.on("streamCreated", () => {
|
|
1192
|
+
params.events?.onPublisherCreated?.({
|
|
1193
|
+
sessionId: session.sessionId,
|
|
1194
|
+
streamId: publisher.stream?.streamId
|
|
1195
|
+
});
|
|
1196
|
+
});
|
|
1197
|
+
await session.connect(params.sessionToken);
|
|
1198
|
+
params.events?.onSessionConnected?.(session.sessionId);
|
|
1199
|
+
try {
|
|
1200
|
+
await session.publish(publisher);
|
|
1201
|
+
} catch (error) {
|
|
1202
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1203
|
+
params.events?.onPublisherError?.({
|
|
1204
|
+
message,
|
|
1205
|
+
sessionId: session.sessionId,
|
|
1206
|
+
streamId: publisher.stream?.streamId
|
|
1207
|
+
});
|
|
1208
|
+
throw error;
|
|
1209
|
+
}
|
|
1210
|
+
return {
|
|
1211
|
+
sessionId: session.sessionId,
|
|
1212
|
+
publisher: {
|
|
1213
|
+
getStreamId: () => publisher.stream?.streamId,
|
|
1214
|
+
replaceVideoTrack: async (track) => {
|
|
1215
|
+
await publisher.replaceTrack(track);
|
|
1216
|
+
},
|
|
1217
|
+
destroy: () => {}
|
|
1218
|
+
},
|
|
1219
|
+
disconnect: async () => {
|
|
1220
|
+
try {
|
|
1221
|
+
session.disconnect();
|
|
1222
|
+
params.stream.getTracks().forEach((t) => {
|
|
1223
|
+
t.stop();
|
|
1224
|
+
});
|
|
1225
|
+
} finally {
|
|
1226
|
+
params.events?.onSessionDisconnected?.(session.sessionId);
|
|
1227
|
+
if (container.element.parentNode) container.element.parentNode.removeChild(container.element);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
};
|
|
1233
|
+
|
|
1234
|
+
//#endregion
|
|
1235
|
+
//#region ../infra/src/providers/browser/VisibilityProvider.ts
|
|
1236
|
+
var VisibilityProvider = class {
|
|
1237
|
+
constructor() {
|
|
1238
|
+
this._wasBackgrounded = false;
|
|
1239
|
+
this.visibilityChangeHandler = this.onVisibilityChange.bind(this);
|
|
1240
|
+
document.addEventListener("visibilitychange", this.visibilityChangeHandler);
|
|
1241
|
+
}
|
|
1242
|
+
get wasBackgrounded() {
|
|
1243
|
+
return this._wasBackgrounded;
|
|
1244
|
+
}
|
|
1245
|
+
reset() {
|
|
1246
|
+
this._wasBackgrounded = false;
|
|
1247
|
+
}
|
|
1248
|
+
cleanup() {
|
|
1249
|
+
document.removeEventListener("visibilitychange", this.visibilityChangeHandler);
|
|
1250
|
+
}
|
|
1251
|
+
onVisibilityChange() {
|
|
1252
|
+
if (document.hidden) this._wasBackgrounded = true;
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
|
|
1256
|
+
//#endregion
|
|
1257
|
+
//#region ../infra/src/wasm/IdCaptureModelType.ts
|
|
1258
|
+
let IdCaptureModelType = /* @__PURE__ */ function(IdCaptureModelType$1) {
|
|
1259
|
+
IdCaptureModelType$1[IdCaptureModelType$1["IdCaptureV1x"] = 0] = "IdCaptureV1x";
|
|
1260
|
+
IdCaptureModelType$1[IdCaptureModelType$1["IdCaptureV2x"] = 1] = "IdCaptureV2x";
|
|
1261
|
+
IdCaptureModelType$1[IdCaptureModelType$1["IdCaptureV3x"] = 2] = "IdCaptureV3x";
|
|
1262
|
+
return IdCaptureModelType$1;
|
|
1263
|
+
}({});
|
|
1264
|
+
|
|
1265
|
+
//#endregion
|
|
1266
|
+
//#region ../infra/src/wasm/Mutex.ts
|
|
1267
|
+
var Semaphore = class {
|
|
1268
|
+
constructor(maxConcurrent = 1) {
|
|
1269
|
+
this.maxConcurrent = maxConcurrent;
|
|
1270
|
+
this.current = 0;
|
|
1271
|
+
this.queue = [];
|
|
1272
|
+
}
|
|
1273
|
+
async acquire() {
|
|
1274
|
+
if (this.current < this.maxConcurrent) {
|
|
1275
|
+
this.current++;
|
|
1276
|
+
return Promise.resolve();
|
|
1277
|
+
}
|
|
1278
|
+
return new Promise((resolve) => {
|
|
1279
|
+
this.queue.push(resolve);
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
release() {
|
|
1283
|
+
this.current = Math.max(0, this.current - 1);
|
|
1284
|
+
if (this.queue.length > 0 && this.current < this.maxConcurrent) {
|
|
1285
|
+
this.current++;
|
|
1286
|
+
const next = this.queue.shift();
|
|
1287
|
+
if (next) next();
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
};
|
|
1291
|
+
var Mutex = class {
|
|
1292
|
+
constructor() {
|
|
1293
|
+
this.semaphore = new Semaphore(1);
|
|
1294
|
+
}
|
|
1295
|
+
async lock() {
|
|
1296
|
+
return this.semaphore.acquire();
|
|
1297
|
+
}
|
|
1298
|
+
unlock() {
|
|
1299
|
+
this.semaphore.release();
|
|
1300
|
+
}
|
|
1301
|
+
async withLock(fn, ...args) {
|
|
1302
|
+
await this.lock();
|
|
1303
|
+
try {
|
|
1304
|
+
return await fn(...args);
|
|
1305
|
+
} finally {
|
|
1306
|
+
this.unlock();
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
};
|
|
1310
|
+
|
|
1311
|
+
//#endregion
|
|
1312
|
+
//#region ../infra/src/wasm/WasmPipelineType.ts
|
|
1313
|
+
let WasmPipelineType = /* @__PURE__ */ function(WasmPipelineType$1) {
|
|
1314
|
+
WasmPipelineType$1[WasmPipelineType$1["IdBlurGlarePipeline"] = 0] = "IdBlurGlarePipeline";
|
|
1315
|
+
WasmPipelineType$1[WasmPipelineType$1["IdBarcodeAndTextQualityPipeline"] = 1] = "IdBarcodeAndTextQualityPipeline";
|
|
1316
|
+
WasmPipelineType$1[WasmPipelineType$1["IdVideoSelfiePipeline"] = 2] = "IdVideoSelfiePipeline";
|
|
1317
|
+
WasmPipelineType$1[WasmPipelineType$1["SelfieWithAggregationMetrics"] = 3] = "SelfieWithAggregationMetrics";
|
|
1318
|
+
WasmPipelineType$1[WasmPipelineType$1["SelfieWithQualityMetrics"] = 4] = "SelfieWithQualityMetrics";
|
|
1319
|
+
WasmPipelineType$1[WasmPipelineType$1["IdFaceDetectionPipeline"] = 5] = "IdFaceDetectionPipeline";
|
|
1320
|
+
return WasmPipelineType$1;
|
|
1321
|
+
}({});
|
|
1322
|
+
|
|
1323
|
+
//#endregion
|
|
1324
|
+
//#region ../infra/src/wasm/mlWasmJSApi.ts
|
|
1325
|
+
window.wasmArrayBuffer = null;
|
|
1326
|
+
var MlWasmJSApi = class MlWasmJSApi {
|
|
1327
|
+
constructor() {
|
|
1328
|
+
this.versionsFile = null;
|
|
1329
|
+
this.modelsBuffers = null;
|
|
1330
|
+
this.inputImageBuffer = null;
|
|
1331
|
+
this.wasmModule = null;
|
|
1332
|
+
this.pipelineApiUtilities = null;
|
|
1333
|
+
this.utilityApi = null;
|
|
1334
|
+
this.idCaptureWasmApi = null;
|
|
1335
|
+
this.faceDetectionWasmApi = null;
|
|
1336
|
+
this.imageWidth_ = null;
|
|
1337
|
+
this.imageHeight_ = null;
|
|
1338
|
+
this.pipelines_ = null;
|
|
1339
|
+
this.isInitialized_ = false;
|
|
1340
|
+
this.inspectorOpened_ = false;
|
|
1341
|
+
this.wasmCallMutex = new Mutex();
|
|
1342
|
+
this.Module = null;
|
|
1343
|
+
this.loadModule = async (glueCodePath) => {
|
|
1344
|
+
this.Module = (await import(
|
|
1345
|
+
/* @vite-ignore */
|
|
1346
|
+
/* webpackIgnore: true */
|
|
1347
|
+
glueCodePath
|
|
1348
|
+
)).Module;
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Initiallization method, use it when the application starts
|
|
1353
|
+
* TODO: this method can return the list of promises to be awaited together with other initialization code
|
|
1354
|
+
* @param {string} webLibPath - The path to the webassembly binary
|
|
1355
|
+
* @param {string} webLibPathSimd - The path to the SIMD version webassembly binary
|
|
1356
|
+
* @param {boolean} useSimd - Indicates whether SIMD optimizations should be used
|
|
1357
|
+
* @param {string} versionsFile - The path to the file containing versioning information
|
|
1358
|
+
* @param {Map.<WasmPipelineType, Array<string>>} pipelines - pipelines for initialization and corresponding models paths
|
|
1359
|
+
* @returns {Promise<boolean>} A promise that resolves to a boolean indicating whether SIMD is enabled once the initialization is complete.
|
|
1360
|
+
* @throws {Error} Throws an error if the initialization fails.
|
|
1361
|
+
*/
|
|
1362
|
+
async initialize(webLibPath, webLibPathSimd, glueCodePath, useSimd, versionsFile, pipelines) {
|
|
1363
|
+
await this.freeResources();
|
|
1364
|
+
this.pipelines_ = pipelines;
|
|
1365
|
+
this.versionsFile = versionsFile;
|
|
1366
|
+
await this.loadModule(glueCodePath);
|
|
1367
|
+
const simdIsEnabled = await this.loadWasm(useSimd, webLibPath, webLibPathSimd);
|
|
1368
|
+
this.pipelineApiUtilities = new this.wasmModule.PipelineApiUtilities();
|
|
1369
|
+
this.utilityApi = new this.wasmModule.UtilityApi();
|
|
1370
|
+
this.idCaptureWasmApi = new this.wasmModule.IdCaptureApi();
|
|
1371
|
+
this.faceDetectionWasmApi = new this.wasmModule.FaceDetectionApi();
|
|
1372
|
+
this.isInitialized_ = true;
|
|
1373
|
+
return simdIsEnabled;
|
|
1374
|
+
}
|
|
1375
|
+
static getInstance() {
|
|
1376
|
+
if (!MlWasmJSApi.instance) MlWasmJSApi.instance = new MlWasmJSApi();
|
|
1377
|
+
return MlWasmJSApi.instance;
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Returns initialization status
|
|
1381
|
+
* @returns
|
|
1382
|
+
*/
|
|
1383
|
+
isInitialized() {
|
|
1384
|
+
return this.pipelineApiUtilities != null && this.utilityApi != null && this.idCaptureWasmApi != null && this.faceDetectionWasmApi != null && this.isInitialized_;
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Allocate shared memory for image buffers (RGBA format)
|
|
1388
|
+
* Use it every time when the frame dimentions changes
|
|
1389
|
+
* @param {number} imageWidth - image width
|
|
1390
|
+
* @param {number} imageHeight - image height
|
|
1391
|
+
*/
|
|
1392
|
+
async allocateImageBuffers(imageWidth, imageHeight) {
|
|
1393
|
+
this.checkWasmInitialization("Unable to allocate image buffers, cpp API hasn't been initialized");
|
|
1394
|
+
if (imageWidth && imageHeight && imageWidth == this.imageWidth_ && imageHeight == this.imageHeight_ && this.inputImageBuffer && imageWidth * imageHeight * 4 === this.inputImageBuffer.length) return;
|
|
1395
|
+
this.imageWidth_ = imageWidth;
|
|
1396
|
+
this.imageHeight_ = imageHeight;
|
|
1397
|
+
this.inputImageBuffer = this.pipelineApiUtilities.allocateInputImageBuffer(imageWidth, imageHeight, 4);
|
|
1398
|
+
}
|
|
1399
|
+
async handleDetectionCallAndUpdateState(type) {
|
|
1400
|
+
this.checkWasmInitialization("Unable to update pipeline state, cpp API hasn't been initialized");
|
|
1401
|
+
this.pipelineApiUtilities.handleDetectionCallAndUpdateState(this.pipelineTypeToWasmEnum(type));
|
|
1402
|
+
}
|
|
1403
|
+
ens(image) {
|
|
1404
|
+
this.checkWasmInitialization("Unable to encrypt the image, cpp API hasn't been initialized");
|
|
1405
|
+
return this.utilityApi.ens(image);
|
|
1406
|
+
}
|
|
1407
|
+
isVirtualCamera(label) {
|
|
1408
|
+
this.checkWasmInitialization("Unable to check if the camera is virtual, cpp API hasn't been initialized");
|
|
1409
|
+
if (label) return this.utilityApi.isVirtualCamera(label);
|
|
1410
|
+
return false;
|
|
1411
|
+
}
|
|
1412
|
+
estimatePerformance() {
|
|
1413
|
+
this.checkWasmInitialization("Unable to estimate performance, cpp API hasn't been initialized");
|
|
1414
|
+
return this.utilityApi.estimatePerformance();
|
|
1415
|
+
}
|
|
1416
|
+
async analyzeFrame(image) {
|
|
1417
|
+
this.checkWasmInitialization("Unable to analyze the frame, cpp API hasn't been initialized");
|
|
1418
|
+
await this.allocateImageBuffers(image.width, image.height);
|
|
1419
|
+
this.inputImageBuffer.set(image.data);
|
|
1420
|
+
this.utilityApi.analyzeFrame();
|
|
1421
|
+
}
|
|
1422
|
+
/**
|
|
1423
|
+
* Free allocated memory
|
|
1424
|
+
*/
|
|
1425
|
+
async freeResources() {
|
|
1426
|
+
this.versionsFile = null;
|
|
1427
|
+
this.modelsBuffers = null;
|
|
1428
|
+
this.inputImageBuffer = null;
|
|
1429
|
+
this.imageWidth_ = null;
|
|
1430
|
+
this.imageHeight_ = null;
|
|
1431
|
+
this.pipelines_ = null;
|
|
1432
|
+
window.wasmArrayBuffer = null;
|
|
1433
|
+
if (this.pipelineApiUtilities && typeof this.pipelineApiUtilities.delete === "function") {
|
|
1434
|
+
this.pipelineApiUtilities.delete();
|
|
1435
|
+
this.pipelineApiUtilities = null;
|
|
1436
|
+
}
|
|
1437
|
+
if (this.utilityApi && typeof this.utilityApi.delete === "function") {
|
|
1438
|
+
this.utilityApi.delete();
|
|
1439
|
+
this.utilityApi = null;
|
|
1440
|
+
}
|
|
1441
|
+
if (this.idCaptureWasmApi && typeof this.idCaptureWasmApi.delete === "function") {
|
|
1442
|
+
this.idCaptureWasmApi.delete();
|
|
1443
|
+
this.idCaptureWasmApi = null;
|
|
1444
|
+
}
|
|
1445
|
+
if (this.faceDetectionWasmApi && typeof this.faceDetectionWasmApi.delete === "function") {
|
|
1446
|
+
this.faceDetectionWasmApi.delete();
|
|
1447
|
+
this.faceDetectionWasmApi = null;
|
|
1448
|
+
}
|
|
1449
|
+
this.wasmModule = null;
|
|
1450
|
+
this.isInitialized_ = false;
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* Clear pipeline state
|
|
1454
|
+
*/
|
|
1455
|
+
resetPipeline(type) {
|
|
1456
|
+
this.checkWasmInitialization("Unable to reset pipeline, cpp API hasn't been initialized");
|
|
1457
|
+
this.pipelineApiUtilities.resetPipeline(this.pipelineTypeToWasmEnum(type));
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* Clear all pipelines states
|
|
1461
|
+
*/
|
|
1462
|
+
resetAllPipelines() {
|
|
1463
|
+
this.checkWasmInitialization("Unable to reset pipelines, cpp API hasn't been initialized");
|
|
1464
|
+
for (const [type, model] of this.pipelines_) this.resetPipeline(type);
|
|
1465
|
+
}
|
|
1466
|
+
/**
|
|
1467
|
+
* Clear all states, not related to ml pipelines
|
|
1468
|
+
*/
|
|
1469
|
+
resetOther() {
|
|
1470
|
+
this.checkWasmInitialization("Unable to reset other states, cpp API hasn't been initialized");
|
|
1471
|
+
this.utilityApi.resetOther();
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Full reset
|
|
1475
|
+
*/
|
|
1476
|
+
reset() {
|
|
1477
|
+
this.resetAllPipelines();
|
|
1478
|
+
this.resetOther();
|
|
1479
|
+
}
|
|
1480
|
+
/**
|
|
1481
|
+
* Process one frame using one of the pipelines
|
|
1482
|
+
* @param {ImageData} image - input image
|
|
1483
|
+
* @param {WasmPipelineType} type - pipeline type
|
|
1484
|
+
* @returns
|
|
1485
|
+
*/
|
|
1486
|
+
async process(image, type) {
|
|
1487
|
+
this.checkWasmInitialization("Unable to process the image, cpp API hasn't been initialized");
|
|
1488
|
+
if (this.inputImageBuffer === null) throw new Error("Unable to process the image, buffers haven't been allocated!");
|
|
1489
|
+
this.inputImageBuffer.set(image.data);
|
|
1490
|
+
switch (type) {
|
|
1491
|
+
case WasmPipelineType.IdBlurGlarePipeline:
|
|
1492
|
+
case WasmPipelineType.IdBarcodeAndTextQualityPipeline: return this.idCaptureWasmApi.runIdCapturePipeline(this.pipelineTypeToWasmEnum(type));
|
|
1493
|
+
case WasmPipelineType.IdFaceDetectionPipeline: return this.faceDetectionWasmApi.runIdFaceDetectionPipeline();
|
|
1494
|
+
case WasmPipelineType.IdVideoSelfiePipeline: return this.idCaptureWasmApi.runIdVideoSelfiePipeline();
|
|
1495
|
+
case WasmPipelineType.SelfieWithAggregationMetrics:
|
|
1496
|
+
case WasmPipelineType.SelfieWithQualityMetrics: return this.faceDetectionWasmApi.runSelfieFaceDetectionPipeline(this.pipelineTypeToWasmEnum(type));
|
|
1497
|
+
default: throw new Error("Unknown pipeline type");
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
async runIdCapture(image) {
|
|
1501
|
+
this.checkWasmInitialization("Unable to run Id Capture, cpp API hasn't been initialized");
|
|
1502
|
+
if (this.inputImageBuffer === null) throw new Error("Unable to process the image, buffers haven't been allocated!");
|
|
1503
|
+
this.inputImageBuffer.set(image.data);
|
|
1504
|
+
return this.idCaptureWasmApi.runIdCapture();
|
|
1505
|
+
}
|
|
1506
|
+
async runSelfieCapture(image) {
|
|
1507
|
+
this.checkWasmInitialization("Unable to run Selfie Capture, cpp API hasn't been initialized");
|
|
1508
|
+
if (this.inputImageBuffer === null) throw new Error("Unable to process the image, buffers haven't been allocated!");
|
|
1509
|
+
this.inputImageBuffer.set(image.data);
|
|
1510
|
+
return this.faceDetectionWasmApi.runSelfieCapture();
|
|
1511
|
+
}
|
|
1512
|
+
async setFacePositionConstraints(type, minX, minY, maxX, maxY) {
|
|
1513
|
+
this.checkWasmInitialization("Unable to set face position constraints, cpp API hasn't been initialized");
|
|
1514
|
+
this.faceDetectionWasmApi.setFacePositionConstraints(this.pipelineTypeToWasmEnum(type), minX, minY, maxX, maxY);
|
|
1515
|
+
}
|
|
1516
|
+
async setFaceDetectionThresholds(type, brightnessThreshold, blurrinessThreshold, tiltRotationAngleThreshold, minMagicCropSize, autocaptureInterval, minFaceQualityScore, faceOcclusionThreshold) {
|
|
1517
|
+
this.checkWasmInitialization("Unable to set face detection thresholds, cpp API hasn't been initialized");
|
|
1518
|
+
this.faceDetectionWasmApi.setFaceDetectionThresholds(this.pipelineTypeToWasmEnum(type), brightnessThreshold, blurrinessThreshold, tiltRotationAngleThreshold, minMagicCropSize, autocaptureInterval, minFaceQualityScore, faceOcclusionThreshold);
|
|
1519
|
+
}
|
|
1520
|
+
async setFaceAttributesThresholds(type, headwearThreshold, lensesThreshold, closedEyesThreshold, maskThreshold) {
|
|
1521
|
+
this.checkWasmInitialization("Unable to set face attributes thresholds, cpp API hasn't been initialized");
|
|
1522
|
+
this.faceDetectionWasmApi.setFaceAttributesThresholds(this.pipelineTypeToWasmEnum(type), headwearThreshold, lensesThreshold, closedEyesThreshold, maskThreshold);
|
|
1523
|
+
}
|
|
1524
|
+
async setFaceChecksEnabled(type, isLensesCheckEnabled, isMaskCheckEnabled, isClosedEyesCheckEnabled, isHeadWearCheckEnabled, isOcclusionCheckEnabled) {
|
|
1525
|
+
this.checkWasmInitialization("Unable to set face checks enabled flags, cpp API hasn't been initialized");
|
|
1526
|
+
this.faceDetectionWasmApi.setFaceChecksEnabled(this.pipelineTypeToWasmEnum(type), isLensesCheckEnabled, isMaskCheckEnabled, isClosedEyesCheckEnabled, isHeadWearCheckEnabled, isOcclusionCheckEnabled);
|
|
1527
|
+
}
|
|
1528
|
+
async setFaceDetectionMode(type, isVideoSelfie) {
|
|
1529
|
+
this.checkWasmInitialization("Unable to set face detection mode, cpp API hasn't been initialized");
|
|
1530
|
+
this.faceDetectionWasmApi.setFaceDetectionMode(this.pipelineTypeToWasmEnum(type), isVideoSelfie);
|
|
1531
|
+
}
|
|
1532
|
+
async setFaceDetectionCallbacks(type, onFarAway, onTooClose, onTooManyFaces, onNoFace, onCapture, onGetReady, onGetReadyFinished, onCenterFace, onDark, onBlur, onFaceAngle, onBestShot, onLenses, onMask, onEyesClosed, onHeadWear, onSwitchToManualCapture, onFaceOccluded) {
|
|
1533
|
+
this.checkWasmInitialization("Unable to set face detection callbacks, cpp API hasn't been initialized");
|
|
1534
|
+
this.faceDetectionWasmApi.setFaceDetectionCallbacks(this.pipelineTypeToWasmEnum(type), onFarAway, onTooClose, onTooManyFaces, onNoFace, onCapture, onGetReady, onGetReadyFinished, onCenterFace, onDark, onBlur, onFaceAngle, onBestShot, onLenses, onMask, onEyesClosed, onHeadWear, onSwitchToManualCapture, onFaceOccluded);
|
|
1535
|
+
}
|
|
1536
|
+
async setIdCaptureThresholds(type, blurThreshold, blurChangeThreshold, glareThreshold, clsThreshold, sideThreshold, iouThreshold, idDetectedTimeout, autocaptureTimeout, framesAggregationInterval, minFaceIdQualityScore) {
|
|
1537
|
+
this.checkWasmInitialization("Unable to set thresholds, cpp API hasn't been initialized");
|
|
1538
|
+
this.idCaptureWasmApi.setIdCaptureThresholds(this.pipelineTypeToWasmEnum(type), blurThreshold, blurChangeThreshold, glareThreshold, clsThreshold, sideThreshold, iouThreshold, idDetectedTimeout, autocaptureTimeout, framesAggregationInterval, minFaceIdQualityScore);
|
|
1539
|
+
}
|
|
1540
|
+
async setIdCaptureCallbacks(type, onFarAway, onDetectionStarted, onMaskChange, onBlur, onGlare, onCapturing, onCapture, onBestFrame, onIDNotDetected, onSwitchToManualCapture, onIDTypeChange, onIDSideChange, onCapturingCounterValueChange) {
|
|
1541
|
+
this.checkWasmInitialization("Unable to set callbacks, cpp API hasn't been initialized");
|
|
1542
|
+
this.idCaptureWasmApi.setIdCaptureCallbacks(this.pipelineTypeToWasmEnum(type), onFarAway, onDetectionStarted, onMaskChange, onBlur, onGlare, onCapturing, onCapture, onBestFrame, onIDNotDetected, onSwitchToManualCapture, onIDTypeChange, onIDSideChange, onCapturingCounterValueChange);
|
|
1543
|
+
}
|
|
1544
|
+
async setIdCaptureGeometryParams(type, areaDown, areaUp, areaIOSPassportUp, areaIOSPassportDown, widthIOSUp, widthIOSDown, widthDown, widthUp, windowOuterWidth, windowOuterHeight, windowInnerWidth, windowInnerHeight) {
|
|
1545
|
+
this.checkWasmInitialization("Unable to set geometry params, cpp API hasn't been initialized");
|
|
1546
|
+
this.idCaptureWasmApi.setIdCaptureGeometryParams(this.pipelineTypeToWasmEnum(type), areaDown, areaUp, areaIOSPassportUp, areaIOSPassportDown, widthIOSUp, widthIOSDown, widthDown, widthUp, windowOuterWidth, windowOuterHeight, windowInnerWidth, windowInnerHeight);
|
|
1547
|
+
}
|
|
1548
|
+
async setIdCaptureConfigParams(type, isFixedMask, isIPhone14OrHigher, idType, isBlurCheckEnabled, isGlareCheckEnabled, isIdFaceQualityCheckEnabled, isIouCheckEnabled) {
|
|
1549
|
+
this.checkWasmInitialization("Unable to set config params, cpp API hasn't been initialized");
|
|
1550
|
+
this.idCaptureWasmApi.setIdCaptureConfigParams(this.pipelineTypeToWasmEnum(type), isFixedMask, isIPhone14OrHigher, idType, isBlurCheckEnabled, isGlareCheckEnabled, isIdFaceQualityCheckEnabled, isIouCheckEnabled);
|
|
1551
|
+
}
|
|
1552
|
+
setIdCaptureModelType(pipelineType, modelType) {
|
|
1553
|
+
this.checkWasmInitialization("Unable to set model type, cpp API hasn't been initialized");
|
|
1554
|
+
this.idCaptureWasmApi.setIdCaptureModelType(this.pipelineTypeToWasmEnum(pipelineType), this.IdCaptureModelTypeToWasmEnum(modelType));
|
|
1555
|
+
}
|
|
1556
|
+
IdPerspectiveTransform(image, frameRect) {
|
|
1557
|
+
this.checkWasmInitialization("Unable to perform perspective transform, cpp API hasn't been initialized");
|
|
1558
|
+
return this.idCaptureWasmApi.IdPerspectiveTransform(image, frameRect);
|
|
1559
|
+
}
|
|
1560
|
+
async getVersions() {
|
|
1561
|
+
const text = await (await fetch(this.versionsFile)).text();
|
|
1562
|
+
return JSON.parse(text);
|
|
1563
|
+
}
|
|
1564
|
+
async loadWasm(useSimd, webLibPath, webLibPathSimd) {
|
|
1565
|
+
const libPath = useSimd ? webLibPathSimd : webLibPath;
|
|
1566
|
+
try {
|
|
1567
|
+
window.wasmArrayBuffer = await fetch(libPath).then((response) => response.arrayBuffer()).then((buffer) => new Uint8Array(buffer));
|
|
1568
|
+
this.wasmModule = await this.Module();
|
|
1569
|
+
} catch (e) {
|
|
1570
|
+
console.log(e, useSimd, "useSmd");
|
|
1571
|
+
if (useSimd) return await this.loadWasm(false, webLibPath, webLibPathSimd);
|
|
1572
|
+
else throw e;
|
|
1573
|
+
}
|
|
1574
|
+
return useSimd;
|
|
1575
|
+
}
|
|
1576
|
+
async loadModels() {
|
|
1577
|
+
this.checkWasmInitialization("Unable load the models, cpp API hasn't been initialized");
|
|
1578
|
+
const buffSizes = new this.wasmModule.PipelineTypeToIntMap();
|
|
1579
|
+
const modelData = /* @__PURE__ */ new Map();
|
|
1580
|
+
const loadedModels = /* @__PURE__ */ new Map();
|
|
1581
|
+
for (const [type, modelsPaths] of this.pipelines_) {
|
|
1582
|
+
const wasmType = this.pipelineTypeToWasmEnum(type);
|
|
1583
|
+
const pipelineBuffers = [];
|
|
1584
|
+
const sizes = new this.wasmModule.VectorInt();
|
|
1585
|
+
for (const path of modelsPaths) {
|
|
1586
|
+
if (!loadedModels.has(path)) {
|
|
1587
|
+
const model$1 = await fetch(path).then((response) => response.arrayBuffer()).then((buffer) => new Uint8Array(buffer));
|
|
1588
|
+
loadedModels.set(path, model$1);
|
|
1589
|
+
}
|
|
1590
|
+
const model = loadedModels.get(path);
|
|
1591
|
+
sizes.push_back(model.byteLength);
|
|
1592
|
+
pipelineBuffers.push(model);
|
|
1593
|
+
}
|
|
1594
|
+
buffSizes.set(wasmType, sizes);
|
|
1595
|
+
modelData.set(wasmType, pipelineBuffers);
|
|
1596
|
+
}
|
|
1597
|
+
this.modelsBuffers = this.pipelineApiUtilities.allocateModelsBuffers(buffSizes);
|
|
1598
|
+
for (const [type, data] of modelData) {
|
|
1599
|
+
const buffers = this.modelsBuffers?.get(type);
|
|
1600
|
+
for (let k = 0; k < buffers.size(); k++) {
|
|
1601
|
+
const buffer = buffers?.get(k);
|
|
1602
|
+
if (buffer) buffer.set(data[k]);
|
|
1603
|
+
else throw new Error("Unable to get model buffer from shared memory!");
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
async initializePipelines() {
|
|
1608
|
+
this.checkWasmInitialization("Unable to initialize pipelines, cpp API hasn't been initialized");
|
|
1609
|
+
if (!this.modelsBuffers) await this.loadModels();
|
|
1610
|
+
this.pipelineApiUtilities.initializePipelines();
|
|
1611
|
+
}
|
|
1612
|
+
async setProductionMode(productionMode) {
|
|
1613
|
+
this.checkWasmInitialization("Unable to set production mode, cpp API hasn't been initialized");
|
|
1614
|
+
this.utilityApi.setProductionMode(productionMode);
|
|
1615
|
+
}
|
|
1616
|
+
getPipelineState() {
|
|
1617
|
+
this.checkWasmInitialization("Unable to get pipeline state, cpp API hasn't been initialized");
|
|
1618
|
+
return this.pipelineApiUtilities.getPipelineState();
|
|
1619
|
+
}
|
|
1620
|
+
getCurrentPipeline() {
|
|
1621
|
+
this.checkWasmInitialization("Unable to get current pipeline, cpp API hasn't been initialized");
|
|
1622
|
+
return this.pipelineTypeFromWasmEnum(this.pipelineApiUtilities.getCurrentPipeline());
|
|
1623
|
+
}
|
|
1624
|
+
setSdkVersion(sdkVersion) {
|
|
1625
|
+
this.checkWasmInitialization("Unable to set sdk version, cpp API hasn't been initialized");
|
|
1626
|
+
this.utilityApi.setSdkVersion(sdkVersion);
|
|
1627
|
+
}
|
|
1628
|
+
setSdkPlatform(sdkPlatform) {
|
|
1629
|
+
this.checkWasmInitialization("Unable to set device type, cpp API hasn't been initialized");
|
|
1630
|
+
this.utilityApi.setSdkPlatform(sdkPlatform);
|
|
1631
|
+
}
|
|
1632
|
+
setDeviceInfo(deviceInfo, overrideExisting = true) {
|
|
1633
|
+
this.checkWasmInitialization("Unable to set device info, cpp API hasn't been initialized");
|
|
1634
|
+
this.utilityApi.setDeviceInfo(deviceInfo, overrideExisting);
|
|
1635
|
+
}
|
|
1636
|
+
setBrowserInfo(browserInfo, overrideExisting = true) {
|
|
1637
|
+
this.checkWasmInitialization("Unable to set browser info, cpp API hasn't been initialized");
|
|
1638
|
+
this.utilityApi.setBrowserInfo(browserInfo, overrideExisting);
|
|
1639
|
+
}
|
|
1640
|
+
setCameraInfo(cameraInfo, overrideExisting = true) {
|
|
1641
|
+
this.checkWasmInitialization("Unable to set camera info, cpp API hasn't been initialized");
|
|
1642
|
+
this.utilityApi.setCameraInfo(cameraInfo, overrideExisting);
|
|
1643
|
+
}
|
|
1644
|
+
setZc(zc) {
|
|
1645
|
+
this.checkWasmInitialization("Unable to set zc, cpp API hasn't been initialized");
|
|
1646
|
+
this.utilityApi.setZc(zc);
|
|
1647
|
+
}
|
|
1648
|
+
setMotionStatus(motionStatus) {
|
|
1649
|
+
this.checkWasmInitialization("Unable to set motion status, cpp API hasn't been initialized");
|
|
1650
|
+
this.utilityApi.setMotionStatus(motionStatus);
|
|
1651
|
+
}
|
|
1652
|
+
setMetadataField(key, value) {
|
|
1653
|
+
this.checkWasmInitialization("Unable to set metadata field, cpp API hasn't been initialized");
|
|
1654
|
+
this.utilityApi.setMetadataField(key, value);
|
|
1655
|
+
}
|
|
1656
|
+
setInspectorOpened(inspectorOpened) {
|
|
1657
|
+
this.inspectorOpened_ = inspectorOpened;
|
|
1658
|
+
}
|
|
1659
|
+
setBackgroundMode(backgroundMode) {
|
|
1660
|
+
this.checkWasmInitialization("Unable to set background mode, cpp API hasn't been initialized");
|
|
1661
|
+
this.utilityApi.setBackgroundMode(backgroundMode);
|
|
1662
|
+
}
|
|
1663
|
+
getCheck() {
|
|
1664
|
+
this.checkWasmInitialization("Unable to get check, cpp API hasn't been initialized");
|
|
1665
|
+
return this.utilityApi.getCheck();
|
|
1666
|
+
}
|
|
1667
|
+
getMetadata() {
|
|
1668
|
+
this.checkWasmInitialization("Unable to get metadata, cpp API hasn't been initialized");
|
|
1669
|
+
this.utilityApi.setInspectorOpened(this.inspectorOpened_);
|
|
1670
|
+
return this.utilityApi.getMetadata();
|
|
1671
|
+
}
|
|
1672
|
+
async prc() {
|
|
1673
|
+
this.checkWasmInitialization("Unable to prc, cpp API hasn't been initialized");
|
|
1674
|
+
return await this.wasmCallWrapper(this.utilityApi.prc.bind(this.utilityApi), []);
|
|
1675
|
+
}
|
|
1676
|
+
async poc(output) {
|
|
1677
|
+
this.checkWasmInitialization("Unable to poc, cpp API hasn't been initialized");
|
|
1678
|
+
await this.wasmCallWrapper(this.utilityApi.poc.bind(this.utilityApi), [output]);
|
|
1679
|
+
}
|
|
1680
|
+
async pc(deviceId) {
|
|
1681
|
+
this.checkWasmInitialization("Unable to pc, cpp API hasn't been initialized");
|
|
1682
|
+
await this.wasmCallWrapper(this.utilityApi.pc.bind(this.utilityApi), [deviceId]);
|
|
1683
|
+
}
|
|
1684
|
+
ckvcks(data) {
|
|
1685
|
+
this.checkWasmInitialization("Unable to ckvcks, cpp API hasn't been initialized");
|
|
1686
|
+
this.utilityApi.ckvcks(data);
|
|
1687
|
+
}
|
|
1688
|
+
pipelineTypeToWasmEnum(type) {
|
|
1689
|
+
switch (type) {
|
|
1690
|
+
case WasmPipelineType.IdBlurGlarePipeline: return this.wasmModule.PipelineType.IdBlurGlarePipeline;
|
|
1691
|
+
case WasmPipelineType.IdBarcodeAndTextQualityPipeline: return this.wasmModule.PipelineType.IdBarcodeAndTextQualityPipeline;
|
|
1692
|
+
case WasmPipelineType.IdFaceDetectionPipeline: return this.wasmModule.PipelineType.IdFaceDetectionPipeline;
|
|
1693
|
+
case WasmPipelineType.IdVideoSelfiePipeline: return this.wasmModule.PipelineType.IdVideoSelfiePipeline;
|
|
1694
|
+
case WasmPipelineType.SelfieWithAggregationMetrics: return this.wasmModule.PipelineType.SelfieWithAggregationMetrics;
|
|
1695
|
+
case WasmPipelineType.SelfieWithQualityMetrics: return this.wasmModule.PipelineType.SelfieWithQualityMetrics;
|
|
1696
|
+
default: throw new Error("Unknown pipeline type");
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
pipelineTypeFromWasmEnum(type) {
|
|
1700
|
+
switch (type) {
|
|
1701
|
+
case this.wasmModule.PipelineType.IdBlurGlarePipeline: return WasmPipelineType.IdBlurGlarePipeline;
|
|
1702
|
+
case this.wasmModule.IdBarcodeAndTextQualityPipeline: return WasmPipelineType.IdBarcodeAndTextQualityPipeline;
|
|
1703
|
+
case this.wasmModule.PipelineType.IdFaceDetectionPipeline: return WasmPipelineType.IdFaceDetectionPipeline;
|
|
1704
|
+
case this.wasmModule.PipelineType.IdVideoSelfiePipeline: return WasmPipelineType.IdVideoSelfiePipeline;
|
|
1705
|
+
case this.wasmModule.PipelineType.SelfieWithAggregationMetrics: return WasmPipelineType.SelfieWithAggregationMetrics;
|
|
1706
|
+
case this.wasmModule.PipelineType.SelfieWithQualityMetrics: return WasmPipelineType.SelfieWithQualityMetrics;
|
|
1707
|
+
default: throw new Error("Unknown pipeline type");
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
IdCaptureModelTypeToWasmEnum(type) {
|
|
1711
|
+
switch (type) {
|
|
1712
|
+
case IdCaptureModelType.IdCaptureV1x: return this.wasmModule.IdCaptureModelType.IdCaptureV1x;
|
|
1713
|
+
case IdCaptureModelType.IdCaptureV2x: return this.wasmModule.IdCaptureModelType.IdCaptureV2x;
|
|
1714
|
+
case IdCaptureModelType.IdCaptureV3x: return this.wasmModule.IdCaptureModelType.IdCaptureV3x;
|
|
1715
|
+
default: throw new Error("Unknown Id Capture model type");
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
IdCaptureModelTypeFromWasmEnum(type) {
|
|
1719
|
+
switch (type) {
|
|
1720
|
+
case this.wasmModule.IdCaptureModelType.IdCaptureV1x: return IdCaptureModelType.IdCaptureV1x;
|
|
1721
|
+
case this.wasmModule.IdCaptureModelType.IdCaptureV2x: return IdCaptureModelType.IdCaptureV2x;
|
|
1722
|
+
case this.wasmModule.IdCaptureModelType.IdCaptureV3x: return IdCaptureModelType.IdCaptureV3x;
|
|
1723
|
+
default: throw new Error("Unknown Id Capture model type");
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
checkWasmInitialization(message) {
|
|
1727
|
+
if (!this.isInitialized()) throw new Error(message);
|
|
1728
|
+
}
|
|
1729
|
+
async wasmCallWrapper(wasmMethod, args = []) {
|
|
1730
|
+
return await this.wasmCallMutex.withLock(async (...args$1) => {
|
|
1731
|
+
let isFinished = false;
|
|
1732
|
+
try {
|
|
1733
|
+
while (true) {
|
|
1734
|
+
isFinished = wasmMethod(...args$1);
|
|
1735
|
+
if (isFinished) return;
|
|
1736
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1737
|
+
}
|
|
1738
|
+
} catch (e) {
|
|
1739
|
+
console.log("Error in wasmCallWrapper:", e);
|
|
1740
|
+
}
|
|
1741
|
+
}, ...args);
|
|
1742
|
+
}
|
|
1743
|
+
};
|
|
1744
|
+
var mlWasmJSApi_default = MlWasmJSApi.getInstance();
|
|
1745
|
+
|
|
1746
|
+
//#endregion
|
|
1747
|
+
//#region ../infra/src/wasm/warmup.ts
|
|
1748
|
+
/** Array of all available pipelines */
|
|
1749
|
+
const WASM_PIPELINES = ["selfie", "idCapture"];
|
|
1750
|
+
/**
|
|
1751
|
+
* Default model files for each pipeline.
|
|
1752
|
+
* These are the ONNX model files required by each ML pipeline.
|
|
1753
|
+
*/
|
|
1754
|
+
const DEFAULT_PIPELINE_MODELS = {
|
|
1755
|
+
selfie: [
|
|
1756
|
+
"selfie_bf_angles_192x192_opset9_fp16.ortmodelv2",
|
|
1757
|
+
"face_attributes_v1_3_fp16.ortmodelv2",
|
|
1758
|
+
"mls_regressor_4773007c657b4f05a460321456740d0f_fp16.ortmodelv2",
|
|
1759
|
+
"face_occlusion_v0_1_fp16.ortmodelv2"
|
|
1760
|
+
],
|
|
1761
|
+
idCapture: ["id_capture_2_01_fp16.ortmodelv2", "id_fiqa_19a81a0b9bf6492eb03b4667f6db4c85_fp16.ortmodelv2"]
|
|
1762
|
+
};
|
|
1763
|
+
let state = "idle";
|
|
1764
|
+
let loadingPromise = null;
|
|
1765
|
+
let wasmError = null;
|
|
1766
|
+
let loadedPipelines = [];
|
|
1767
|
+
let lastConfig = null;
|
|
1768
|
+
function mapPipelineToWasmType(pipeline) {
|
|
1769
|
+
switch (pipeline) {
|
|
1770
|
+
case "selfie": return WasmPipelineType.SelfieWithQualityMetrics;
|
|
1771
|
+
case "idCapture": return WasmPipelineType.IdBlurGlarePipeline;
|
|
1772
|
+
default: throw new Error(`Unknown pipeline: ${pipeline}`);
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
/**
|
|
1776
|
+
* Derives the models base path from the WASM path.
|
|
1777
|
+
* Assumes models are in a 'models' subdirectory relative to the WASM binary location.
|
|
1778
|
+
* e.g., '/wasm/v2/binary.wasm' -> '/wasm/v2/models'
|
|
1779
|
+
*/
|
|
1780
|
+
function deriveModelsBasePath(wasmPath) {
|
|
1781
|
+
const lastSlashIndex = wasmPath.lastIndexOf("/");
|
|
1782
|
+
if (lastSlashIndex === -1) return "models";
|
|
1783
|
+
return `${wasmPath.substring(0, lastSlashIndex)}/models`;
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Builds the pipelines map with model paths for WASM initialization.
|
|
1787
|
+
* @param pipelines - Array of pipeline types to initialize
|
|
1788
|
+
* @param modelsBasePath - Base path where model files are located
|
|
1789
|
+
* @param customModels - Optional custom model files per pipeline
|
|
1790
|
+
*/
|
|
1791
|
+
function buildPipelinesMap(pipelines, modelsBasePath, customModels) {
|
|
1792
|
+
const pipelinesMap = /* @__PURE__ */ new Map();
|
|
1793
|
+
for (const pipeline of pipelines) {
|
|
1794
|
+
const wasmType = mapPipelineToWasmType(pipeline);
|
|
1795
|
+
if (!pipelinesMap.has(wasmType)) {
|
|
1796
|
+
const modelPaths = (customModels?.[pipeline] ?? DEFAULT_PIPELINE_MODELS[pipeline]).map((modelFile) => `${modelsBasePath}/${modelFile}`);
|
|
1797
|
+
pipelinesMap.set(wasmType, modelPaths);
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
return pipelinesMap;
|
|
1801
|
+
}
|
|
1802
|
+
/**
|
|
1803
|
+
* Preloads WASM binary and ML models at app startup.
|
|
1804
|
+
* Runs asynchronously - app can continue while WASM loads in background.
|
|
1805
|
+
*
|
|
1806
|
+
* Model files are automatically loaded based on the pipeline type.
|
|
1807
|
+
* By default, models are expected in a 'models' subdirectory relative to the WASM binary.
|
|
1808
|
+
*
|
|
1809
|
+
* @param config - Configuration for WASM warmup
|
|
1810
|
+
* @returns Promise that resolves when WASM is ready
|
|
1811
|
+
*
|
|
1812
|
+
* @example
|
|
1813
|
+
* ```ts
|
|
1814
|
+
* // Basic usage - models loaded from /wasm/v2/models/
|
|
1815
|
+
* warmupWasm({
|
|
1816
|
+
* wasmPath: '/wasm/v2/ml-wasm.wasm',
|
|
1817
|
+
* glueCodePath: '/wasm/v2/ml-wasm.js',
|
|
1818
|
+
* pipelines: ['selfie', 'idCapture'],
|
|
1819
|
+
* });
|
|
1820
|
+
*
|
|
1821
|
+
* // With explicit models path
|
|
1822
|
+
* warmupWasm({
|
|
1823
|
+
* wasmPath: '/wasm/v2/ml-wasm.wasm',
|
|
1824
|
+
* glueCodePath: '/wasm/v2/ml-wasm.js',
|
|
1825
|
+
* modelsBasePath: 'https://cdn.example.com/wasm/v2/models',
|
|
1826
|
+
* pipelines: ['selfie'],
|
|
1827
|
+
* });
|
|
1828
|
+
* ```
|
|
1829
|
+
*/
|
|
1830
|
+
async function warmupWasm(config) {
|
|
1831
|
+
const pipelines = config.pipelines ?? [...WASM_PIPELINES];
|
|
1832
|
+
const modelsBasePath = config.modelsBasePath ?? deriveModelsBasePath(config.wasmPath);
|
|
1833
|
+
if (state === "loading" && loadingPromise) return loadingPromise;
|
|
1834
|
+
if (state === "ready") {
|
|
1835
|
+
if (pipelines.filter((p) => !loadedPipelines.includes(p)).length === 0) return;
|
|
1836
|
+
if (!lastConfig) throw new Error("Cannot add pipelines: original warmup config not available");
|
|
1837
|
+
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.");
|
|
1838
|
+
const combinedPipelines = [...new Set([...loadedPipelines, ...pipelines])];
|
|
1839
|
+
state = "loading";
|
|
1840
|
+
wasmError = null;
|
|
1841
|
+
loadingPromise = (async () => {
|
|
1842
|
+
try {
|
|
1843
|
+
const pipelinesMap = buildPipelinesMap(combinedPipelines, lastConfig.modelsBasePath ?? deriveModelsBasePath(lastConfig.wasmPath), lastConfig.pipelineModels);
|
|
1844
|
+
await mlWasmJSApi_default.initialize(lastConfig.wasmPath, lastConfig.wasmSimdPath ?? lastConfig.wasmPath, lastConfig.glueCodePath, lastConfig.useSimd ?? true, "", pipelinesMap);
|
|
1845
|
+
await mlWasmJSApi_default.loadModels();
|
|
1846
|
+
await mlWasmJSApi_default.initializePipelines();
|
|
1847
|
+
state = "ready";
|
|
1848
|
+
loadedPipelines = combinedPipelines;
|
|
1849
|
+
lastConfig = {
|
|
1850
|
+
...lastConfig,
|
|
1851
|
+
pipelines: combinedPipelines
|
|
1852
|
+
};
|
|
1853
|
+
loadingPromise = null;
|
|
1854
|
+
} catch (error) {
|
|
1855
|
+
state = "error";
|
|
1856
|
+
wasmError = error instanceof Error ? error : new Error(String(error));
|
|
1857
|
+
loadingPromise = null;
|
|
1858
|
+
throw wasmError;
|
|
1859
|
+
}
|
|
1860
|
+
})();
|
|
1861
|
+
return loadingPromise;
|
|
1862
|
+
}
|
|
1863
|
+
state = "loading";
|
|
1864
|
+
wasmError = null;
|
|
1865
|
+
loadingPromise = (async () => {
|
|
1866
|
+
try {
|
|
1867
|
+
const pipelinesMap = buildPipelinesMap(pipelines, modelsBasePath, config.pipelineModels);
|
|
1868
|
+
await mlWasmJSApi_default.initialize(config.wasmPath, config.wasmSimdPath ?? config.wasmPath, config.glueCodePath, config.useSimd ?? true, "", pipelinesMap);
|
|
1869
|
+
await mlWasmJSApi_default.loadModels();
|
|
1870
|
+
await mlWasmJSApi_default.initializePipelines();
|
|
1871
|
+
state = "ready";
|
|
1872
|
+
loadedPipelines = [...pipelines];
|
|
1873
|
+
lastConfig = {
|
|
1874
|
+
...config,
|
|
1875
|
+
pipelines
|
|
1876
|
+
};
|
|
1877
|
+
loadingPromise = null;
|
|
1878
|
+
} catch (error) {
|
|
1879
|
+
state = "error";
|
|
1880
|
+
wasmError = error instanceof Error ? error : new Error(String(error));
|
|
1881
|
+
loadingPromise = null;
|
|
1882
|
+
throw wasmError;
|
|
1883
|
+
}
|
|
1884
|
+
})();
|
|
1885
|
+
return loadingPromise;
|
|
1886
|
+
}
|
|
1887
|
+
/**
|
|
1888
|
+
* Returns the current warmup status.
|
|
1889
|
+
* Useful for showing loading indicators.
|
|
1890
|
+
*
|
|
1891
|
+
* @returns Current warmup status
|
|
1892
|
+
*/
|
|
1893
|
+
function getWasmStatus() {
|
|
1894
|
+
return {
|
|
1895
|
+
isReady: state === "ready",
|
|
1896
|
+
isLoading: state === "loading",
|
|
1897
|
+
error: wasmError ?? void 0,
|
|
1898
|
+
loadedPipelines: [...loadedPipelines]
|
|
1899
|
+
};
|
|
1900
|
+
}
|
|
1901
|
+
/**
|
|
1902
|
+
* Returns true if WASM is fully initialized and ready.
|
|
1903
|
+
*
|
|
1904
|
+
* @returns True if WASM is ready
|
|
1905
|
+
*/
|
|
1906
|
+
function isWasmReady() {
|
|
1907
|
+
return state === "ready";
|
|
1908
|
+
}
|
|
1909
|
+
/**
|
|
1910
|
+
* Returns a promise that resolves when WASM is ready.
|
|
1911
|
+
* - If ready: resolves immediately
|
|
1912
|
+
* - If loading: waits for completion, then resolves
|
|
1913
|
+
* - If not started: rejects with error
|
|
1914
|
+
*
|
|
1915
|
+
* @returns Promise that resolves when WASM is ready
|
|
1916
|
+
* @throws Error if WASM is in error state or was never started
|
|
1917
|
+
*/
|
|
1918
|
+
function waitForWasm() {
|
|
1919
|
+
if (state === "ready") return Promise.resolve();
|
|
1920
|
+
if (state === "loading" && loadingPromise) return loadingPromise;
|
|
1921
|
+
if (state === "error") return Promise.reject(wasmError ?? /* @__PURE__ */ new Error("WASM initialization failed"));
|
|
1922
|
+
return Promise.reject(/* @__PURE__ */ new Error("WASM warmup was not started. Call warmupWasm() first."));
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
//#endregion
|
|
1926
|
+
//#region ../infra/src/providers/wasm/BaseWasmProvider.ts
|
|
1927
|
+
/**
|
|
1928
|
+
* Base provider class that abstracts common WASM functionality.
|
|
1929
|
+
* This serves as a foundation for specific ML capability providers
|
|
1930
|
+
* like FaceDetectionProvider and IdCaptureProvider.
|
|
1931
|
+
*/
|
|
1932
|
+
var BaseWasmProvider = class {
|
|
1933
|
+
/**
|
|
1934
|
+
* Creates a new BaseWasmProvider
|
|
1935
|
+
* @param pipelineType - The WASM pipeline type this provider uses
|
|
1936
|
+
*/
|
|
1937
|
+
constructor(pipelineType) {
|
|
1938
|
+
this._isInitialized = false;
|
|
1939
|
+
this.pipelineType = pipelineType;
|
|
1940
|
+
}
|
|
1941
|
+
/**
|
|
1942
|
+
* Returns whether this provider has been initialized.
|
|
1943
|
+
*/
|
|
1944
|
+
get initialized() {
|
|
1945
|
+
return this._isInitialized;
|
|
1946
|
+
}
|
|
1947
|
+
getPipelineType() {
|
|
1948
|
+
if (this.pipelineType === void 0) throw new Error(`${this.constructor.name} has no pipeline type configured.`);
|
|
1949
|
+
return this.pipelineType;
|
|
1950
|
+
}
|
|
1951
|
+
/**
|
|
1952
|
+
* Initializes the provider by ensuring WASM is loaded
|
|
1953
|
+
* @param config - Provider configuration
|
|
1954
|
+
* @param pipeline - The pipeline type to warm up ('selfie', 'idCapture', etc.)
|
|
1955
|
+
*/
|
|
1956
|
+
async initializeBase(config, pipeline) {
|
|
1957
|
+
if (this._isInitialized) return;
|
|
1958
|
+
if (getWasmStatus().isLoading || isWasmReady()) await waitForWasm();
|
|
1959
|
+
else {
|
|
1960
|
+
if (!config.wasmPath || !config.glueCodePath) throw new Error("WASM path and glue code path are required. Call warmupWasm() first.");
|
|
1961
|
+
await warmupWasm({
|
|
1962
|
+
wasmPath: config.wasmPath,
|
|
1963
|
+
wasmSimdPath: config.wasmSimdPath,
|
|
1964
|
+
glueCodePath: config.glueCodePath,
|
|
1965
|
+
useSimd: config.useSimd,
|
|
1966
|
+
modelsBasePath: config.modelsBasePath,
|
|
1967
|
+
pipelines: [pipeline]
|
|
1968
|
+
});
|
|
1969
|
+
}
|
|
1970
|
+
this._isInitialized = true;
|
|
1971
|
+
}
|
|
1972
|
+
/**
|
|
1973
|
+
* Ensures the provider is initialized before performing operations.
|
|
1974
|
+
* @throws Error if not initialized
|
|
1975
|
+
*/
|
|
1976
|
+
ensureInitialized() {
|
|
1977
|
+
if (!this._isInitialized) throw new Error(`${this.constructor.name} not initialized. Call initialize() first.`);
|
|
1978
|
+
}
|
|
1979
|
+
/**
|
|
1980
|
+
* Processes a frame through the WASM pipeline
|
|
1981
|
+
* @param image - Image data to process
|
|
1982
|
+
*/
|
|
1983
|
+
async processFrame(image) {
|
|
1984
|
+
this.ensureInitialized();
|
|
1985
|
+
const pipelineType = this.getPipelineType();
|
|
1986
|
+
await mlWasmJSApi_default.allocateImageBuffers(image.width, image.height);
|
|
1987
|
+
await mlWasmJSApi_default.process(image, pipelineType);
|
|
1988
|
+
}
|
|
1989
|
+
/**
|
|
1990
|
+
* Resets the pipeline to its initial state.
|
|
1991
|
+
* Safe to call even if not initialized (no-op in that case).
|
|
1992
|
+
*/
|
|
1993
|
+
reset() {
|
|
1994
|
+
if (this._isInitialized && this.pipelineType !== void 0) mlWasmJSApi_default.resetPipeline(this.pipelineType);
|
|
1995
|
+
}
|
|
1996
|
+
/**
|
|
1997
|
+
* Disposes of resources and resets initialization state.
|
|
1998
|
+
* Safe to call even if not initialized.
|
|
1999
|
+
*/
|
|
2000
|
+
async dispose() {
|
|
2001
|
+
this.reset();
|
|
2002
|
+
this._isInitialized = false;
|
|
2003
|
+
}
|
|
2004
|
+
};
|
|
2005
|
+
|
|
2006
|
+
//#endregion
|
|
2007
|
+
//#region ../infra/src/providers/wasm/FaceDetectionProvider.ts
|
|
2008
|
+
var FaceDetectionProvider = class extends BaseWasmProvider {
|
|
2009
|
+
constructor() {
|
|
2010
|
+
super(WasmPipelineType.SelfieWithQualityMetrics);
|
|
2011
|
+
this.defaultThresholds = {
|
|
2012
|
+
frameMinX: 0,
|
|
2013
|
+
frameMinY: 0,
|
|
2014
|
+
frameMaxX: 1,
|
|
2015
|
+
frameMaxY: 1,
|
|
2016
|
+
brightnessThreshold: 50,
|
|
2017
|
+
blurrinessThreshold: 50,
|
|
2018
|
+
tiltRotationAngleThreshold: 15,
|
|
2019
|
+
minMagicCropSize: 200,
|
|
2020
|
+
headwearThreshold: .86,
|
|
2021
|
+
lensesThreshold: .95,
|
|
2022
|
+
closedEyesThreshold: .9,
|
|
2023
|
+
maskThreshold: .85,
|
|
2024
|
+
minFaceQualityScore: .63,
|
|
2025
|
+
faceOcclusionThreshold: .3
|
|
2026
|
+
};
|
|
2027
|
+
this.currentFrame = null;
|
|
2028
|
+
this.bestCanvas = null;
|
|
2029
|
+
this.bestFace = null;
|
|
2030
|
+
}
|
|
2031
|
+
async processFrame(image) {
|
|
2032
|
+
this.currentFrame = image;
|
|
2033
|
+
await super.processFrame(image);
|
|
2034
|
+
}
|
|
2035
|
+
async initialize(config) {
|
|
2036
|
+
await this.initializeBase(config, "selfie");
|
|
2037
|
+
this.applyDefaults(config.autocaptureInterval ?? 0);
|
|
2038
|
+
}
|
|
2039
|
+
setCallbacks(callbacks) {
|
|
2040
|
+
this.ensureInitialized();
|
|
2041
|
+
const onBestShotWrapper = (face) => {
|
|
2042
|
+
this.bestFace = face;
|
|
2043
|
+
if (this.currentFrame) {
|
|
2044
|
+
const frameCanvas = IncodeCanvas.fromImageData(this.currentFrame);
|
|
2045
|
+
this.bestCanvas = frameCanvas.clone() ?? frameCanvas;
|
|
2046
|
+
}
|
|
2047
|
+
callbacks.onBestShot?.(face);
|
|
2048
|
+
};
|
|
2049
|
+
const onCaptureWrapper = () => {
|
|
2050
|
+
let frameCanvas = this.bestCanvas;
|
|
2051
|
+
if (!frameCanvas && this.currentFrame) frameCanvas = IncodeCanvas.fromImageData(this.currentFrame);
|
|
2052
|
+
if (!frameCanvas) return;
|
|
2053
|
+
const faceCoordinates = this.bestFace ? this.formatFaceCoordinates(this.bestFace) : this.createDefaultFaceCoordinates(frameCanvas);
|
|
2054
|
+
try {
|
|
2055
|
+
frameCanvas.updateBase64Image();
|
|
2056
|
+
frameCanvas.updateBlob();
|
|
2057
|
+
} catch {}
|
|
2058
|
+
callbacks.onCapture?.(frameCanvas, faceCoordinates);
|
|
2059
|
+
this.bestCanvas = null;
|
|
2060
|
+
this.bestFace = null;
|
|
2061
|
+
};
|
|
2062
|
+
mlWasmJSApi_default.setFaceDetectionCallbacks(this.getPipelineType(), callbacks.onFarAway ?? (() => {}), callbacks.onTooClose ?? (() => {}), callbacks.onTooManyFaces ?? (() => {}), callbacks.onNoFace ?? (() => {}), onCaptureWrapper, callbacks.onGetReady ?? (() => {}), callbacks.onGetReadyFinished ?? (() => {}), callbacks.onCenterFace ?? (() => {}), callbacks.onDark ?? (() => {}), callbacks.onBlur ?? (() => {}), callbacks.onFaceAngle ?? (() => {}), onBestShotWrapper, callbacks.onLenses ?? (() => {}), callbacks.onMask ?? (() => {}), callbacks.onEyesClosed ?? (() => {}), callbacks.onHeadWear ?? (() => {}), callbacks.onSwitchToManualCapture ?? (() => {}), callbacks.onFaceOccluded ?? (() => {}));
|
|
2063
|
+
}
|
|
2064
|
+
setPositionConstraints(constraints) {
|
|
2065
|
+
this.ensureInitialized();
|
|
2066
|
+
mlWasmJSApi_default.setFacePositionConstraints(this.getPipelineType(), constraints.minX, constraints.minY, constraints.maxX, constraints.maxY);
|
|
2067
|
+
}
|
|
2068
|
+
applyDefaults(autocaptureInterval = 0) {
|
|
2069
|
+
this.ensureInitialized();
|
|
2070
|
+
this.setThresholds({
|
|
2071
|
+
brightnessThreshold: this.defaultThresholds.brightnessThreshold,
|
|
2072
|
+
blurrinessThreshold: this.defaultThresholds.blurrinessThreshold,
|
|
2073
|
+
tiltRotationAngleThreshold: this.defaultThresholds.tiltRotationAngleThreshold,
|
|
2074
|
+
minMagicCropSize: this.defaultThresholds.minMagicCropSize,
|
|
2075
|
+
autocaptureInterval,
|
|
2076
|
+
minFaceQualityScore: this.defaultThresholds.minFaceQualityScore,
|
|
2077
|
+
faceOcclusionThreshold: this.defaultThresholds.faceOcclusionThreshold
|
|
2078
|
+
});
|
|
2079
|
+
this.setPositionConstraints({
|
|
2080
|
+
minX: this.defaultThresholds.frameMinX,
|
|
2081
|
+
minY: this.defaultThresholds.frameMinY,
|
|
2082
|
+
maxX: this.defaultThresholds.frameMaxX,
|
|
2083
|
+
maxY: this.defaultThresholds.frameMaxY
|
|
2084
|
+
});
|
|
2085
|
+
this.setAttributesThresholds({
|
|
2086
|
+
headwearThreshold: this.defaultThresholds.headwearThreshold,
|
|
2087
|
+
lensesThreshold: this.defaultThresholds.lensesThreshold,
|
|
2088
|
+
closedEyesThreshold: this.defaultThresholds.closedEyesThreshold,
|
|
2089
|
+
maskThreshold: this.defaultThresholds.maskThreshold
|
|
2090
|
+
});
|
|
2091
|
+
}
|
|
2092
|
+
setAutocaptureInterval(interval) {
|
|
2093
|
+
this.ensureInitialized();
|
|
2094
|
+
if (!this.currentThresholds) {
|
|
2095
|
+
this.applyDefaults(interval);
|
|
2096
|
+
return;
|
|
2097
|
+
}
|
|
2098
|
+
this.setThresholds({
|
|
2099
|
+
...this.currentThresholds,
|
|
2100
|
+
autocaptureInterval: interval
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
setThresholds(thresholds) {
|
|
2104
|
+
this.ensureInitialized();
|
|
2105
|
+
this.currentThresholds = { ...thresholds };
|
|
2106
|
+
mlWasmJSApi_default.setFaceDetectionThresholds(this.getPipelineType(), thresholds.brightnessThreshold, thresholds.blurrinessThreshold, thresholds.tiltRotationAngleThreshold, thresholds.minMagicCropSize, thresholds.autocaptureInterval, thresholds.minFaceQualityScore, thresholds.faceOcclusionThreshold);
|
|
2107
|
+
}
|
|
2108
|
+
setAttributesThresholds(thresholds) {
|
|
2109
|
+
this.ensureInitialized();
|
|
2110
|
+
mlWasmJSApi_default.setFaceAttributesThresholds(this.getPipelineType(), thresholds.headwearThreshold, thresholds.lensesThreshold, thresholds.closedEyesThreshold, thresholds.maskThreshold);
|
|
2111
|
+
}
|
|
2112
|
+
setChecksEnabled(config) {
|
|
2113
|
+
this.ensureInitialized();
|
|
2114
|
+
mlWasmJSApi_default.setFaceChecksEnabled(this.getPipelineType(), config.lenses, config.mask, config.closedEyes, config.headWear, config.occlusion);
|
|
2115
|
+
}
|
|
2116
|
+
setVideoSelfieMode(enabled) {
|
|
2117
|
+
this.ensureInitialized();
|
|
2118
|
+
mlWasmJSApi_default.setFaceDetectionMode(this.getPipelineType(), enabled);
|
|
2119
|
+
}
|
|
2120
|
+
reset() {
|
|
2121
|
+
super.reset();
|
|
2122
|
+
this.currentFrame = null;
|
|
2123
|
+
this.bestCanvas = null;
|
|
2124
|
+
this.bestFace = null;
|
|
2125
|
+
}
|
|
2126
|
+
createDefaultFaceCoordinates(canvas) {
|
|
2127
|
+
return {
|
|
2128
|
+
rightEyeX: 0,
|
|
2129
|
+
rightEyeY: 0,
|
|
2130
|
+
leftEyeX: 0,
|
|
2131
|
+
leftEyeY: 0,
|
|
2132
|
+
noseTipX: 0,
|
|
2133
|
+
noseTipY: 0,
|
|
2134
|
+
rightMouthX: 0,
|
|
2135
|
+
rightMouthY: 0,
|
|
2136
|
+
mouthX: 0,
|
|
2137
|
+
mouthY: 0,
|
|
2138
|
+
x: 0,
|
|
2139
|
+
y: 0,
|
|
2140
|
+
width: canvas.width() ?? 0,
|
|
2141
|
+
height: canvas.height() ?? 0
|
|
2142
|
+
};
|
|
2143
|
+
}
|
|
2144
|
+
formatFaceCoordinates(face) {
|
|
2145
|
+
return {
|
|
2146
|
+
rightEyeX: face.rightEye.x,
|
|
2147
|
+
rightEyeY: face.rightEye.y,
|
|
2148
|
+
leftEyeX: face.leftEye.x,
|
|
2149
|
+
leftEyeY: face.leftEye.y,
|
|
2150
|
+
noseTipX: face.noseTip.x,
|
|
2151
|
+
noseTipY: face.noseTip.y,
|
|
2152
|
+
rightMouthX: face.rightMouthCorner.x,
|
|
2153
|
+
rightMouthY: face.rightMouthCorner.y,
|
|
2154
|
+
mouthX: face.leftMouthCorner.x,
|
|
2155
|
+
mouthY: face.leftMouthCorner.y,
|
|
2156
|
+
x: face.rect.x,
|
|
2157
|
+
y: face.rect.y,
|
|
2158
|
+
width: face.rect.width,
|
|
2159
|
+
height: face.rect.height
|
|
2160
|
+
};
|
|
2161
|
+
}
|
|
2162
|
+
};
|
|
2163
|
+
|
|
2164
|
+
//#endregion
|
|
2165
|
+
//#region ../infra/src/providers/wasm/WasmUtilProvider.ts
|
|
2166
|
+
var WasmUtilProvider = class WasmUtilProvider extends BaseWasmProvider {
|
|
2167
|
+
static async getInstance() {
|
|
2168
|
+
if (WasmUtilProvider.instance) return WasmUtilProvider.instance;
|
|
2169
|
+
if (WasmUtilProvider.initPromise) return WasmUtilProvider.initPromise;
|
|
2170
|
+
WasmUtilProvider.initPromise = (async () => {
|
|
2171
|
+
const instance = new WasmUtilProvider();
|
|
2172
|
+
await instance.initializeBase({}, "selfie");
|
|
2173
|
+
WasmUtilProvider.instance = instance;
|
|
2174
|
+
return instance;
|
|
2175
|
+
})();
|
|
2176
|
+
return WasmUtilProvider.initPromise;
|
|
2177
|
+
}
|
|
2178
|
+
static resetInstance() {
|
|
2179
|
+
WasmUtilProvider.instance = void 0;
|
|
2180
|
+
WasmUtilProvider.initPromise = void 0;
|
|
2181
|
+
}
|
|
2182
|
+
constructor() {
|
|
2183
|
+
super(void 0);
|
|
2184
|
+
}
|
|
2185
|
+
async initialize(config) {
|
|
2186
|
+
if (this.initialized) return;
|
|
2187
|
+
const pipeline = config.pipelines?.[0] ?? "selfie";
|
|
2188
|
+
await this.initializeBase(config, pipeline);
|
|
2189
|
+
}
|
|
2190
|
+
encryptImage(image) {
|
|
2191
|
+
this.ensureInitialized();
|
|
2192
|
+
return mlWasmJSApi_default.ens(image);
|
|
2193
|
+
}
|
|
2194
|
+
setSdkVersion(version) {
|
|
2195
|
+
this.ensureInitialized();
|
|
2196
|
+
mlWasmJSApi_default.setSdkVersion(version);
|
|
2197
|
+
}
|
|
2198
|
+
setSdkPlatform(platform) {
|
|
2199
|
+
this.ensureInitialized();
|
|
2200
|
+
mlWasmJSApi_default.setSdkPlatform(platform);
|
|
2201
|
+
}
|
|
2202
|
+
setDeviceInfo(deviceInfo, overrideExisting = true) {
|
|
2203
|
+
this.ensureInitialized();
|
|
2204
|
+
mlWasmJSApi_default.setDeviceInfo(deviceInfo, overrideExisting);
|
|
2205
|
+
}
|
|
2206
|
+
setBrowserInfo(browserInfo, overrideExisting = true) {
|
|
2207
|
+
this.ensureInitialized();
|
|
2208
|
+
mlWasmJSApi_default.setBrowserInfo(browserInfo, overrideExisting);
|
|
2209
|
+
}
|
|
2210
|
+
setCameraInfo(cameraInfo, overrideExisting = true) {
|
|
2211
|
+
this.ensureInitialized();
|
|
2212
|
+
mlWasmJSApi_default.setCameraInfo(cameraInfo, overrideExisting);
|
|
2213
|
+
}
|
|
2214
|
+
setMotionStatus(status) {
|
|
2215
|
+
this.ensureInitialized();
|
|
2216
|
+
mlWasmJSApi_default.setMotionStatus(status);
|
|
2217
|
+
}
|
|
2218
|
+
setBackgroundMode(backgroundMode) {
|
|
2219
|
+
this.ensureInitialized();
|
|
2220
|
+
mlWasmJSApi_default.setBackgroundMode(backgroundMode);
|
|
2221
|
+
}
|
|
2222
|
+
setZc(zc) {
|
|
2223
|
+
this.ensureInitialized();
|
|
2224
|
+
mlWasmJSApi_default.setZc(zc);
|
|
2225
|
+
}
|
|
2226
|
+
setInspectorOpened(opened) {
|
|
2227
|
+
this.ensureInitialized();
|
|
2228
|
+
mlWasmJSApi_default.setInspectorOpened(opened);
|
|
2229
|
+
}
|
|
2230
|
+
getMetadata() {
|
|
2231
|
+
this.ensureInitialized();
|
|
2232
|
+
return mlWasmJSApi_default.getMetadata();
|
|
2233
|
+
}
|
|
2234
|
+
async analyzeFrame(image) {
|
|
2235
|
+
this.ensureInitialized();
|
|
2236
|
+
await mlWasmJSApi_default.analyzeFrame(image);
|
|
2237
|
+
}
|
|
2238
|
+
getCheck() {
|
|
2239
|
+
this.ensureInitialized();
|
|
2240
|
+
return mlWasmJSApi_default.getCheck();
|
|
2241
|
+
}
|
|
2242
|
+
estimatePerformance() {
|
|
2243
|
+
this.ensureInitialized();
|
|
2244
|
+
return mlWasmJSApi_default.estimatePerformance();
|
|
2245
|
+
}
|
|
2246
|
+
isVirtualCamera(label) {
|
|
2247
|
+
this.ensureInitialized();
|
|
2248
|
+
return mlWasmJSApi_default.isVirtualCamera(label);
|
|
2249
|
+
}
|
|
2250
|
+
async poc(output) {
|
|
2251
|
+
this.ensureInitialized();
|
|
2252
|
+
await mlWasmJSApi_default.poc(output);
|
|
2253
|
+
}
|
|
2254
|
+
ckvcks(data) {
|
|
2255
|
+
this.ensureInitialized();
|
|
2256
|
+
mlWasmJSApi_default.ckvcks(data);
|
|
2257
|
+
}
|
|
2258
|
+
async getVersions() {
|
|
2259
|
+
this.ensureInitialized();
|
|
2260
|
+
return mlWasmJSApi_default.getVersions();
|
|
2261
|
+
}
|
|
2262
|
+
};
|
|
2263
|
+
|
|
2264
|
+
//#endregion
|
|
2265
|
+
//#region src/internal/http/api.ts
|
|
2266
|
+
let client = null;
|
|
2267
|
+
let currentToken = null;
|
|
2268
|
+
function setClient(httpClient) {
|
|
2269
|
+
client = httpClient;
|
|
2270
|
+
}
|
|
2271
|
+
function setToken(token) {
|
|
2272
|
+
currentToken = token;
|
|
2273
|
+
}
|
|
2274
|
+
function getToken() {
|
|
2275
|
+
return currentToken;
|
|
2276
|
+
}
|
|
2277
|
+
function getApi() {
|
|
2278
|
+
if (!client) throw new Error("SDK not configured. Call setup({ apiURL: \"...\" }) first.");
|
|
2279
|
+
return client;
|
|
2280
|
+
}
|
|
2281
|
+
function resetApi() {
|
|
2282
|
+
client = null;
|
|
2283
|
+
currentToken = null;
|
|
2284
|
+
}
|
|
2285
|
+
function addTokenHeader(config) {
|
|
2286
|
+
if (!currentToken) return config ?? {};
|
|
2287
|
+
return {
|
|
2288
|
+
...config,
|
|
2289
|
+
headers: {
|
|
2290
|
+
...config?.headers,
|
|
2291
|
+
"X-Incode-Hardware-Id": currentToken
|
|
2292
|
+
}
|
|
2293
|
+
};
|
|
2294
|
+
}
|
|
2295
|
+
const api = {
|
|
2296
|
+
get(url, config) {
|
|
2297
|
+
return getApi().get(url, addTokenHeader(config));
|
|
2298
|
+
},
|
|
2299
|
+
post(url, data, config) {
|
|
2300
|
+
return getApi().post(url, data, addTokenHeader(config));
|
|
2301
|
+
},
|
|
2302
|
+
put(url, data, config) {
|
|
2303
|
+
return getApi().put(url, data, addTokenHeader(config));
|
|
2304
|
+
},
|
|
2305
|
+
patch(url, data, config) {
|
|
2306
|
+
return getApi().patch(url, data, addTokenHeader(config));
|
|
2307
|
+
},
|
|
2308
|
+
delete(url, config) {
|
|
2309
|
+
return getApi().delete(url, addTokenHeader(config));
|
|
2310
|
+
}
|
|
2311
|
+
};
|
|
2312
|
+
|
|
2313
|
+
//#endregion
|
|
2314
|
+
//#region src/internal/http/endpoints.ts
|
|
2315
|
+
const endpoints = {
|
|
2316
|
+
createSession: "/omni/start",
|
|
2317
|
+
flow: "/omni/onboarding/flow",
|
|
2318
|
+
events: "/omni/interview-events",
|
|
2319
|
+
selfie: "/omni/add/face",
|
|
2320
|
+
recordingCreateSessionV2: "/omni/recordings/create-session/v2",
|
|
2321
|
+
recordingStartV2: "/omni/recordings/record-start/v2",
|
|
2322
|
+
recordingStopV2: "/omni/recordings/record-stop/v2",
|
|
2323
|
+
deepsightVideoImport: "/omni/recordings/import",
|
|
2324
|
+
phone: "/omni/add/phone",
|
|
2325
|
+
phoneInstant: "/omni/instant/add/phone",
|
|
2326
|
+
getPhone: "/omni/get/phone",
|
|
2327
|
+
startInfo: "/omni/start-info",
|
|
2328
|
+
sendSmsOtp: "/omni/send/sms-otp",
|
|
2329
|
+
compareOtp: "/omni/compare/otp",
|
|
2330
|
+
email: "/omni/add/email",
|
|
2331
|
+
getEmail: "/omni/get/email"
|
|
2332
|
+
};
|
|
2333
|
+
|
|
2334
|
+
//#endregion
|
|
2335
|
+
export { queryCameraPermission as _, resetApi as a, createManager as b, WasmUtilProvider as c, VisibilityProvider as d, OpenViduRecordingProvider as f, StreamCanvasCapture as g, StreamCanvasProcessingSession as h, getToken as i, FaceDetectionProvider as l, DeepsightRecordingProvider as m, api as n, setClient as o, MotionSensorProvider as p, getApi as r, setToken as s, endpoints as t, warmupWasm as u, requestCameraAccess as v, createApi_default as x, stopCameraStream as y };
|