@idmission/websdk-core 0.1.0-rc.1 → 0.2.0-rc.1
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/client/IdmissionClient.d.ts +20 -11
- package/dist/client/IdmissionClient.d.ts.map +1 -1
- package/dist/client/additionalDocument.d.ts +9 -0
- package/dist/client/additionalDocument.d.ts.map +1 -1
- package/dist/client/artifacts.d.ts +14 -3
- package/dist/client/artifacts.d.ts.map +1 -1
- package/dist/client/index.d.ts +4 -4
- package/dist/client/index.d.ts.map +1 -1
- package/dist/documentCapture/controller.d.ts +8 -5
- package/dist/documentCapture/controller.d.ts.map +1 -1
- package/dist/documentCapture/controller.js +22 -6
- package/dist/documentCapture/index.d.ts +1 -1
- package/dist/documentCapture/index.d.ts.map +1 -1
- package/dist/documentCapture/index.js +1 -1
- package/dist/documentCapture/state.d.ts +35 -4
- package/dist/documentCapture/state.d.ts.map +1 -1
- package/dist/documentCapture/state.js +27 -4
- package/dist/idCapture/index.d.ts +2 -2
- package/dist/idCapture/index.d.ts.map +1 -1
- package/dist/models/VisionRuntime.d.ts +21 -0
- package/dist/models/VisionRuntime.d.ts.map +1 -1
- package/dist/models/VisionRuntime.js +59 -12
- package/dist/models/providers/litert/runtime.d.ts.map +1 -1
- package/dist/models/providers/litert/runtime.js +63 -7
- package/dist/selfieCapture/controller.d.ts +7 -6
- package/dist/selfieCapture/controller.d.ts.map +1 -1
- package/dist/selfieCapture/index.d.ts +1 -1
- package/dist/selfieCapture/index.d.ts.map +1 -1
- package/dist/selfieCapture/pipeline.d.ts.map +1 -1
- package/dist/selfieCapture/pipeline.js +33 -8
- package/dist/selfieCapture/state.d.ts.map +1 -1
- package/dist/selfieCapture/state.js +20 -4
- package/dist/signature/frameDecode.d.ts +18 -0
- package/dist/signature/frameDecode.d.ts.map +1 -1
- package/dist/signature/frameDecode.js +42 -1
- package/dist/signature/quality.d.ts +11 -0
- package/dist/signature/quality.d.ts.map +1 -1
- package/dist/signature/quality.js +1 -0
- package/dist/signatureCapture/controller.d.ts.map +1 -1
- package/dist/signatureCapture/controller.js +9 -0
- package/dist/signatureCapture/pipeline.d.ts.map +1 -1
- package/dist/signatureCapture/pipeline.js +182 -15
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -2,6 +2,35 @@ import { TRIM_PADDING_START_MS, validateDecodableFrames, } from '../signature/fr
|
|
|
2
2
|
import { evaluateQuality, readDeviceSignals, shouldFireQualityWarning, withFrameDecode, } from '../signature/quality';
|
|
3
3
|
import { warn } from '../utils/logger';
|
|
4
4
|
const DEFAULT_DRAIN = { minWaitMs: 1500, maxWaitMs: 3000, pollIntervalMs: 250 };
|
|
5
|
+
/**
|
|
6
|
+
* How long `start()` waits for the camera's real frame size before recording
|
|
7
|
+
* at the fallback size. Long enough for a phone camera's first frame, short
|
|
8
|
+
* enough that a camera which never delivers one still gets a recording.
|
|
9
|
+
*/
|
|
10
|
+
const VIDEO_DIMENSIONS_TIMEOUT_MS = 3000;
|
|
11
|
+
/** What the output canvas falls back to when the camera reports no size. */
|
|
12
|
+
const FALLBACK_OUTPUT_SIZE = { width: 1280, height: 720 };
|
|
13
|
+
/** The element's own frame size — 0x0 until it has metadata. */
|
|
14
|
+
function readVideoSize(el) {
|
|
15
|
+
return el.videoWidth && el.videoHeight
|
|
16
|
+
? { width: el.videoWidth, height: el.videoHeight }
|
|
17
|
+
: null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The camera track's size, which is populated before the element's metadata
|
|
21
|
+
* lands. Second choice, not first: a browser that rotates the frame for the
|
|
22
|
+
* device's orientation reports the ROTATED size on the element and the sensor
|
|
23
|
+
* size on the track, and `drawImage` draws what the element has.
|
|
24
|
+
*/
|
|
25
|
+
function readTrackSize(el) {
|
|
26
|
+
const source = el.srcObject;
|
|
27
|
+
if (!source || typeof source.getVideoTracks !== 'function')
|
|
28
|
+
return null;
|
|
29
|
+
const settings = source.getVideoTracks()[0]?.getSettings?.();
|
|
30
|
+
return settings?.width && settings.height
|
|
31
|
+
? { width: settings.width, height: settings.height }
|
|
32
|
+
: null;
|
|
33
|
+
}
|
|
5
34
|
/**
|
|
6
35
|
* How long after the first ink `simulateRecordingInterrupted` lets the
|
|
7
36
|
* recording run.
|
|
@@ -210,22 +239,85 @@ export function createSignatureCapturePipeline(config = {}) {
|
|
|
210
239
|
id = requestAnimationFrame(next);
|
|
211
240
|
return () => cancelAnimationFrame(id);
|
|
212
241
|
}
|
|
213
|
-
|
|
242
|
+
/**
|
|
243
|
+
* The size to record at, waiting for the camera to report one.
|
|
244
|
+
*
|
|
245
|
+
* `videoWidth`/`videoHeight` are 0 until the element has metadata, and the
|
|
246
|
+
* signature stage mounts its OWN `<video>` and starts recording as soon as
|
|
247
|
+
* the pipeline is ready — so the metadata routinely lands after `start()`.
|
|
248
|
+
* Sizing the canvas off the landscape fallback in that window recorded every
|
|
249
|
+
* portrait capture stretched into landscape, because `paintFrame` paints the
|
|
250
|
+
* camera across the whole canvas. Desktop never saw it: a landscape camera
|
|
251
|
+
* matches the fallback. The canvas cannot be resized later either — its size
|
|
252
|
+
* is the recording's, fixed when `captureStream` hands the track over.
|
|
253
|
+
*/
|
|
254
|
+
async function resolveOutputSize(el) {
|
|
255
|
+
const ready = readVideoSize(el);
|
|
256
|
+
if (ready)
|
|
257
|
+
return ready;
|
|
258
|
+
if (typeof el.addEventListener === 'function') {
|
|
259
|
+
// Cleared after the wait rather than inside it: an `io.setTimeout` that
|
|
260
|
+
// calls back synchronously — a test's, never a browser's — would reach
|
|
261
|
+
// this in its dead zone and throw out of `start()`.
|
|
262
|
+
let timer;
|
|
263
|
+
await new Promise((resolve) => {
|
|
264
|
+
let settled = false;
|
|
265
|
+
const finish = () => {
|
|
266
|
+
if (settled)
|
|
267
|
+
return;
|
|
268
|
+
settled = true;
|
|
269
|
+
el.removeEventListener('loadedmetadata', finish);
|
|
270
|
+
// `resize` also covers a camera that reports a size and then changes
|
|
271
|
+
// it — a device rotation between attach and start.
|
|
272
|
+
el.removeEventListener('resize', finish);
|
|
273
|
+
resolve();
|
|
274
|
+
};
|
|
275
|
+
timer = io.setTimeout(finish, VIDEO_DIMENSIONS_TIMEOUT_MS);
|
|
276
|
+
// Already timed out, so there is nothing left to listen for.
|
|
277
|
+
if (settled)
|
|
278
|
+
return;
|
|
279
|
+
el.addEventListener('loadedmetadata', finish);
|
|
280
|
+
el.addEventListener('resize', finish);
|
|
281
|
+
// The metadata can land between the check above and the listener.
|
|
282
|
+
if (readVideoSize(el))
|
|
283
|
+
finish();
|
|
284
|
+
});
|
|
285
|
+
if (timer !== undefined)
|
|
286
|
+
io.clearTimeout(timer);
|
|
287
|
+
}
|
|
288
|
+
return readVideoSize(el) ?? readTrackSize(el) ?? FALLBACK_OUTPUT_SIZE;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Composites the camera, the watermark panel and any ink onto the output
|
|
292
|
+
* canvas. Metric-free, so it can also PRIME the canvas before the capture
|
|
293
|
+
* stream exists — see `start()`. Returns whether ink was drawn.
|
|
294
|
+
*/
|
|
295
|
+
function paintFrame() {
|
|
214
296
|
if (!video || !signatureCanvas || !outputCanvas)
|
|
215
|
-
return;
|
|
297
|
+
return false;
|
|
216
298
|
const context = outputCanvas.getContext('2d');
|
|
217
299
|
if (!context)
|
|
218
|
-
return;
|
|
219
|
-
const now = io.now();
|
|
220
|
-
if (lastFrameAt)
|
|
221
|
-
maxFrameGapMs = Math.max(maxFrameGapMs, now - lastFrameAt);
|
|
222
|
-
lastFrameAt = now;
|
|
223
|
-
totalFrames += 1;
|
|
224
|
-
if (signatureStartedAt && !acceptClickedAt)
|
|
225
|
-
signingWindowFrames += 1;
|
|
300
|
+
return false;
|
|
226
301
|
const width = outputCanvas.width;
|
|
227
302
|
const height = outputCanvas.height;
|
|
228
|
-
|
|
303
|
+
// Aspect-preserving, so a camera whose frame does not match the canvas
|
|
304
|
+
// cannot be recorded distorted. The two match for the whole recording in
|
|
305
|
+
// the normal case (`resolveOutputSize` sized the canvas from this very
|
|
306
|
+
// element), which makes the scale exactly 1 and this an ordinary
|
|
307
|
+
// full-canvas draw. It bites only when they diverge — the camera reported
|
|
308
|
+
// no size at all and the canvas took the fallback, or the device was
|
|
309
|
+
// rotated mid-recording — where cropping the overflow beats stretching
|
|
310
|
+
// the signer sideways.
|
|
311
|
+
const source = readVideoSize(video);
|
|
312
|
+
if (source) {
|
|
313
|
+
const scale = Math.max(width / source.width, height / source.height);
|
|
314
|
+
const drawWidth = source.width * scale;
|
|
315
|
+
const drawHeight = source.height * scale;
|
|
316
|
+
context.drawImage(video, (width - drawWidth) / 2, (height - drawHeight) / 2, drawWidth, drawHeight);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
context.drawImage(video, 0, 0, width, height);
|
|
320
|
+
}
|
|
229
321
|
const portrait = width < height;
|
|
230
322
|
const rect = [
|
|
231
323
|
width * (portrait ? 0.02 : 0.15),
|
|
@@ -237,8 +329,27 @@ export function createSignatureCapturePipeline(config = {}) {
|
|
|
237
329
|
context.fillRect(...rect);
|
|
238
330
|
if (signatureStartedAt && hasDrawablePixels(signatureCanvas)) {
|
|
239
331
|
context.drawImage(signatureCanvas, ...rect);
|
|
240
|
-
|
|
332
|
+
return true;
|
|
241
333
|
}
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
function drawFrame() {
|
|
337
|
+
if (!video || !signatureCanvas || !outputCanvas)
|
|
338
|
+
return;
|
|
339
|
+
// Not redundant with the same check inside `paintFrame`: a canvas with no
|
|
340
|
+
// 2d context draws nothing, and a frame that was never drawn must not be
|
|
341
|
+
// counted below. Browsers hand back the same cached context each call.
|
|
342
|
+
if (!outputCanvas.getContext('2d'))
|
|
343
|
+
return;
|
|
344
|
+
const now = io.now();
|
|
345
|
+
if (lastFrameAt)
|
|
346
|
+
maxFrameGapMs = Math.max(maxFrameGapMs, now - lastFrameAt);
|
|
347
|
+
lastFrameAt = now;
|
|
348
|
+
totalFrames += 1;
|
|
349
|
+
if (signatureStartedAt && !acceptClickedAt)
|
|
350
|
+
signingWindowFrames += 1;
|
|
351
|
+
if (paintFrame())
|
|
352
|
+
signatureFrames += 1;
|
|
242
353
|
}
|
|
243
354
|
async function exportImage() {
|
|
244
355
|
if (!signatureCanvas)
|
|
@@ -349,7 +460,23 @@ export function createSignatureCapturePipeline(config = {}) {
|
|
|
349
460
|
activeRecorder.onstop = null;
|
|
350
461
|
activeRecorder.onerror = null;
|
|
351
462
|
if (activeRecorder.state !== 'inactive') {
|
|
352
|
-
|
|
463
|
+
try {
|
|
464
|
+
await waitForRecorderStop(activeRecorder);
|
|
465
|
+
}
|
|
466
|
+
catch (cause) {
|
|
467
|
+
// Best-effort by design. This teardown discards the recording —
|
|
468
|
+
// `start()` runs it before building a fresh recorder, so nothing
|
|
469
|
+
// here is handed to the user. A recorder that never fires `onstop`
|
|
470
|
+
// (iOS Safari does this) would otherwise fail the restart it was
|
|
471
|
+
// clearing the way for: the user taps Clear and gets an error
|
|
472
|
+
// screen instead of a blank pad. The `finally` below releases the
|
|
473
|
+
// tracks and drops the reference either way, so abandoning the
|
|
474
|
+
// dead recorder leaks nothing.
|
|
475
|
+
//
|
|
476
|
+
// `stopRecorder()` keeps propagating its timeout — there the stop
|
|
477
|
+
// IS the capture, and a truncated video must not pass silently.
|
|
478
|
+
warn('[signature] recorder did not stop during teardown', cause);
|
|
479
|
+
}
|
|
353
480
|
}
|
|
354
481
|
}
|
|
355
482
|
}
|
|
@@ -436,9 +563,49 @@ export function createSignatureCapturePipeline(config = {}) {
|
|
|
436
563
|
return;
|
|
437
564
|
if (!video || !signatureCanvas)
|
|
438
565
|
throw new Error('Signature pipeline not attached');
|
|
566
|
+
// Awaited BEFORE the canvas exists: its size is the recording's, and
|
|
567
|
+
// nothing can change it once the track is live.
|
|
568
|
+
let measured = video;
|
|
569
|
+
let size = await resolveOutputSize(measured);
|
|
570
|
+
// A view can replace the `<video>` during that wait — SignatureKYCFlow
|
|
571
|
+
// hands one element across its stages — and the frame loop paints
|
|
572
|
+
// whatever `video` is by then, so a size measured off the old element
|
|
573
|
+
// would put the crop path to work for the whole recording. Re-measure
|
|
574
|
+
// the element that will actually be painted, without chasing a swap
|
|
575
|
+
// that keeps repeating.
|
|
576
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
577
|
+
if (disposed || !video || video === measured)
|
|
578
|
+
break;
|
|
579
|
+
measured = video;
|
|
580
|
+
size = await resolveOutputSize(measured);
|
|
581
|
+
}
|
|
582
|
+
// The wait is the only await between the attachment check and the
|
|
583
|
+
// recorder, so a pipeline disposed while the camera was still coming up
|
|
584
|
+
// would otherwise build a recorder nothing will ever stop.
|
|
585
|
+
if (disposed || !video || !signatureCanvas)
|
|
586
|
+
return;
|
|
439
587
|
outputCanvas = io.createCanvas();
|
|
440
|
-
outputCanvas.width =
|
|
441
|
-
outputCanvas.height =
|
|
588
|
+
outputCanvas.width = size.width;
|
|
589
|
+
outputCanvas.height = size.height;
|
|
590
|
+
// Paint BEFORE the stream exists. `captureStream` emits the canvas as it
|
|
591
|
+
// stands when the track starts, so an unpainted canvas makes frame 0 of
|
|
592
|
+
// the recording blank — and the post-capture probe reads the trim start,
|
|
593
|
+
// which clamps to 0 whenever the user signs inside the padding window.
|
|
594
|
+
// That blank frame then condemned a perfectly good capture as at-risk.
|
|
595
|
+
// It surfaced on iOS Safari only because its mp4 takes the frame probe's
|
|
596
|
+
// seek path, which lands exactly on frame 0; Chrome's bogus-`Duration`
|
|
597
|
+
// WebM routes to the playback path, which had already moved past it.
|
|
598
|
+
try {
|
|
599
|
+
paintFrame();
|
|
600
|
+
}
|
|
601
|
+
catch (cause) {
|
|
602
|
+
// Nothing here is expected to throw — `drawImage` on a camera that has
|
|
603
|
+
// not delivered a frame is a no-op, and the ink draw is guarded — but a
|
|
604
|
+
// silent failure would put frame 0 back to blank with nothing saying
|
|
605
|
+
// so. Log it: the probe's blank frame-0 retry still covers the
|
|
606
|
+
// recording, and failing the capture over the priming would be worse.
|
|
607
|
+
warn('[signature] could not prime the output canvas', cause);
|
|
608
|
+
}
|
|
442
609
|
const captureStream = outputCanvas.captureStream;
|
|
443
610
|
if (!captureStream)
|
|
444
611
|
throw new Error('Canvas captureStream is not supported');
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const webSdkCoreVersion = "0.
|
|
1
|
+
export declare const webSdkCoreVersion = "0.2.0-rc.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const webSdkCoreVersion = '0.
|
|
1
|
+
export const webSdkCoreVersion = '0.2.0-rc.1';
|