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