biometry-sdk 1.3.0 → 1.3.2
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/biometry-sdk.esm.js +1532 -0
- package/dist/components/biometry-enrollment.d.ts +26 -0
- package/dist/components/process-video.d.ts +53 -0
- package/dist/components/types.d.ts +12 -0
- package/dist/index.d.ts +3 -1
- package/dist/sdk.d.ts +98 -22
- package/dist/types/biometry/consent.d.ts +4 -0
- package/dist/types/biometry/doc-auth.d.ts +24 -0
- package/dist/types/biometry/enrollment.d.ts +40 -0
- package/dist/types/biometry/face-match.d.ts +13 -0
- package/dist/types/biometry/process-video.d.ts +32 -0
- package/dist/types/biometry/session.d.ts +4 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/internal.d.ts +4 -0
- package/package.json +3 -3
- package/dist/components/biometry-onboarding.d.ts +0 -1
- package/dist/components/biometry-onboarding.js +0 -233
- package/dist/index.js +0 -2
- package/dist/sdk.js +0 -179
- package/dist/sdk.test.js +0 -255
- package/dist/types.d.ts +0 -105
- package/dist/types.js +0 -14
|
@@ -0,0 +1,1532 @@
|
|
|
1
|
+
class BiometrySDK {
|
|
2
|
+
constructor(apiKey) {
|
|
3
|
+
if (!apiKey) {
|
|
4
|
+
throw new Error('API Key is required to initialize the SDK.');
|
|
5
|
+
}
|
|
6
|
+
this.apiKey = apiKey;
|
|
7
|
+
}
|
|
8
|
+
async request(path, method, body, headers) {
|
|
9
|
+
const defaultHeaders = {
|
|
10
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
11
|
+
};
|
|
12
|
+
const requestHeaders = Object.assign(Object.assign({}, defaultHeaders), headers);
|
|
13
|
+
if (body && !(body instanceof FormData)) {
|
|
14
|
+
requestHeaders['Content-Type'] = 'application/json';
|
|
15
|
+
body = JSON.stringify(body);
|
|
16
|
+
}
|
|
17
|
+
const response = await fetch(`${BiometrySDK.BASE_URL}${path}`, {
|
|
18
|
+
method,
|
|
19
|
+
headers: requestHeaders,
|
|
20
|
+
body,
|
|
21
|
+
});
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
const errorData = await response.json().catch(() => ({}));
|
|
24
|
+
const errorMessage = (errorData === null || errorData === undefined ? undefined : errorData.error) || (errorData === null || errorData === undefined ? undefined : errorData.message) || 'Unknown error occurred';
|
|
25
|
+
throw new Error(`Error ${response.status}: ${errorMessage}`);
|
|
26
|
+
}
|
|
27
|
+
// Extract response headers
|
|
28
|
+
const responseHeaders = {};
|
|
29
|
+
const requestId = response.headers.get("X-Request-Id");
|
|
30
|
+
if (requestId) {
|
|
31
|
+
responseHeaders["X-Request-Id"] = requestId;
|
|
32
|
+
}
|
|
33
|
+
const responseBody = await response.json();
|
|
34
|
+
return {
|
|
35
|
+
body: responseBody,
|
|
36
|
+
headers: responseHeaders
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Starts a new Session for a user.
|
|
41
|
+
*
|
|
42
|
+
* @returns {Promise<ApiResponse<SessionResponse>>} A promise resolving to the session ID.
|
|
43
|
+
* @throws {Error} - If the request fails.
|
|
44
|
+
*/
|
|
45
|
+
async startSession() {
|
|
46
|
+
return await this.request('/api-gateway/sessions/start', 'POST');
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Submits Authorization consent for a user.
|
|
50
|
+
* Authorization Consent is required to use the services like Face and Voice recognition.
|
|
51
|
+
*
|
|
52
|
+
* @param {boolean} isConsentGiven - Indicates whether the user has given consent.
|
|
53
|
+
* @param {string} userFullName - The full name of the user giving consent.
|
|
54
|
+
* @param {Object} [props] - Optional properties for the consent request.
|
|
55
|
+
* @param {string} [props.sessionId] - Session ID to link this consent with a specific session group.
|
|
56
|
+
* @param {object} [props.deviceInfo] - Device information object containing details about the user's device.
|
|
57
|
+
* This can include properties like operating system, browser, etc.
|
|
58
|
+
* @returns {Promise<ApiResponse<ConsentResponse>>} A promise resolving to the consent response.
|
|
59
|
+
* @throws {Error} - If the user's full name is not provided or if the request fails.
|
|
60
|
+
*/
|
|
61
|
+
async giveAuthorizationConsent(isConsentGiven, userFullName, props) {
|
|
62
|
+
if (!userFullName) {
|
|
63
|
+
throw new Error('User Full Name is required to give consent.');
|
|
64
|
+
}
|
|
65
|
+
const body = {
|
|
66
|
+
is_consent_given: isConsentGiven,
|
|
67
|
+
user_fullname: userFullName,
|
|
68
|
+
};
|
|
69
|
+
const headers = {};
|
|
70
|
+
if (props === null || props === undefined ? undefined : props.sessionId) {
|
|
71
|
+
headers['X-Session-ID'] = props.sessionId;
|
|
72
|
+
}
|
|
73
|
+
if (props === null || props === undefined ? undefined : props.deviceInfo) {
|
|
74
|
+
headers['X-Device-Info'] = JSON.stringify(props.deviceInfo);
|
|
75
|
+
}
|
|
76
|
+
return await this.request('/api-consent/consent', 'POST', body, headers);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Submits Storage consent for a user.
|
|
80
|
+
* Storage consent is granted by users, allowing us to store their biometric data for future verification.
|
|
81
|
+
*
|
|
82
|
+
* @param {boolean} isStorageConsentGiven - Indicates whether the user has given storage consent.
|
|
83
|
+
* @param {string} userFullName - The full name of the user giving storage consent.
|
|
84
|
+
* @param {Object} [props] - Optional properties for the consent request.
|
|
85
|
+
* @param {string} [props.sessionId] - Session ID to link this consent with a specific session group.
|
|
86
|
+
* @param {object} [props.deviceInfo] - Device information object containing details about the user's device.
|
|
87
|
+
* This can include properties like operating system, browser, etc.
|
|
88
|
+
* @returns {Promise<ApiResponse<ConsentResponse>>} A promise resolving to the consent response.
|
|
89
|
+
* @throws {Error} - If the user's full name is not provided or if the request fails.
|
|
90
|
+
*/
|
|
91
|
+
async giveStorageConsent(isStorageConsentGiven, userFullName, props) {
|
|
92
|
+
if (!userFullName) {
|
|
93
|
+
throw new Error('User Full Name is required to give storage consent.');
|
|
94
|
+
}
|
|
95
|
+
const body = {
|
|
96
|
+
is_consent_given: isStorageConsentGiven,
|
|
97
|
+
user_fullname: userFullName,
|
|
98
|
+
};
|
|
99
|
+
const headers = {};
|
|
100
|
+
if (props === null || props === undefined ? undefined : props.sessionId) {
|
|
101
|
+
headers['X-Session-ID'] = props.sessionId;
|
|
102
|
+
}
|
|
103
|
+
if (props === null || props === undefined ? undefined : props.deviceInfo) {
|
|
104
|
+
headers['X-Device-Info'] = JSON.stringify(props.deviceInfo);
|
|
105
|
+
}
|
|
106
|
+
return await this.request('/api-consent/strg-consent', 'POST', body, headers);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Enrolls a user's voice for biometric authentication.
|
|
110
|
+
*
|
|
111
|
+
* @param {File} audio - The audio file containing the user's voice.
|
|
112
|
+
* @param {string} userFullName - The full name of the user being enrolled.
|
|
113
|
+
* @param {string} uniqueId - A unique identifier for the enrolling process.
|
|
114
|
+
* @param {string} phrase - The phrase spoken in the audio file.
|
|
115
|
+
* @param {Object} [props] - Optional properties for the enrollment request.
|
|
116
|
+
* @param {string} [props.sessionId] - Session ID to link this enrollment with a specific session group.
|
|
117
|
+
* @param {object} [props.deviceInfo] - Device information object containing details about the user's device.
|
|
118
|
+
* This can include properties like operating system, browser, etc.
|
|
119
|
+
* @returns {Promise<ApiResponse<VoiceEnrollmentResponse>>} - A promise resolving to the voice enrolling response.
|
|
120
|
+
* @throws {Error} - If required parameters are missing or the request fails.
|
|
121
|
+
*/
|
|
122
|
+
async enrollVoice(audio, userFullName, uniqueId, phrase, props) {
|
|
123
|
+
if (!userFullName)
|
|
124
|
+
throw new Error('User fullname is required.');
|
|
125
|
+
if (!uniqueId)
|
|
126
|
+
throw new Error('Unique ID is required.');
|
|
127
|
+
if (!phrase)
|
|
128
|
+
throw new Error('Phrase is required.');
|
|
129
|
+
if (!audio)
|
|
130
|
+
throw new Error('Audio file is required.');
|
|
131
|
+
const formData = new FormData();
|
|
132
|
+
formData.append('unique_id', uniqueId);
|
|
133
|
+
formData.append('phrase', phrase);
|
|
134
|
+
formData.append('voice', audio);
|
|
135
|
+
const headers = {
|
|
136
|
+
'X-User-Fullname': userFullName,
|
|
137
|
+
};
|
|
138
|
+
if (props === null || props === undefined ? undefined : props.sessionId) {
|
|
139
|
+
headers['X-Session-ID'] = props.sessionId;
|
|
140
|
+
}
|
|
141
|
+
if (props === null || props === undefined ? undefined : props.deviceInfo) {
|
|
142
|
+
headers['X-Device-Info'] = JSON.stringify(props.deviceInfo);
|
|
143
|
+
}
|
|
144
|
+
return await this.request('/api-gateway/enroll/voice', 'POST', formData, headers);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Enrolls a user's face for biometric authentication.
|
|
148
|
+
*
|
|
149
|
+
* @param {File} face - Image file that contains user's face.
|
|
150
|
+
* @param {string} userFullName - The full name of the user being enrolled.
|
|
151
|
+
* @param {string} isDocument - Indicates whether the image is a document.
|
|
152
|
+
* @param {Object} [props] - Optional properties for the enrollment request.
|
|
153
|
+
* @param {string} [props.sessionId] - Session ID to link this enrollment with a specific session group.
|
|
154
|
+
* @param {object} [props.deviceInfo] - Device information object containing details about the user's device.
|
|
155
|
+
* This can include properties like operating system, browser, etc.
|
|
156
|
+
* @returns {Promise<ApiResponse<FaceEnrollmentResponse>>} - A promise resolving to the voice enrolling response.
|
|
157
|
+
* @throws {Error} - If required parameters are missing or the request fails.
|
|
158
|
+
*/
|
|
159
|
+
async enrollFace(face, userFullName, isDocument, props) {
|
|
160
|
+
if (!userFullName)
|
|
161
|
+
throw new Error('User fullname is required.');
|
|
162
|
+
if (!face)
|
|
163
|
+
throw new Error('Face image is required.');
|
|
164
|
+
const formData = new FormData();
|
|
165
|
+
formData.append('face', face);
|
|
166
|
+
if (isDocument) {
|
|
167
|
+
formData.append('is_document', 'true');
|
|
168
|
+
}
|
|
169
|
+
const headers = {
|
|
170
|
+
'X-User-Fullname': userFullName,
|
|
171
|
+
};
|
|
172
|
+
if (props === null || props === undefined ? undefined : props.sessionId) {
|
|
173
|
+
headers['X-Session-ID'] = props.sessionId;
|
|
174
|
+
}
|
|
175
|
+
if (props === null || props === undefined ? undefined : props.deviceInfo) {
|
|
176
|
+
headers['X-Device-Info'] = JSON.stringify(props.deviceInfo);
|
|
177
|
+
}
|
|
178
|
+
return await this.request('/api-gateway/enroll/face', 'POST', formData, headers);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Check the validity of a documents.
|
|
182
|
+
*
|
|
183
|
+
* @param {File} document - Document image file.
|
|
184
|
+
* @param {string} userFullName - The full name of the user being checked.
|
|
185
|
+
* @param {Object} [props] - Optional properties for the enrollment request.
|
|
186
|
+
* @param {string} [props.sessionId] - Session ID to link this enrollment with a specific session group.
|
|
187
|
+
* @param {object} [props.deviceInfo] - Device information object containing details about the user's device.
|
|
188
|
+
* This can include properties like operating system, browser, etc.
|
|
189
|
+
* @returns {Promise<ApiResponse<DocAuthInfo>>} - A promise resolving to the document authentication information.
|
|
190
|
+
*/
|
|
191
|
+
async checkDocAuth(document, userFullName, props) {
|
|
192
|
+
if (!document)
|
|
193
|
+
throw new Error('Document image is required.');
|
|
194
|
+
if (!userFullName)
|
|
195
|
+
throw new Error('User fullname is required.');
|
|
196
|
+
const formData = new FormData();
|
|
197
|
+
formData.append('document', document);
|
|
198
|
+
const headers = {
|
|
199
|
+
'X-User-Fullname': userFullName,
|
|
200
|
+
};
|
|
201
|
+
if (props === null || props === undefined ? undefined : props.sessionId) {
|
|
202
|
+
headers['X-Session-ID'] = props.sessionId;
|
|
203
|
+
}
|
|
204
|
+
if (props === null || props === undefined ? undefined : props.deviceInfo) {
|
|
205
|
+
headers['X-Device-Info'] = JSON.stringify(props.deviceInfo);
|
|
206
|
+
}
|
|
207
|
+
return await this.request('/api-gateway/check-doc-auth', 'POST', formData, headers);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Matches a user's face from video against a reference image.
|
|
211
|
+
*
|
|
212
|
+
* @param {File} image - Reference image file that contains user's face.
|
|
213
|
+
* @param {string} video - Video file that contains user's face.
|
|
214
|
+
* @param {string} userFullName - Pass the full name of end-user to process Voice and Face recognition services.
|
|
215
|
+
* @param {string} processVideoRequestId - ID from the response header of /process-video endpoint.
|
|
216
|
+
* @param {boolean} usePrefilledVideo - Pass true to use the video from the process-video endpoint.
|
|
217
|
+
* @param {Object} [props] - Optional properties for the enrollment request.
|
|
218
|
+
* @param {string} [props.sessionId] - Session ID to link this enrollment with a specific session group.
|
|
219
|
+
* @param {object} [props.deviceInfo] - Device information object containing details about the user's device.
|
|
220
|
+
* This can include properties like operating system, browser, etc.
|
|
221
|
+
* @returns {Promise<FaceMatchResponse>} - A promise resolving to the voice enrolling response.
|
|
222
|
+
* @throws {Error} - If required parameters are missing or the request fails.
|
|
223
|
+
*/
|
|
224
|
+
async matchFaces(image, video, userFullName, processVideoRequestId, usePrefilledVideo, props) {
|
|
225
|
+
if (!image)
|
|
226
|
+
throw new Error('Face image is required.');
|
|
227
|
+
if ((!processVideoRequestId && !usePrefilledVideo) && !video)
|
|
228
|
+
throw new Error('Video is required.');
|
|
229
|
+
const formData = new FormData();
|
|
230
|
+
if (video) {
|
|
231
|
+
formData.append('video', video);
|
|
232
|
+
}
|
|
233
|
+
formData.append('image', image);
|
|
234
|
+
const headers = {};
|
|
235
|
+
if (userFullName) {
|
|
236
|
+
headers['X-User-Fullname'] = userFullName;
|
|
237
|
+
}
|
|
238
|
+
if (processVideoRequestId) {
|
|
239
|
+
headers['X-Request-Id'] = processVideoRequestId;
|
|
240
|
+
}
|
|
241
|
+
if (processVideoRequestId && usePrefilledVideo) {
|
|
242
|
+
headers['X-Use-Prefilled-Video'] = 'true';
|
|
243
|
+
}
|
|
244
|
+
if (props === null || props === undefined ? undefined : props.sessionId) {
|
|
245
|
+
headers['X-Session-ID'] = props.sessionId;
|
|
246
|
+
}
|
|
247
|
+
if (props === null || props === undefined ? undefined : props.deviceInfo) {
|
|
248
|
+
headers['X-Device-Info'] = JSON.stringify(props.deviceInfo);
|
|
249
|
+
}
|
|
250
|
+
if (props === null || props === undefined ? undefined : props.deviceInfo) {
|
|
251
|
+
headers['X-Device-Info'] = JSON.stringify(props.deviceInfo);
|
|
252
|
+
}
|
|
253
|
+
return await this.request('/api-gateway/match-faces', 'POST', formData, headers);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Process the video through Biometry services to check liveness and authorize user
|
|
257
|
+
*
|
|
258
|
+
* @param {File} video - Video file that you want to process.
|
|
259
|
+
* @param {string} phrase - Set of numbers that user needs to say out loud in the video.
|
|
260
|
+
* @param {string} userFullName - Pass the full name of end-user to process Voice and Face recognition services.
|
|
261
|
+
* @param {Object} [props] - Optional properties for the enrollment request.
|
|
262
|
+
* @param {string} [props.sessionId] - Session ID to link this enrollment with a specific session group.
|
|
263
|
+
* @param {object} [props.deviceInfo] - Device information object containing details about the user's device.
|
|
264
|
+
* This can include properties like operating system, browser, etc.
|
|
265
|
+
* @returns {Promise<ApiResponse<ProcessVideoResponse>>} - A promise resolving to the process video response.
|
|
266
|
+
*/
|
|
267
|
+
async processVideo(video, phrase, userFullName, props) {
|
|
268
|
+
if (!video)
|
|
269
|
+
throw new Error('Video is required.');
|
|
270
|
+
if (!phrase)
|
|
271
|
+
throw new Error('Phrase is required.');
|
|
272
|
+
const formData = new FormData();
|
|
273
|
+
formData.append('phrase', phrase);
|
|
274
|
+
formData.append('video', video);
|
|
275
|
+
const headers = {};
|
|
276
|
+
if (userFullName) {
|
|
277
|
+
headers['X-User-Fullname'] = userFullName;
|
|
278
|
+
}
|
|
279
|
+
if (props === null || props === undefined ? undefined : props.sessionId) {
|
|
280
|
+
headers['X-Session-ID'] = props.sessionId;
|
|
281
|
+
}
|
|
282
|
+
if (props === null || props === undefined ? undefined : props.deviceInfo) {
|
|
283
|
+
headers['X-Device-Info'] = JSON.stringify(props.deviceInfo);
|
|
284
|
+
}
|
|
285
|
+
return await this.request('/api-gateway/process-video', 'POST', formData, headers);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
BiometrySDK.BASE_URL = 'https://api.biometrysolutions.com'; //'https://dev-console.biometrysolutions.com';
|
|
289
|
+
|
|
290
|
+
var BiometryAttributes;
|
|
291
|
+
(function (BiometryAttributes) {
|
|
292
|
+
BiometryAttributes["ApiKey"] = "api-key";
|
|
293
|
+
BiometryAttributes["UserFullname"] = "user-fullname";
|
|
294
|
+
})(BiometryAttributes || (BiometryAttributes = {}));
|
|
295
|
+
var BiometryEnrollmentState;
|
|
296
|
+
(function (BiometryEnrollmentState) {
|
|
297
|
+
BiometryEnrollmentState["Loading"] = "loading";
|
|
298
|
+
BiometryEnrollmentState["Success"] = "success";
|
|
299
|
+
BiometryEnrollmentState["ErrorNoFace"] = "error-no-face";
|
|
300
|
+
BiometryEnrollmentState["ErrorMultipleFaces"] = "error-multiple-faces";
|
|
301
|
+
BiometryEnrollmentState["ErrorNotCentered"] = "error-not-centered";
|
|
302
|
+
BiometryEnrollmentState["ErrorOther"] = "error-other";
|
|
303
|
+
})(BiometryEnrollmentState || (BiometryEnrollmentState = {}));
|
|
304
|
+
|
|
305
|
+
class BiometryEnrollment extends HTMLElement {
|
|
306
|
+
constructor() {
|
|
307
|
+
super();
|
|
308
|
+
this.videoElement = null;
|
|
309
|
+
this.canvasElement = null;
|
|
310
|
+
this.captureButton = null;
|
|
311
|
+
this.shadow = this.attachShadow({ mode: "open" });
|
|
312
|
+
this.sdk = null;
|
|
313
|
+
this.toggleState = this.toggleState.bind(this);
|
|
314
|
+
this.capturePhoto = this.capturePhoto.bind(this);
|
|
315
|
+
}
|
|
316
|
+
static get observedAttributes() {
|
|
317
|
+
return Object.values(BiometryAttributes);
|
|
318
|
+
}
|
|
319
|
+
get apiKey() {
|
|
320
|
+
return this.getAttribute("api-key");
|
|
321
|
+
}
|
|
322
|
+
set apiKey(value) {
|
|
323
|
+
if (value) {
|
|
324
|
+
this.setAttribute("api-key", value);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
this.removeAttribute("api-key");
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
get userFullname() {
|
|
331
|
+
return this.getAttribute("user-fullname");
|
|
332
|
+
}
|
|
333
|
+
set userFullname(value) {
|
|
334
|
+
if (value) {
|
|
335
|
+
this.setAttribute("user-fullname", value);
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
this.removeAttribute("user-fullname");
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
342
|
+
if (name === "api-key" || name === "user-fullname") {
|
|
343
|
+
this.validateAttributes();
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
connectedCallback() {
|
|
347
|
+
this.validateAttributes();
|
|
348
|
+
this.init();
|
|
349
|
+
}
|
|
350
|
+
disconnectedCallback() {
|
|
351
|
+
this.cleanup();
|
|
352
|
+
}
|
|
353
|
+
validateAttributes() {
|
|
354
|
+
if (!this.apiKey) {
|
|
355
|
+
console.error("API key is required.");
|
|
356
|
+
this.toggleState(BiometryEnrollmentState.ErrorOther);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (!this.userFullname) {
|
|
360
|
+
console.error("User fullname is required.");
|
|
361
|
+
this.toggleState(BiometryEnrollmentState.ErrorOther);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
init() {
|
|
366
|
+
this.shadow.innerHTML = `
|
|
367
|
+
<style>
|
|
368
|
+
.wrapper {
|
|
369
|
+
position: relative;
|
|
370
|
+
}
|
|
371
|
+
video {
|
|
372
|
+
transform: scaleX(-1); /* Flip video for preview */
|
|
373
|
+
max-width: 100%;
|
|
374
|
+
border-radius: var(--border-radius, 8px);
|
|
375
|
+
}
|
|
376
|
+
canvas {
|
|
377
|
+
display: none;
|
|
378
|
+
}
|
|
379
|
+
</style>
|
|
380
|
+
<div class="wrapper">
|
|
381
|
+
<slot name="video">
|
|
382
|
+
<video id="video" autoplay playsinline></video>
|
|
383
|
+
</slot>
|
|
384
|
+
<slot name="canvas">
|
|
385
|
+
<canvas id="canvas" style="display: none;"></canvas>
|
|
386
|
+
</slot>
|
|
387
|
+
<slot name="button">
|
|
388
|
+
<button id="button">Capture Photo</button>
|
|
389
|
+
</slot>
|
|
390
|
+
<div class="status">
|
|
391
|
+
<slot name="loading" class="loading"></slot>
|
|
392
|
+
<slot name="success" class="success"></slot>
|
|
393
|
+
<slot name="error-no-face" class="error-no-face"></slot>
|
|
394
|
+
<slot name="error-multiple-faces" class="error-multiple-faces"></slot>
|
|
395
|
+
<slot name="error-not-centered" class="error-not-centered"></slot>
|
|
396
|
+
<slot name="error-other" class="error-other"></slot>
|
|
397
|
+
</div>
|
|
398
|
+
</div>
|
|
399
|
+
`;
|
|
400
|
+
this.initializeSDK();
|
|
401
|
+
this.attachSlotListeners();
|
|
402
|
+
this.setupCamera();
|
|
403
|
+
this.toggleState("");
|
|
404
|
+
}
|
|
405
|
+
cleanup() {
|
|
406
|
+
var _a;
|
|
407
|
+
if ((_a = this.videoElement) === null || _a === undefined ? undefined : _a.srcObject) {
|
|
408
|
+
const tracks = this.videoElement.srcObject.getTracks();
|
|
409
|
+
tracks.forEach((track) => track.stop());
|
|
410
|
+
}
|
|
411
|
+
if (this.videoElement) {
|
|
412
|
+
this.videoElement.srcObject = null;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
initializeSDK() {
|
|
416
|
+
if (this.apiKey) {
|
|
417
|
+
this.sdk = new BiometrySDK(this.apiKey);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
this.toggleState(BiometryEnrollmentState.ErrorOther);
|
|
421
|
+
console.error("API key is required to initialize the SDK.");
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
toggleState(state) {
|
|
425
|
+
const slots = [
|
|
426
|
+
BiometryEnrollmentState.Loading,
|
|
427
|
+
BiometryEnrollmentState.Success,
|
|
428
|
+
BiometryEnrollmentState.ErrorNoFace,
|
|
429
|
+
BiometryEnrollmentState.ErrorMultipleFaces,
|
|
430
|
+
BiometryEnrollmentState.ErrorNotCentered,
|
|
431
|
+
BiometryEnrollmentState.ErrorOther,
|
|
432
|
+
];
|
|
433
|
+
slots.forEach((slotName) => {
|
|
434
|
+
const slot = this.shadow.querySelector(`slot[name="${slotName}"]`);
|
|
435
|
+
if (slot) {
|
|
436
|
+
slot.style.display = slotName === state ? "block" : "none";
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
attachSlotListeners() {
|
|
441
|
+
const videoSlot = this.shadow.querySelector('slot[name="video"]');
|
|
442
|
+
const canvasSlot = this.shadow.querySelector('slot[name="canvas"]');
|
|
443
|
+
const buttonSlot = this.shadow.querySelector('slot[name="button"]');
|
|
444
|
+
const assignedVideoElements = videoSlot.assignedElements();
|
|
445
|
+
this.videoElement = (assignedVideoElements.length > 0 ? assignedVideoElements[0] : null) || this.shadow.querySelector("#video");
|
|
446
|
+
const assignedCanvasElements = canvasSlot.assignedElements();
|
|
447
|
+
this.canvasElement = (assignedCanvasElements.length > 0 ? assignedCanvasElements[0] : null) || this.shadow.querySelector("#canvas");
|
|
448
|
+
const assignedButtonElements = buttonSlot.assignedElements();
|
|
449
|
+
this.captureButton = (assignedButtonElements.length > 0 ? assignedButtonElements[0] : null) || this.shadow.querySelector("#button");
|
|
450
|
+
if (!this.videoElement) {
|
|
451
|
+
console.error("Video element is missing.");
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
if (!this.captureButton) {
|
|
455
|
+
console.error("Capture button is missing.");
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
this.captureButton.addEventListener("click", this.capturePhoto);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
setupCamera() {
|
|
463
|
+
if (!this.videoElement) {
|
|
464
|
+
console.error("Video element is missing.");
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
navigator.mediaDevices
|
|
468
|
+
.getUserMedia({ video: true })
|
|
469
|
+
.then((stream) => {
|
|
470
|
+
this.videoElement.srcObject = stream;
|
|
471
|
+
})
|
|
472
|
+
.catch((error) => {
|
|
473
|
+
console.error("Error accessing camera:", error);
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
async capturePhoto() {
|
|
477
|
+
try {
|
|
478
|
+
if (!this.videoElement || !this.canvasElement || !this.sdk) {
|
|
479
|
+
console.error("Essential elements or SDK are not initialized.");
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
const context = this.canvasElement.getContext("2d");
|
|
483
|
+
this.canvasElement.width = this.videoElement.videoWidth;
|
|
484
|
+
this.canvasElement.height = this.videoElement.videoHeight;
|
|
485
|
+
context.drawImage(this.videoElement, 0, 0, this.canvasElement.width, this.canvasElement.height);
|
|
486
|
+
this.toggleState("loading");
|
|
487
|
+
this.canvasElement.toBlob(async (blob) => {
|
|
488
|
+
try {
|
|
489
|
+
if (!blob) {
|
|
490
|
+
console.error("Failed to capture photo.");
|
|
491
|
+
this.toggleState(BiometryEnrollmentState.ErrorOther);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
const file = new File([blob], "onboard-face.jpg", { type: "image/jpeg" });
|
|
495
|
+
try {
|
|
496
|
+
const response = await this.sdk.enrollFace(file, this.userFullname);
|
|
497
|
+
const result = response.body.data.enroll_result;
|
|
498
|
+
this.resultCode = result === null || result === void 0 ? void 0 : result.code;
|
|
499
|
+
this.description = (result === null || result === void 0 ? void 0 : result.description) || "Unknown error occurred.";
|
|
500
|
+
switch (this.resultCode) {
|
|
501
|
+
case 0:
|
|
502
|
+
this.toggleState(BiometryEnrollmentState.Success);
|
|
503
|
+
break;
|
|
504
|
+
case 1:
|
|
505
|
+
this.toggleState(BiometryEnrollmentState.ErrorNoFace);
|
|
506
|
+
break;
|
|
507
|
+
case 2:
|
|
508
|
+
this.toggleState(BiometryEnrollmentState.ErrorMultipleFaces);
|
|
509
|
+
break;
|
|
510
|
+
case 3:
|
|
511
|
+
this.toggleState(BiometryEnrollmentState.ErrorNotCentered);
|
|
512
|
+
break;
|
|
513
|
+
default:
|
|
514
|
+
this.toggleState(BiometryEnrollmentState.ErrorOther);
|
|
515
|
+
}
|
|
516
|
+
console.log("Enrollment result:", result);
|
|
517
|
+
}
|
|
518
|
+
catch (error) {
|
|
519
|
+
console.error("Error enrolling face:", error);
|
|
520
|
+
this.toggleState(BiometryEnrollmentState.ErrorOther);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
catch (error) {
|
|
524
|
+
console.error("Error in toBlob callback:", error);
|
|
525
|
+
this.toggleState(BiometryEnrollmentState.ErrorOther);
|
|
526
|
+
}
|
|
527
|
+
}, "image/jpeg");
|
|
528
|
+
}
|
|
529
|
+
catch (error) {
|
|
530
|
+
console.error("Error capturing photo:", error);
|
|
531
|
+
this.toggleState(BiometryEnrollmentState.ErrorOther);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
customElements.define("biometry-enrollment", BiometryEnrollment);
|
|
536
|
+
|
|
537
|
+
function getDefaultExportFromCjs (x) {
|
|
538
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
var fixWebmDuration = {exports: {}};
|
|
542
|
+
|
|
543
|
+
var hasRequiredFixWebmDuration;
|
|
544
|
+
|
|
545
|
+
function requireFixWebmDuration () {
|
|
546
|
+
if (hasRequiredFixWebmDuration) return fixWebmDuration.exports;
|
|
547
|
+
hasRequiredFixWebmDuration = 1;
|
|
548
|
+
(function (module) {
|
|
549
|
+
(function (name, definition) {
|
|
550
|
+
if (module.exports) { // CommonJS / Node.js
|
|
551
|
+
module.exports = definition();
|
|
552
|
+
} else { // Direct include
|
|
553
|
+
window.ysFixWebmDuration = definition();
|
|
554
|
+
}
|
|
555
|
+
})('fix-webm-duration', function () {
|
|
556
|
+
/*
|
|
557
|
+
* This is the list of possible WEBM file sections by their IDs.
|
|
558
|
+
* Possible types: Container, Binary, Uint, Int, String, Float, Date
|
|
559
|
+
*/
|
|
560
|
+
var sections = {
|
|
561
|
+
0xa45dfa3: { name: 'EBML', type: 'Container' },
|
|
562
|
+
0x286: { name: 'EBMLVersion', type: 'Uint' },
|
|
563
|
+
0x2f7: { name: 'EBMLReadVersion', type: 'Uint' },
|
|
564
|
+
0x2f2: { name: 'EBMLMaxIDLength', type: 'Uint' },
|
|
565
|
+
0x2f3: { name: 'EBMLMaxSizeLength', type: 'Uint' },
|
|
566
|
+
0x282: { name: 'DocType', type: 'String' },
|
|
567
|
+
0x287: { name: 'DocTypeVersion', type: 'Uint' },
|
|
568
|
+
0x285: { name: 'DocTypeReadVersion', type: 'Uint' },
|
|
569
|
+
0x6c: { name: 'Void', type: 'Binary' },
|
|
570
|
+
0x3f: { name: 'CRC-32', type: 'Binary' },
|
|
571
|
+
0xb538667: { name: 'SignatureSlot', type: 'Container' },
|
|
572
|
+
0x3e8a: { name: 'SignatureAlgo', type: 'Uint' },
|
|
573
|
+
0x3e9a: { name: 'SignatureHash', type: 'Uint' },
|
|
574
|
+
0x3ea5: { name: 'SignaturePublicKey', type: 'Binary' },
|
|
575
|
+
0x3eb5: { name: 'Signature', type: 'Binary' },
|
|
576
|
+
0x3e5b: { name: 'SignatureElements', type: 'Container' },
|
|
577
|
+
0x3e7b: { name: 'SignatureElementList', type: 'Container' },
|
|
578
|
+
0x2532: { name: 'SignedElement', type: 'Binary' },
|
|
579
|
+
0x8538067: { name: 'Segment', type: 'Container' },
|
|
580
|
+
0x14d9b74: { name: 'SeekHead', type: 'Container' },
|
|
581
|
+
0xdbb: { name: 'Seek', type: 'Container' },
|
|
582
|
+
0x13ab: { name: 'SeekID', type: 'Binary' },
|
|
583
|
+
0x13ac: { name: 'SeekPosition', type: 'Uint' },
|
|
584
|
+
0x549a966: { name: 'Info', type: 'Container' },
|
|
585
|
+
0x33a4: { name: 'SegmentUID', type: 'Binary' },
|
|
586
|
+
0x3384: { name: 'SegmentFilename', type: 'String' },
|
|
587
|
+
0x1cb923: { name: 'PrevUID', type: 'Binary' },
|
|
588
|
+
0x1c83ab: { name: 'PrevFilename', type: 'String' },
|
|
589
|
+
0x1eb923: { name: 'NextUID', type: 'Binary' },
|
|
590
|
+
0x1e83bb: { name: 'NextFilename', type: 'String' },
|
|
591
|
+
0x444: { name: 'SegmentFamily', type: 'Binary' },
|
|
592
|
+
0x2924: { name: 'ChapterTranslate', type: 'Container' },
|
|
593
|
+
0x29fc: { name: 'ChapterTranslateEditionUID', type: 'Uint' },
|
|
594
|
+
0x29bf: { name: 'ChapterTranslateCodec', type: 'Uint' },
|
|
595
|
+
0x29a5: { name: 'ChapterTranslateID', type: 'Binary' },
|
|
596
|
+
0xad7b1: { name: 'TimecodeScale', type: 'Uint' },
|
|
597
|
+
0x489: { name: 'Duration', type: 'Float' },
|
|
598
|
+
0x461: { name: 'DateUTC', type: 'Date' },
|
|
599
|
+
0x3ba9: { name: 'Title', type: 'String' },
|
|
600
|
+
0xd80: { name: 'MuxingApp', type: 'String' },
|
|
601
|
+
0x1741: { name: 'WritingApp', type: 'String' },
|
|
602
|
+
// 0xf43b675: { name: 'Cluster', type: 'Container' },
|
|
603
|
+
0x67: { name: 'Timecode', type: 'Uint' },
|
|
604
|
+
0x1854: { name: 'SilentTracks', type: 'Container' },
|
|
605
|
+
0x18d7: { name: 'SilentTrackNumber', type: 'Uint' },
|
|
606
|
+
0x27: { name: 'Position', type: 'Uint' },
|
|
607
|
+
0x2b: { name: 'PrevSize', type: 'Uint' },
|
|
608
|
+
0x23: { name: 'SimpleBlock', type: 'Binary' },
|
|
609
|
+
0x20: { name: 'BlockGroup', type: 'Container' },
|
|
610
|
+
0x21: { name: 'Block', type: 'Binary' },
|
|
611
|
+
0x22: { name: 'BlockVirtual', type: 'Binary' },
|
|
612
|
+
0x35a1: { name: 'BlockAdditions', type: 'Container' },
|
|
613
|
+
0x26: { name: 'BlockMore', type: 'Container' },
|
|
614
|
+
0x6e: { name: 'BlockAddID', type: 'Uint' },
|
|
615
|
+
0x25: { name: 'BlockAdditional', type: 'Binary' },
|
|
616
|
+
0x1b: { name: 'BlockDuration', type: 'Uint' },
|
|
617
|
+
0x7a: { name: 'ReferencePriority', type: 'Uint' },
|
|
618
|
+
0x7b: { name: 'ReferenceBlock', type: 'Int' },
|
|
619
|
+
0x7d: { name: 'ReferenceVirtual', type: 'Int' },
|
|
620
|
+
0x24: { name: 'CodecState', type: 'Binary' },
|
|
621
|
+
0x35a2: { name: 'DiscardPadding', type: 'Int' },
|
|
622
|
+
0xe: { name: 'Slices', type: 'Container' },
|
|
623
|
+
0x68: { name: 'TimeSlice', type: 'Container' },
|
|
624
|
+
0x4c: { name: 'LaceNumber', type: 'Uint' },
|
|
625
|
+
0x4d: { name: 'FrameNumber', type: 'Uint' },
|
|
626
|
+
0x4b: { name: 'BlockAdditionID', type: 'Uint' },
|
|
627
|
+
0x4e: { name: 'Delay', type: 'Uint' },
|
|
628
|
+
0x4f: { name: 'SliceDuration', type: 'Uint' },
|
|
629
|
+
0x48: { name: 'ReferenceFrame', type: 'Container' },
|
|
630
|
+
0x49: { name: 'ReferenceOffset', type: 'Uint' },
|
|
631
|
+
0x4a: { name: 'ReferenceTimeCode', type: 'Uint' },
|
|
632
|
+
0x2f: { name: 'EncryptedBlock', type: 'Binary' },
|
|
633
|
+
0x654ae6b: { name: 'Tracks', type: 'Container' },
|
|
634
|
+
0x2e: { name: 'TrackEntry', type: 'Container' },
|
|
635
|
+
0x57: { name: 'TrackNumber', type: 'Uint' },
|
|
636
|
+
0x33c5: { name: 'TrackUID', type: 'Uint' },
|
|
637
|
+
0x3: { name: 'TrackType', type: 'Uint' },
|
|
638
|
+
0x39: { name: 'FlagEnabled', type: 'Uint' },
|
|
639
|
+
0x8: { name: 'FlagDefault', type: 'Uint' },
|
|
640
|
+
0x15aa: { name: 'FlagForced', type: 'Uint' },
|
|
641
|
+
0x1c: { name: 'FlagLacing', type: 'Uint' },
|
|
642
|
+
0x2de7: { name: 'MinCache', type: 'Uint' },
|
|
643
|
+
0x2df8: { name: 'MaxCache', type: 'Uint' },
|
|
644
|
+
0x3e383: { name: 'DefaultDuration', type: 'Uint' },
|
|
645
|
+
0x34e7a: { name: 'DefaultDecodedFieldDuration', type: 'Uint' },
|
|
646
|
+
0x3314f: { name: 'TrackTimecodeScale', type: 'Float' },
|
|
647
|
+
0x137f: { name: 'TrackOffset', type: 'Int' },
|
|
648
|
+
0x15ee: { name: 'MaxBlockAdditionID', type: 'Uint' },
|
|
649
|
+
0x136e: { name: 'Name', type: 'String' },
|
|
650
|
+
0x2b59c: { name: 'Language', type: 'String' },
|
|
651
|
+
0x6: { name: 'CodecID', type: 'String' },
|
|
652
|
+
0x23a2: { name: 'CodecPrivate', type: 'Binary' },
|
|
653
|
+
0x58688: { name: 'CodecName', type: 'String' },
|
|
654
|
+
0x3446: { name: 'AttachmentLink', type: 'Uint' },
|
|
655
|
+
0x1a9697: { name: 'CodecSettings', type: 'String' },
|
|
656
|
+
0x1b4040: { name: 'CodecInfoURL', type: 'String' },
|
|
657
|
+
0x6b240: { name: 'CodecDownloadURL', type: 'String' },
|
|
658
|
+
0x2a: { name: 'CodecDecodeAll', type: 'Uint' },
|
|
659
|
+
0x2fab: { name: 'TrackOverlay', type: 'Uint' },
|
|
660
|
+
0x16aa: { name: 'CodecDelay', type: 'Uint' },
|
|
661
|
+
0x16bb: { name: 'SeekPreRoll', type: 'Uint' },
|
|
662
|
+
0x2624: { name: 'TrackTranslate', type: 'Container' },
|
|
663
|
+
0x26fc: { name: 'TrackTranslateEditionUID', type: 'Uint' },
|
|
664
|
+
0x26bf: { name: 'TrackTranslateCodec', type: 'Uint' },
|
|
665
|
+
0x26a5: { name: 'TrackTranslateTrackID', type: 'Binary' },
|
|
666
|
+
0x60: { name: 'Video', type: 'Container' },
|
|
667
|
+
0x1a: { name: 'FlagInterlaced', type: 'Uint' },
|
|
668
|
+
0x13b8: { name: 'StereoMode', type: 'Uint' },
|
|
669
|
+
0x13c0: { name: 'AlphaMode', type: 'Uint' },
|
|
670
|
+
0x13b9: { name: 'OldStereoMode', type: 'Uint' },
|
|
671
|
+
0x30: { name: 'PixelWidth', type: 'Uint' },
|
|
672
|
+
0x3a: { name: 'PixelHeight', type: 'Uint' },
|
|
673
|
+
0x14aa: { name: 'PixelCropBottom', type: 'Uint' },
|
|
674
|
+
0x14bb: { name: 'PixelCropTop', type: 'Uint' },
|
|
675
|
+
0x14cc: { name: 'PixelCropLeft', type: 'Uint' },
|
|
676
|
+
0x14dd: { name: 'PixelCropRight', type: 'Uint' },
|
|
677
|
+
0x14b0: { name: 'DisplayWidth', type: 'Uint' },
|
|
678
|
+
0x14ba: { name: 'DisplayHeight', type: 'Uint' },
|
|
679
|
+
0x14b2: { name: 'DisplayUnit', type: 'Uint' },
|
|
680
|
+
0x14b3: { name: 'AspectRatioType', type: 'Uint' },
|
|
681
|
+
0xeb524: { name: 'ColourSpace', type: 'Binary' },
|
|
682
|
+
0xfb523: { name: 'GammaValue', type: 'Float' },
|
|
683
|
+
0x383e3: { name: 'FrameRate', type: 'Float' },
|
|
684
|
+
0x61: { name: 'Audio', type: 'Container' },
|
|
685
|
+
0x35: { name: 'SamplingFrequency', type: 'Float' },
|
|
686
|
+
0x38b5: { name: 'OutputSamplingFrequency', type: 'Float' },
|
|
687
|
+
0x1f: { name: 'Channels', type: 'Uint' },
|
|
688
|
+
0x3d7b: { name: 'ChannelPositions', type: 'Binary' },
|
|
689
|
+
0x2264: { name: 'BitDepth', type: 'Uint' },
|
|
690
|
+
0x62: { name: 'TrackOperation', type: 'Container' },
|
|
691
|
+
0x63: { name: 'TrackCombinePlanes', type: 'Container' },
|
|
692
|
+
0x64: { name: 'TrackPlane', type: 'Container' },
|
|
693
|
+
0x65: { name: 'TrackPlaneUID', type: 'Uint' },
|
|
694
|
+
0x66: { name: 'TrackPlaneType', type: 'Uint' },
|
|
695
|
+
0x69: { name: 'TrackJoinBlocks', type: 'Container' },
|
|
696
|
+
0x6d: { name: 'TrackJoinUID', type: 'Uint' },
|
|
697
|
+
0x40: { name: 'TrickTrackUID', type: 'Uint' },
|
|
698
|
+
0x41: { name: 'TrickTrackSegmentUID', type: 'Binary' },
|
|
699
|
+
0x46: { name: 'TrickTrackFlag', type: 'Uint' },
|
|
700
|
+
0x47: { name: 'TrickMasterTrackUID', type: 'Uint' },
|
|
701
|
+
0x44: { name: 'TrickMasterTrackSegmentUID', type: 'Binary' },
|
|
702
|
+
0x2d80: { name: 'ContentEncodings', type: 'Container' },
|
|
703
|
+
0x2240: { name: 'ContentEncoding', type: 'Container' },
|
|
704
|
+
0x1031: { name: 'ContentEncodingOrder', type: 'Uint' },
|
|
705
|
+
0x1032: { name: 'ContentEncodingScope', type: 'Uint' },
|
|
706
|
+
0x1033: { name: 'ContentEncodingType', type: 'Uint' },
|
|
707
|
+
0x1034: { name: 'ContentCompression', type: 'Container' },
|
|
708
|
+
0x254: { name: 'ContentCompAlgo', type: 'Uint' },
|
|
709
|
+
0x255: { name: 'ContentCompSettings', type: 'Binary' },
|
|
710
|
+
0x1035: { name: 'ContentEncryption', type: 'Container' },
|
|
711
|
+
0x7e1: { name: 'ContentEncAlgo', type: 'Uint' },
|
|
712
|
+
0x7e2: { name: 'ContentEncKeyID', type: 'Binary' },
|
|
713
|
+
0x7e3: { name: 'ContentSignature', type: 'Binary' },
|
|
714
|
+
0x7e4: { name: 'ContentSigKeyID', type: 'Binary' },
|
|
715
|
+
0x7e5: { name: 'ContentSigAlgo', type: 'Uint' },
|
|
716
|
+
0x7e6: { name: 'ContentSigHashAlgo', type: 'Uint' },
|
|
717
|
+
0xc53bb6b: { name: 'Cues', type: 'Container' },
|
|
718
|
+
0x3b: { name: 'CuePoint', type: 'Container' },
|
|
719
|
+
0x33: { name: 'CueTime', type: 'Uint' },
|
|
720
|
+
0x37: { name: 'CueTrackPositions', type: 'Container' },
|
|
721
|
+
0x77: { name: 'CueTrack', type: 'Uint' },
|
|
722
|
+
0x71: { name: 'CueClusterPosition', type: 'Uint' },
|
|
723
|
+
0x70: { name: 'CueRelativePosition', type: 'Uint' },
|
|
724
|
+
0x32: { name: 'CueDuration', type: 'Uint' },
|
|
725
|
+
0x1378: { name: 'CueBlockNumber', type: 'Uint' },
|
|
726
|
+
0x6a: { name: 'CueCodecState', type: 'Uint' },
|
|
727
|
+
0x5b: { name: 'CueReference', type: 'Container' },
|
|
728
|
+
0x16: { name: 'CueRefTime', type: 'Uint' },
|
|
729
|
+
0x17: { name: 'CueRefCluster', type: 'Uint' },
|
|
730
|
+
0x135f: { name: 'CueRefNumber', type: 'Uint' },
|
|
731
|
+
0x6b: { name: 'CueRefCodecState', type: 'Uint' },
|
|
732
|
+
0x941a469: { name: 'Attachments', type: 'Container' },
|
|
733
|
+
0x21a7: { name: 'AttachedFile', type: 'Container' },
|
|
734
|
+
0x67e: { name: 'FileDescription', type: 'String' },
|
|
735
|
+
0x66e: { name: 'FileName', type: 'String' },
|
|
736
|
+
0x660: { name: 'FileMimeType', type: 'String' },
|
|
737
|
+
0x65c: { name: 'FileData', type: 'Binary' },
|
|
738
|
+
0x6ae: { name: 'FileUID', type: 'Uint' },
|
|
739
|
+
0x675: { name: 'FileReferral', type: 'Binary' },
|
|
740
|
+
0x661: { name: 'FileUsedStartTime', type: 'Uint' },
|
|
741
|
+
0x662: { name: 'FileUsedEndTime', type: 'Uint' },
|
|
742
|
+
0x43a770: { name: 'Chapters', type: 'Container' },
|
|
743
|
+
0x5b9: { name: 'EditionEntry', type: 'Container' },
|
|
744
|
+
0x5bc: { name: 'EditionUID', type: 'Uint' },
|
|
745
|
+
0x5bd: { name: 'EditionFlagHidden', type: 'Uint' },
|
|
746
|
+
0x5db: { name: 'EditionFlagDefault', type: 'Uint' },
|
|
747
|
+
0x5dd: { name: 'EditionFlagOrdered', type: 'Uint' },
|
|
748
|
+
0x36: { name: 'ChapterAtom', type: 'Container' },
|
|
749
|
+
0x33c4: { name: 'ChapterUID', type: 'Uint' },
|
|
750
|
+
0x1654: { name: 'ChapterStringUID', type: 'String' },
|
|
751
|
+
0x11: { name: 'ChapterTimeStart', type: 'Uint' },
|
|
752
|
+
0x12: { name: 'ChapterTimeEnd', type: 'Uint' },
|
|
753
|
+
0x18: { name: 'ChapterFlagHidden', type: 'Uint' },
|
|
754
|
+
0x598: { name: 'ChapterFlagEnabled', type: 'Uint' },
|
|
755
|
+
0x2e67: { name: 'ChapterSegmentUID', type: 'Binary' },
|
|
756
|
+
0x2ebc: { name: 'ChapterSegmentEditionUID', type: 'Uint' },
|
|
757
|
+
0x23c3: { name: 'ChapterPhysicalEquiv', type: 'Uint' },
|
|
758
|
+
0xf: { name: 'ChapterTrack', type: 'Container' },
|
|
759
|
+
0x9: { name: 'ChapterTrackNumber', type: 'Uint' },
|
|
760
|
+
0x0: { name: 'ChapterDisplay', type: 'Container' },
|
|
761
|
+
0x5: { name: 'ChapString', type: 'String' },
|
|
762
|
+
0x37c: { name: 'ChapLanguage', type: 'String' },
|
|
763
|
+
0x37e: { name: 'ChapCountry', type: 'String' },
|
|
764
|
+
0x2944: { name: 'ChapProcess', type: 'Container' },
|
|
765
|
+
0x2955: { name: 'ChapProcessCodecID', type: 'Uint' },
|
|
766
|
+
0x50d: { name: 'ChapProcessPrivate', type: 'Binary' },
|
|
767
|
+
0x2911: { name: 'ChapProcessCommand', type: 'Container' },
|
|
768
|
+
0x2922: { name: 'ChapProcessTime', type: 'Uint' },
|
|
769
|
+
0x2933: { name: 'ChapProcessData', type: 'Binary' },
|
|
770
|
+
0x254c367: { name: 'Tags', type: 'Container' },
|
|
771
|
+
0x3373: { name: 'Tag', type: 'Container' },
|
|
772
|
+
0x23c0: { name: 'Targets', type: 'Container' },
|
|
773
|
+
0x28ca: { name: 'TargetTypeValue', type: 'Uint' },
|
|
774
|
+
0x23ca: { name: 'TargetType', type: 'String' },
|
|
775
|
+
0x23c5: { name: 'TagTrackUID', type: 'Uint' },
|
|
776
|
+
0x23c9: { name: 'TagEditionUID', type: 'Uint' },
|
|
777
|
+
0x23c4: { name: 'TagChapterUID', type: 'Uint' },
|
|
778
|
+
0x23c6: { name: 'TagAttachmentUID', type: 'Uint' },
|
|
779
|
+
0x27c8: { name: 'SimpleTag', type: 'Container' },
|
|
780
|
+
0x5a3: { name: 'TagName', type: 'String' },
|
|
781
|
+
0x47a: { name: 'TagLanguage', type: 'String' },
|
|
782
|
+
0x484: { name: 'TagDefault', type: 'Uint' },
|
|
783
|
+
0x487: { name: 'TagString', type: 'String' },
|
|
784
|
+
0x485: { name: 'TagBinary', type: 'Binary' }
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
function doInherit(newClass, baseClass) {
|
|
788
|
+
newClass.prototype = Object.create(baseClass.prototype);
|
|
789
|
+
newClass.prototype.constructor = newClass;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
function WebmBase(name, type) {
|
|
793
|
+
this.name = name || 'Unknown';
|
|
794
|
+
this.type = type || 'Unknown';
|
|
795
|
+
}
|
|
796
|
+
WebmBase.prototype.updateBySource = function() { };
|
|
797
|
+
WebmBase.prototype.setSource = function(source) {
|
|
798
|
+
this.source = source;
|
|
799
|
+
this.updateBySource();
|
|
800
|
+
};
|
|
801
|
+
WebmBase.prototype.updateByData = function() { };
|
|
802
|
+
WebmBase.prototype.setData = function(data) {
|
|
803
|
+
this.data = data;
|
|
804
|
+
this.updateByData();
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
function WebmUint(name, type) {
|
|
808
|
+
WebmBase.call(this, name, type || 'Uint');
|
|
809
|
+
}
|
|
810
|
+
doInherit(WebmUint, WebmBase);
|
|
811
|
+
function padHex(hex) {
|
|
812
|
+
return hex.length % 2 === 1 ? '0' + hex : hex;
|
|
813
|
+
}
|
|
814
|
+
WebmUint.prototype.updateBySource = function() {
|
|
815
|
+
// use hex representation of a number instead of number value
|
|
816
|
+
this.data = '';
|
|
817
|
+
for (var i = 0; i < this.source.length; i++) {
|
|
818
|
+
var hex = this.source[i].toString(16);
|
|
819
|
+
this.data += padHex(hex);
|
|
820
|
+
}
|
|
821
|
+
};
|
|
822
|
+
WebmUint.prototype.updateByData = function() {
|
|
823
|
+
var length = this.data.length / 2;
|
|
824
|
+
this.source = new Uint8Array(length);
|
|
825
|
+
for (var i = 0; i < length; i++) {
|
|
826
|
+
var hex = this.data.substr(i * 2, 2);
|
|
827
|
+
this.source[i] = parseInt(hex, 16);
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
WebmUint.prototype.getValue = function() {
|
|
831
|
+
return parseInt(this.data, 16);
|
|
832
|
+
};
|
|
833
|
+
WebmUint.prototype.setValue = function(value) {
|
|
834
|
+
this.setData(padHex(value.toString(16)));
|
|
835
|
+
};
|
|
836
|
+
|
|
837
|
+
function WebmFloat(name, type) {
|
|
838
|
+
WebmBase.call(this, name, type || 'Float');
|
|
839
|
+
}
|
|
840
|
+
doInherit(WebmFloat, WebmBase);
|
|
841
|
+
WebmFloat.prototype.getFloatArrayType = function() {
|
|
842
|
+
return this.source && this.source.length === 4 ? Float32Array : Float64Array;
|
|
843
|
+
};
|
|
844
|
+
WebmFloat.prototype.updateBySource = function() {
|
|
845
|
+
var byteArray = this.source.reverse();
|
|
846
|
+
var floatArrayType = this.getFloatArrayType();
|
|
847
|
+
var floatArray = new floatArrayType(byteArray.buffer);
|
|
848
|
+
this.data = floatArray[0];
|
|
849
|
+
};
|
|
850
|
+
WebmFloat.prototype.updateByData = function() {
|
|
851
|
+
var floatArrayType = this.getFloatArrayType();
|
|
852
|
+
var floatArray = new floatArrayType([ this.data ]);
|
|
853
|
+
var byteArray = new Uint8Array(floatArray.buffer);
|
|
854
|
+
this.source = byteArray.reverse();
|
|
855
|
+
};
|
|
856
|
+
WebmFloat.prototype.getValue = function() {
|
|
857
|
+
return this.data;
|
|
858
|
+
};
|
|
859
|
+
WebmFloat.prototype.setValue = function(value) {
|
|
860
|
+
this.setData(value);
|
|
861
|
+
};
|
|
862
|
+
|
|
863
|
+
function WebmContainer(name, type) {
|
|
864
|
+
WebmBase.call(this, name, type || 'Container');
|
|
865
|
+
}
|
|
866
|
+
doInherit(WebmContainer, WebmBase);
|
|
867
|
+
WebmContainer.prototype.readByte = function() {
|
|
868
|
+
return this.source[this.offset++];
|
|
869
|
+
};
|
|
870
|
+
WebmContainer.prototype.readUint = function() {
|
|
871
|
+
var firstByte = this.readByte();
|
|
872
|
+
var bytes = 8 - firstByte.toString(2).length;
|
|
873
|
+
var value = firstByte - (1 << (7 - bytes));
|
|
874
|
+
for (var i = 0; i < bytes; i++) {
|
|
875
|
+
// don't use bit operators to support x86
|
|
876
|
+
value *= 256;
|
|
877
|
+
value += this.readByte();
|
|
878
|
+
}
|
|
879
|
+
return value;
|
|
880
|
+
};
|
|
881
|
+
WebmContainer.prototype.updateBySource = function() {
|
|
882
|
+
this.data = [];
|
|
883
|
+
for (this.offset = 0; this.offset < this.source.length; this.offset = end) {
|
|
884
|
+
var id = this.readUint();
|
|
885
|
+
var len = this.readUint();
|
|
886
|
+
var end = Math.min(this.offset + len, this.source.length);
|
|
887
|
+
var data = this.source.slice(this.offset, end);
|
|
888
|
+
|
|
889
|
+
var info = sections[id] || { name: 'Unknown', type: 'Unknown' };
|
|
890
|
+
var ctr = WebmBase;
|
|
891
|
+
switch (info.type) {
|
|
892
|
+
case 'Container':
|
|
893
|
+
ctr = WebmContainer;
|
|
894
|
+
break;
|
|
895
|
+
case 'Uint':
|
|
896
|
+
ctr = WebmUint;
|
|
897
|
+
break;
|
|
898
|
+
case 'Float':
|
|
899
|
+
ctr = WebmFloat;
|
|
900
|
+
break;
|
|
901
|
+
}
|
|
902
|
+
var section = new ctr(info.name, info.type);
|
|
903
|
+
section.setSource(data);
|
|
904
|
+
this.data.push({
|
|
905
|
+
id: id,
|
|
906
|
+
idHex: id.toString(16),
|
|
907
|
+
data: section
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
WebmContainer.prototype.writeUint = function(x, draft) {
|
|
912
|
+
for (var bytes = 1, flag = 0x80; x >= flag && bytes < 8; bytes++, flag *= 0x80) { }
|
|
913
|
+
|
|
914
|
+
if (!draft) {
|
|
915
|
+
var value = flag + x;
|
|
916
|
+
for (var i = bytes - 1; i >= 0; i--) {
|
|
917
|
+
// don't use bit operators to support x86
|
|
918
|
+
var c = value % 256;
|
|
919
|
+
this.source[this.offset + i] = c;
|
|
920
|
+
value = (value - c) / 256;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
this.offset += bytes;
|
|
925
|
+
};
|
|
926
|
+
WebmContainer.prototype.writeSections = function(draft) {
|
|
927
|
+
this.offset = 0;
|
|
928
|
+
for (var i = 0; i < this.data.length; i++) {
|
|
929
|
+
var section = this.data[i],
|
|
930
|
+
content = section.data.source,
|
|
931
|
+
contentLength = content.length;
|
|
932
|
+
this.writeUint(section.id, draft);
|
|
933
|
+
this.writeUint(contentLength, draft);
|
|
934
|
+
if (!draft) {
|
|
935
|
+
this.source.set(content, this.offset);
|
|
936
|
+
}
|
|
937
|
+
this.offset += contentLength;
|
|
938
|
+
}
|
|
939
|
+
return this.offset;
|
|
940
|
+
};
|
|
941
|
+
WebmContainer.prototype.updateByData = function() {
|
|
942
|
+
// run without accessing this.source to determine total length - need to know it to create Uint8Array
|
|
943
|
+
var length = this.writeSections('draft');
|
|
944
|
+
this.source = new Uint8Array(length);
|
|
945
|
+
// now really write data
|
|
946
|
+
this.writeSections();
|
|
947
|
+
};
|
|
948
|
+
WebmContainer.prototype.getSectionById = function(id) {
|
|
949
|
+
for (var i = 0; i < this.data.length; i++) {
|
|
950
|
+
var section = this.data[i];
|
|
951
|
+
if (section.id === id) {
|
|
952
|
+
return section.data;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
return null;
|
|
956
|
+
};
|
|
957
|
+
|
|
958
|
+
function WebmFile(source) {
|
|
959
|
+
WebmContainer.call(this, 'File', 'File');
|
|
960
|
+
this.setSource(source);
|
|
961
|
+
}
|
|
962
|
+
doInherit(WebmFile, WebmContainer);
|
|
963
|
+
WebmFile.prototype.fixDuration = function(duration, options) {
|
|
964
|
+
var logger = options && options.logger;
|
|
965
|
+
if (logger === undefined) {
|
|
966
|
+
logger = function(message) {
|
|
967
|
+
console.log(message);
|
|
968
|
+
};
|
|
969
|
+
} else if (!logger) {
|
|
970
|
+
logger = function() { };
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
var segmentSection = this.getSectionById(0x8538067);
|
|
974
|
+
if (!segmentSection) {
|
|
975
|
+
logger('[fix-webm-duration] Segment section is missing');
|
|
976
|
+
return false;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
var infoSection = segmentSection.getSectionById(0x549a966);
|
|
980
|
+
if (!infoSection) {
|
|
981
|
+
logger('[fix-webm-duration] Info section is missing');
|
|
982
|
+
return false;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
var timeScaleSection = infoSection.getSectionById(0xad7b1);
|
|
986
|
+
if (!timeScaleSection) {
|
|
987
|
+
logger('[fix-webm-duration] TimecodeScale section is missing');
|
|
988
|
+
return false;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
var durationSection = infoSection.getSectionById(0x489);
|
|
992
|
+
if (durationSection) {
|
|
993
|
+
if (durationSection.getValue() <= 0) {
|
|
994
|
+
logger(`[fix-webm-duration] Duration section is present, but the value is ${durationSection.getValue()}`);
|
|
995
|
+
durationSection.setValue(duration);
|
|
996
|
+
} else {
|
|
997
|
+
logger(`[fix-webm-duration] Duration section is present, and the value is ${durationSection.getValue()}`);
|
|
998
|
+
return false;
|
|
999
|
+
}
|
|
1000
|
+
} else {
|
|
1001
|
+
logger('[fix-webm-duration] Duration section is missing');
|
|
1002
|
+
// append Duration section
|
|
1003
|
+
durationSection = new WebmFloat('Duration', 'Float');
|
|
1004
|
+
durationSection.setValue(duration);
|
|
1005
|
+
infoSection.data.push({
|
|
1006
|
+
id: 0x489,
|
|
1007
|
+
data: durationSection
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// set default time scale to 1 millisecond (1000000 nanoseconds)
|
|
1012
|
+
timeScaleSection.setValue(1000000);
|
|
1013
|
+
infoSection.updateByData();
|
|
1014
|
+
segmentSection.updateByData();
|
|
1015
|
+
this.updateByData();
|
|
1016
|
+
|
|
1017
|
+
return true;
|
|
1018
|
+
};
|
|
1019
|
+
WebmFile.prototype.toBlob = function(mimeType) {
|
|
1020
|
+
return new Blob([ this.source.buffer ], { type: mimeType || 'video/webm' });
|
|
1021
|
+
};
|
|
1022
|
+
|
|
1023
|
+
function fixWebmDuration(blob, duration, callback, options) {
|
|
1024
|
+
// The callback may be omitted - then the third argument is options
|
|
1025
|
+
if (typeof callback === "object") {
|
|
1026
|
+
options = callback;
|
|
1027
|
+
callback = undefined;
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
if (!callback) {
|
|
1031
|
+
return new Promise(function(resolve) {
|
|
1032
|
+
fixWebmDuration(blob, duration, resolve, options);
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
try {
|
|
1037
|
+
var reader = new FileReader();
|
|
1038
|
+
reader.onloadend = function() {
|
|
1039
|
+
try {
|
|
1040
|
+
var file = new WebmFile(new Uint8Array(reader.result));
|
|
1041
|
+
if (file.fixDuration(duration, options)) {
|
|
1042
|
+
blob = file.toBlob(blob.type);
|
|
1043
|
+
}
|
|
1044
|
+
} catch (ex) {
|
|
1045
|
+
// ignore
|
|
1046
|
+
}
|
|
1047
|
+
callback(blob);
|
|
1048
|
+
};
|
|
1049
|
+
reader.readAsArrayBuffer(blob);
|
|
1050
|
+
} catch (ex) {
|
|
1051
|
+
callback(blob);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// Support AMD import default
|
|
1056
|
+
fixWebmDuration.default = fixWebmDuration;
|
|
1057
|
+
|
|
1058
|
+
return fixWebmDuration;
|
|
1059
|
+
});
|
|
1060
|
+
} (fixWebmDuration));
|
|
1061
|
+
return fixWebmDuration.exports;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
var fixWebmDurationExports = requireFixWebmDuration();
|
|
1065
|
+
var ysFixWebmDuration = /*@__PURE__*/getDefaultExportFromCjs(fixWebmDurationExports);
|
|
1066
|
+
|
|
1067
|
+
class ProcessVideoComponent extends HTMLElement {
|
|
1068
|
+
constructor() {
|
|
1069
|
+
super();
|
|
1070
|
+
this.apiKey = null;
|
|
1071
|
+
this.previewStream = null;
|
|
1072
|
+
this.recordedChunks = [];
|
|
1073
|
+
this.mediaRecorder = null;
|
|
1074
|
+
this.videoFile = null;
|
|
1075
|
+
this.startTime = 0;
|
|
1076
|
+
this.timerInterval = null;
|
|
1077
|
+
this.recordingTimeout = null;
|
|
1078
|
+
this.errorState = null;
|
|
1079
|
+
this.timeLimit = 30;
|
|
1080
|
+
this.phrase = this.generateDefaultPhrase();
|
|
1081
|
+
// Attach shadow DOM and initialize UI
|
|
1082
|
+
this.attachShadow({ mode: 'open' });
|
|
1083
|
+
this.apiKey = this.getAttribute('api-key');
|
|
1084
|
+
this.initializeSDK();
|
|
1085
|
+
this.initializeUI();
|
|
1086
|
+
}
|
|
1087
|
+
initializeSDK() {
|
|
1088
|
+
if (this.apiKey) {
|
|
1089
|
+
this.sdk = new BiometrySDK(this.apiKey);
|
|
1090
|
+
}
|
|
1091
|
+
else {
|
|
1092
|
+
this.toggleState('error');
|
|
1093
|
+
console.error('API key is required to initialize the SDK.');
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
connectedCallback() {
|
|
1097
|
+
if (this.apiKey) {
|
|
1098
|
+
this.initializeSDK();
|
|
1099
|
+
}
|
|
1100
|
+
else {
|
|
1101
|
+
console.error('API key is required.');
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
disconnectedCallback() {
|
|
1105
|
+
this.stopRecording();
|
|
1106
|
+
if (this.previewStream) {
|
|
1107
|
+
this.previewStream.getTracks().forEach(track => track.stop());
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
1111
|
+
if (name === 'api-key' && newValue !== oldValue) {
|
|
1112
|
+
this.apiKey = newValue;
|
|
1113
|
+
this.initializeSDK();
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
generateDefaultPhrase() {
|
|
1117
|
+
return Math.random().toString().slice(2, 10); // 8-digit random phrase
|
|
1118
|
+
}
|
|
1119
|
+
initializeUI() {
|
|
1120
|
+
const phraseDisplay = this.phrase
|
|
1121
|
+
.split("")
|
|
1122
|
+
.map((digit) => `<span class="digit">${digit}</span>`)
|
|
1123
|
+
.join(" ");
|
|
1124
|
+
this.shadowRoot.innerHTML = `
|
|
1125
|
+
<style>
|
|
1126
|
+
:host {
|
|
1127
|
+
display: block;
|
|
1128
|
+
font-family: Arial, sans-serif;
|
|
1129
|
+
--primary-color: #007bff;
|
|
1130
|
+
--secondary-color: #6c757d;
|
|
1131
|
+
--button-bg: var(--primary-color);
|
|
1132
|
+
--button-text-color: #fff;
|
|
1133
|
+
--input-border-color: var(--secondary-color);
|
|
1134
|
+
--input-focus-border-color: var(--primary-color);
|
|
1135
|
+
--spacing: 16px;
|
|
1136
|
+
--button-padding: 10px 20px;
|
|
1137
|
+
--border-radius: 4px;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
.container {
|
|
1141
|
+
display: flex;
|
|
1142
|
+
flex-direction: column;
|
|
1143
|
+
align-items: center;
|
|
1144
|
+
justify-content: center;
|
|
1145
|
+
gap: var(--spacing);
|
|
1146
|
+
padding: var(--spacing);
|
|
1147
|
+
max-width: 500px;
|
|
1148
|
+
margin: 0 auto;
|
|
1149
|
+
text-align: center;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
.video-wrapper {
|
|
1153
|
+
position: relative;
|
|
1154
|
+
display: inline-block;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
#timer-overlay {
|
|
1158
|
+
position: absolute;
|
|
1159
|
+
top: 10px;
|
|
1160
|
+
left: 10px;
|
|
1161
|
+
background-color: rgba(0, 0, 0, 0.7);
|
|
1162
|
+
color: white;
|
|
1163
|
+
padding: 5px 10px;
|
|
1164
|
+
border-radius: 4px;
|
|
1165
|
+
font-family: Arial, sans-serif;
|
|
1166
|
+
font-size: 14px;
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
video {
|
|
1170
|
+
max-width: 100%;
|
|
1171
|
+
border-radius: var(--border-radius);
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
input[type="text"], input[type="file"] {
|
|
1175
|
+
padding: var(--button-padding);
|
|
1176
|
+
border: 1px solid var(--input-border-color);
|
|
1177
|
+
border-radius: var(--border-radius);
|
|
1178
|
+
width: 100%;
|
|
1179
|
+
max-width: 100%;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
input[type="text"]:focus, input[type="file"]:focus {
|
|
1183
|
+
outline: none;
|
|
1184
|
+
border-color: var(--input-focus-border-color);
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
.hidden {
|
|
1188
|
+
display: none;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
.phrase-display {
|
|
1192
|
+
font-size: 24px;
|
|
1193
|
+
font-weight: bold;
|
|
1194
|
+
display: flex;
|
|
1195
|
+
gap: 8px;
|
|
1196
|
+
justify-content: center;
|
|
1197
|
+
}
|
|
1198
|
+
.digit {
|
|
1199
|
+
padding: 4px;
|
|
1200
|
+
border: 1px solid #ccc;
|
|
1201
|
+
border-radius: 4px;
|
|
1202
|
+
text-align: center;
|
|
1203
|
+
width: 24px;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
</style>
|
|
1207
|
+
<div class="container">
|
|
1208
|
+
<slot name="video">
|
|
1209
|
+
<div class="video-wrapper">
|
|
1210
|
+
<video id="video-preview" muted autoplay></video>
|
|
1211
|
+
<div id="timer-overlay" class="hidden">00:00</div>
|
|
1212
|
+
</div>
|
|
1213
|
+
</slot>
|
|
1214
|
+
<slot name="phrase-display">
|
|
1215
|
+
<div class="phrase-display">
|
|
1216
|
+
${phraseDisplay}
|
|
1217
|
+
</div>
|
|
1218
|
+
</slot>
|
|
1219
|
+
<slot name="record-button">
|
|
1220
|
+
<button id="record-button">Start Recording</button>
|
|
1221
|
+
</slot>
|
|
1222
|
+
<slot name="stop-button">
|
|
1223
|
+
<button id="stop-button" disabled>Stop Recording</button>
|
|
1224
|
+
</slot>
|
|
1225
|
+
<slot name="file-input">
|
|
1226
|
+
<input type="file" accept="video/*" id="file-input" />
|
|
1227
|
+
</slot>
|
|
1228
|
+
<slot name="submit-button">
|
|
1229
|
+
<button id="submit-button">Submit Video</button>
|
|
1230
|
+
</slot>
|
|
1231
|
+
<slot name="loading">
|
|
1232
|
+
<div class="message">Loading...</div>
|
|
1233
|
+
</slot>
|
|
1234
|
+
<slot name="error">
|
|
1235
|
+
<div class="message error">An error occurred</div>
|
|
1236
|
+
</slot>
|
|
1237
|
+
<slot name="success">
|
|
1238
|
+
<div class="message success">Video submitted successfully!</div>
|
|
1239
|
+
</slot>
|
|
1240
|
+
</div>
|
|
1241
|
+
`;
|
|
1242
|
+
this.attachSlotListeners();
|
|
1243
|
+
this.setupPreview();
|
|
1244
|
+
this.toggleState(null);
|
|
1245
|
+
}
|
|
1246
|
+
attachSlotListeners() {
|
|
1247
|
+
const videoSlot = this.shadowRoot.querySelector('slot[name="video"]');
|
|
1248
|
+
const recordButtonSlot = this.shadowRoot.querySelector('slot[name="record-button"]');
|
|
1249
|
+
const stopButtonSlot = this.shadowRoot.querySelector('slot[name="stop-button"]');
|
|
1250
|
+
const fileInputSlot = this.shadowRoot.querySelector('slot[name="file-input"]');
|
|
1251
|
+
const submitButtonSlot = this.shadowRoot.querySelector('slot[name="submit-button"]');
|
|
1252
|
+
this.videoElement = this.getSlotElement(videoSlot, '#video-preview', HTMLVideoElement);
|
|
1253
|
+
this.recordButton = this.getSlotElement(recordButtonSlot, '#record-button', HTMLButtonElement);
|
|
1254
|
+
this.stopButton = this.getSlotElement(stopButtonSlot, '#stop-button', HTMLButtonElement);
|
|
1255
|
+
this.fileInput = this.getSlotElement(fileInputSlot, '#file-input', HTMLInputElement);
|
|
1256
|
+
this.submitButton = this.getSlotElement(submitButtonSlot, '#submit-button', HTMLButtonElement);
|
|
1257
|
+
if (this.fileInput) {
|
|
1258
|
+
this.fileInput.addEventListener('change', (e) => this.handleFileUpload(e));
|
|
1259
|
+
}
|
|
1260
|
+
if (this.recordButton) {
|
|
1261
|
+
this.recordButton.addEventListener("click", () => this.startRecording());
|
|
1262
|
+
}
|
|
1263
|
+
if (this.stopButton) {
|
|
1264
|
+
this.stopButton.addEventListener("click", () => this.stopRecording());
|
|
1265
|
+
}
|
|
1266
|
+
if (this.submitButton) {
|
|
1267
|
+
this.submitButton.addEventListener("click", () => this.handleSubmit());
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
getSlotElement(slot, fallbackSelector, elementType) {
|
|
1271
|
+
const assignedElements = slot.assignedElements();
|
|
1272
|
+
return (assignedElements.length > 0 ? assignedElements[0] : null) || this.shadowRoot.querySelector(fallbackSelector);
|
|
1273
|
+
}
|
|
1274
|
+
replaceSlotContent(slotName, content) {
|
|
1275
|
+
const slot = this.shadowRoot.querySelector(`slot[name="${slotName}"]`);
|
|
1276
|
+
if (slot) {
|
|
1277
|
+
if (typeof content === 'string') {
|
|
1278
|
+
slot.innerHTML = content;
|
|
1279
|
+
}
|
|
1280
|
+
else if (content instanceof HTMLElement) {
|
|
1281
|
+
slot.innerHTML = '';
|
|
1282
|
+
slot.appendChild(content);
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
removeSlotListener(slotName, event, callback) {
|
|
1287
|
+
const slot = this.shadowRoot.querySelector(`slot[name="${slotName}"]`);
|
|
1288
|
+
if (slot) {
|
|
1289
|
+
const assignedNodes = slot.assignedElements();
|
|
1290
|
+
assignedNodes.forEach((node) => {
|
|
1291
|
+
node.removeEventListener(event, callback);
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
toggleState(state) {
|
|
1296
|
+
const states = ['loading', 'success', 'error'];
|
|
1297
|
+
states.forEach((slotName) => {
|
|
1298
|
+
const slot = this.shadowRoot.querySelector(`slot[name="${slotName}"]`);
|
|
1299
|
+
if (slot) {
|
|
1300
|
+
slot.style.display = slotName === state ? 'block' : 'none';
|
|
1301
|
+
}
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
convertPhraseToWords(phrase) {
|
|
1305
|
+
const digitWords = [
|
|
1306
|
+
"zero", "one", "two", "three", "four",
|
|
1307
|
+
"five", "six", "seven", "eight", "nine"
|
|
1308
|
+
];
|
|
1309
|
+
return phrase
|
|
1310
|
+
.split("")
|
|
1311
|
+
.map((digit) => digitWords[parseInt(digit, 10)])
|
|
1312
|
+
.join(" ");
|
|
1313
|
+
}
|
|
1314
|
+
async setupPreview() {
|
|
1315
|
+
try {
|
|
1316
|
+
const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
|
|
1317
|
+
this.previewStream = stream;
|
|
1318
|
+
this.videoElement.srcObject = stream;
|
|
1319
|
+
this.videoElement.controls = false;
|
|
1320
|
+
this.videoElement.play();
|
|
1321
|
+
}
|
|
1322
|
+
catch (error) {
|
|
1323
|
+
this.toggleState('error');
|
|
1324
|
+
console.error('Error setting up video preview:', error);
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
async startTimer() {
|
|
1328
|
+
const timerOverlay = this.shadowRoot.querySelector('#timer-overlay');
|
|
1329
|
+
timerOverlay.textContent = '00:00';
|
|
1330
|
+
timerOverlay.classList.remove('hidden');
|
|
1331
|
+
let seconds = 0;
|
|
1332
|
+
this.timerInterval = setInterval(() => {
|
|
1333
|
+
seconds++;
|
|
1334
|
+
const minutes = Math.floor(seconds / 60);
|
|
1335
|
+
const remainingSeconds = seconds % 60;
|
|
1336
|
+
timerOverlay.textContent = `${String(minutes).padStart(2, '0')}:${String(remainingSeconds).padStart(2, '0')}`;
|
|
1337
|
+
}, 1000);
|
|
1338
|
+
this.recordingTimeout = setTimeout(() => {
|
|
1339
|
+
this.stopRecording();
|
|
1340
|
+
}, this.timeLimit * 1000);
|
|
1341
|
+
}
|
|
1342
|
+
async stopTimer() {
|
|
1343
|
+
if (this.recordingTimeout) {
|
|
1344
|
+
clearTimeout(this.recordingTimeout);
|
|
1345
|
+
}
|
|
1346
|
+
if (this.timerInterval) {
|
|
1347
|
+
clearInterval(this.timerInterval);
|
|
1348
|
+
this.timerInterval = null;
|
|
1349
|
+
}
|
|
1350
|
+
const timerOverlay = this.shadowRoot.querySelector('#timer-overlay');
|
|
1351
|
+
timerOverlay.classList.add('hidden');
|
|
1352
|
+
}
|
|
1353
|
+
async startRecording() {
|
|
1354
|
+
if (!window.MediaRecorder) {
|
|
1355
|
+
console.error('MediaRecorder API is not supported in this browser');
|
|
1356
|
+
return;
|
|
1357
|
+
}
|
|
1358
|
+
try {
|
|
1359
|
+
if (this.mediaRecorder && this.mediaRecorder.state !== 'inactive') {
|
|
1360
|
+
console.log('Recording already in progress.');
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1363
|
+
if (!this.previewStream) {
|
|
1364
|
+
console.log('Initializing preview stream...');
|
|
1365
|
+
this.previewStream = await navigator.mediaDevices.getUserMedia({
|
|
1366
|
+
video: true,
|
|
1367
|
+
audio: true,
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
this.videoElement.muted = true;
|
|
1371
|
+
this.videoElement.srcObject = this.previewStream;
|
|
1372
|
+
this.videoElement.currentTime = 0;
|
|
1373
|
+
await this.videoElement.play();
|
|
1374
|
+
this.mediaRecorder = new MediaRecorder(this.previewStream);
|
|
1375
|
+
this.recordedChunks = [];
|
|
1376
|
+
this.mediaRecorder.ondataavailable = (event) => {
|
|
1377
|
+
if (event.data.size > 0) {
|
|
1378
|
+
this.recordedChunks.push(event.data);
|
|
1379
|
+
}
|
|
1380
|
+
};
|
|
1381
|
+
this.mediaRecorder.onstop = () => {
|
|
1382
|
+
const duration = Date.now() - this.startTime;
|
|
1383
|
+
const buggyBlob = new Blob(this.recordedChunks, { type: 'video/webm' });
|
|
1384
|
+
ysFixWebmDuration(buggyBlob, duration, { logger: false })
|
|
1385
|
+
.then((fixedBlob) => {
|
|
1386
|
+
this.onStopMediaRecorder(fixedBlob);
|
|
1387
|
+
});
|
|
1388
|
+
};
|
|
1389
|
+
this.mediaRecorder.start();
|
|
1390
|
+
this.startTimer();
|
|
1391
|
+
this.startTime = Date.now();
|
|
1392
|
+
this.recordButton.disabled = true;
|
|
1393
|
+
this.stopButton.disabled = false;
|
|
1394
|
+
this.videoElement.controls = false;
|
|
1395
|
+
}
|
|
1396
|
+
catch (error) {
|
|
1397
|
+
console.error('Error starting video recording:', error);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
stopRecording() {
|
|
1401
|
+
try {
|
|
1402
|
+
if (!this.mediaRecorder || this.mediaRecorder.state === 'inactive') {
|
|
1403
|
+
console.log('No recording in progress.');
|
|
1404
|
+
return;
|
|
1405
|
+
}
|
|
1406
|
+
this.mediaRecorder.stop();
|
|
1407
|
+
if (this.previewStream) {
|
|
1408
|
+
this.previewStream.getTracks().forEach(track => track.stop());
|
|
1409
|
+
}
|
|
1410
|
+
this.videoElement.srcObject = null;
|
|
1411
|
+
this.videoElement.src = '';
|
|
1412
|
+
this.videoElement.controls = false;
|
|
1413
|
+
this.recordButton.disabled = false;
|
|
1414
|
+
this.stopButton.disabled = true;
|
|
1415
|
+
this.mediaRecorder = null;
|
|
1416
|
+
this.recordedChunks = [];
|
|
1417
|
+
this.previewStream = null;
|
|
1418
|
+
}
|
|
1419
|
+
catch (error) {
|
|
1420
|
+
console.error('Error stopping video recording:', error);
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
onStopMediaRecorder(blob) {
|
|
1424
|
+
const videoURL = URL.createObjectURL(blob);
|
|
1425
|
+
this.videoFile = new File([blob], 'recorded_video.webm', { type: 'video/webm' });
|
|
1426
|
+
this.videoElement.src = videoURL;
|
|
1427
|
+
this.videoElement.controls = true;
|
|
1428
|
+
this.videoElement.play();
|
|
1429
|
+
this.videoElement.muted = false;
|
|
1430
|
+
this.stopTimer();
|
|
1431
|
+
// Clean up the object URL when the video loads
|
|
1432
|
+
this.videoElement.onloadeddata = () => {
|
|
1433
|
+
URL.revokeObjectURL(videoURL);
|
|
1434
|
+
};
|
|
1435
|
+
}
|
|
1436
|
+
handleFileUpload(event) {
|
|
1437
|
+
var _a, _b;
|
|
1438
|
+
const file = (_a = event.target.files) === null || _a === undefined ? undefined : _a[0];
|
|
1439
|
+
if ((_b = file === null || file === undefined ? undefined : file.type) === null || _b === undefined ? undefined : _b.startsWith('video/')) {
|
|
1440
|
+
if (file.size > 100 * 1024 * 1024) { // 100MB limit
|
|
1441
|
+
this.toggleState('error');
|
|
1442
|
+
console.error('File size exceeds limit of 100MB');
|
|
1443
|
+
return;
|
|
1444
|
+
}
|
|
1445
|
+
this.videoFile = file;
|
|
1446
|
+
this.videoElement.src = URL.createObjectURL(file);
|
|
1447
|
+
this.videoElement.play();
|
|
1448
|
+
}
|
|
1449
|
+
else {
|
|
1450
|
+
this.toggleState('error');
|
|
1451
|
+
console.error('Please select a valid video file.');
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
async handleSubmit() {
|
|
1455
|
+
if (!this.videoFile) {
|
|
1456
|
+
this.toggleState('error');
|
|
1457
|
+
console.error('No video file to submit.');
|
|
1458
|
+
return;
|
|
1459
|
+
}
|
|
1460
|
+
if (!this.apiKey || !this.userFullname) {
|
|
1461
|
+
this.toggleState('error');
|
|
1462
|
+
console.error('API key and user fullname must be provided.');
|
|
1463
|
+
return;
|
|
1464
|
+
}
|
|
1465
|
+
this.toggleState('loading');
|
|
1466
|
+
try {
|
|
1467
|
+
const phraseInWords = this.convertPhraseToWords(this.phrase);
|
|
1468
|
+
const result = await this.sdk.processVideo(this.videoFile, phraseInWords, this.userFullname);
|
|
1469
|
+
console.log('Response from processVideo:', result);
|
|
1470
|
+
this.toggleState('success');
|
|
1471
|
+
}
|
|
1472
|
+
catch (error) {
|
|
1473
|
+
this.toggleState('error');
|
|
1474
|
+
console.error('Error submitting video:', error);
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
static get observedAttributes() {
|
|
1478
|
+
return ['api-key', 'user-fullname'];
|
|
1479
|
+
}
|
|
1480
|
+
get userFullname() {
|
|
1481
|
+
return this.getAttribute('user-fullname');
|
|
1482
|
+
}
|
|
1483
|
+
set userFullname(value) {
|
|
1484
|
+
if (value) {
|
|
1485
|
+
this.setAttribute('user-fullname', value);
|
|
1486
|
+
}
|
|
1487
|
+
else {
|
|
1488
|
+
this.removeAttribute('user-fullname');
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
get isRecording() {
|
|
1492
|
+
var _a;
|
|
1493
|
+
return ((_a = this.mediaRecorder) === null || _a === undefined ? undefined : _a.state) === 'recording';
|
|
1494
|
+
}
|
|
1495
|
+
get currentPhrase() {
|
|
1496
|
+
return this.phrase;
|
|
1497
|
+
}
|
|
1498
|
+
get videoDuration() {
|
|
1499
|
+
var _a;
|
|
1500
|
+
return ((_a = this.videoElement) === null || _a === undefined ? undefined : _a.duration) || null;
|
|
1501
|
+
}
|
|
1502
|
+
get currentFile() {
|
|
1503
|
+
return this.videoFile;
|
|
1504
|
+
}
|
|
1505
|
+
get currentStream() {
|
|
1506
|
+
return this.previewStream;
|
|
1507
|
+
}
|
|
1508
|
+
set sdkInstance(newSdk) {
|
|
1509
|
+
this.sdk = newSdk;
|
|
1510
|
+
}
|
|
1511
|
+
get videoElementRef() {
|
|
1512
|
+
return this.videoElement;
|
|
1513
|
+
}
|
|
1514
|
+
get fileInputRef() {
|
|
1515
|
+
return this.fileInput;
|
|
1516
|
+
}
|
|
1517
|
+
get recordingTimeLimit() {
|
|
1518
|
+
return this.timeLimit;
|
|
1519
|
+
}
|
|
1520
|
+
set recordingTimeLimit(value) {
|
|
1521
|
+
this.timeLimit = value;
|
|
1522
|
+
if (this.mediaRecorder && this.mediaRecorder.state === 'recording') {
|
|
1523
|
+
if (this.recordingTimeout) {
|
|
1524
|
+
clearTimeout(this.recordingTimeout);
|
|
1525
|
+
}
|
|
1526
|
+
this.recordingTimeout = setTimeout(() => this.stopRecording(), this.timeLimit * 1000);
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
customElements.define('process-video', ProcessVideoComponent);
|
|
1531
|
+
|
|
1532
|
+
export { BiometryEnrollment, BiometrySDK, ProcessVideoComponent };
|