idmission-web-sdk 2.3.102 → 2.3.104

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/sdk2.esm.js CHANGED
@@ -205,7 +205,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
205
205
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
206
206
  };
207
207
 
208
- var webSdkVersion = '2.3.102';
208
+ var webSdkVersion = '2.3.104';
209
209
 
210
210
  function getPlatform() {
211
211
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -1379,6 +1379,9 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1379
1379
  return __spreadArray(__spreadArray([], attempts, true), [attempt], false);
1380
1380
  });
1381
1381
  }, []);
1382
+ useRevokeObjectUrlOnUnmount(signatureVideoUrl);
1383
+ useRevokeObjectUrlOnUnmount(idCaptureVideoUrl);
1384
+ useRevokeObjectUrlOnUnmount(idCaptureVideoAudioUrl);
1382
1385
  useEffect(function () {
1383
1386
  if (precapturedDocuments === null || precapturedDocuments === void 0 ? void 0 : precapturedDocuments.selfie) {
1384
1387
  setSelfieImage(dataUrlToBase64Sync(precapturedDocuments.selfie.imageData));
@@ -2162,6 +2165,13 @@ function useSubmissionContext() {
2162
2165
  }
2163
2166
  return context;
2164
2167
  }
2168
+ function useRevokeObjectUrlOnUnmount(url) {
2169
+ useEffect(function () {
2170
+ return function () {
2171
+ if (url) URL.revokeObjectURL(url);
2172
+ };
2173
+ }, [url]);
2174
+ }
2165
2175
 
2166
2176
  var visionTasksBasePath = "https://websdk-cdn-dev.idmission.com/assets/vision_wasm_internal_0.10.7";
2167
2177
  var visionRuntimePreloading = false;
@@ -14302,7 +14312,11 @@ var videoSignatureInitialState = {
14302
14312
  return null;
14303
14313
  },
14304
14314
  stopRecording: function stopRecording() {
14305
- return null;
14315
+ return __awaiter(void 0, void 0, void 0, function () {
14316
+ return __generator(this, function (_a) {
14317
+ return [2 /*return*/, void 0];
14318
+ });
14319
+ });
14306
14320
  },
14307
14321
  clearRecordedData: function clearRecordedData() {
14308
14322
  return null;
@@ -14367,45 +14381,54 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14367
14381
  });
14368
14382
  },
14369
14383
  stopRecording: function stopRecording(signatureData, imageUrl) {
14370
- set({
14371
- recordingStopRequestedAt: performance.now()
14372
- });
14373
- waitForOneMoreChunk().then(function () {
14374
- if (!signatureRecorder) return;
14375
- signatureRecorder.stop();
14376
- signatureRecorder.onstop = function () {
14377
- return __awaiter(void 0, void 0, void 0, function () {
14378
- var recordingStoppedAt, inferredType, blob, _a, onSignatureVideoCaptured, recordingStartRequestedAt, recordingStartedAt, firstChunkReceivedAt, signatureStartedAt, signatureEndedAt, recordingStopRequestedAt, lastChunkReceivedAt;
14379
- return __generator(this, function (_b) {
14380
- recordingStoppedAt = performance.now();
14384
+ return __awaiter(this, void 0, void 0, function () {
14385
+ var _this = this;
14386
+ return __generator(this, function (_a) {
14387
+ switch (_a.label) {
14388
+ case 0:
14381
14389
  set({
14382
- recordingStoppedAt: recordingStoppedAt
14383
- });
14384
- inferredType = inferBlobType(signatureChunks[0]) || (signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.mimeType) || 'video/mp4';
14385
- blob = new Blob(signatureChunks, {
14386
- type: inferredType
14387
- });
14388
- signatureChunks = [];
14389
- signatureRecorder = null;
14390
- if (!signatureData) return [2 /*return*/];
14391
- _a = get(), onSignatureVideoCaptured = _a.onSignatureVideoCaptured, recordingStartRequestedAt = _a.recordingStartRequestedAt, recordingStartedAt = _a.recordingStartedAt, firstChunkReceivedAt = _a.firstChunkReceivedAt, signatureStartedAt = _a.signatureStartedAt, signatureEndedAt = _a.signatureEndedAt, recordingStopRequestedAt = _a.recordingStopRequestedAt, lastChunkReceivedAt = _a.lastChunkReceivedAt;
14392
- onSignatureVideoCaptured(blob, signatureData, imageUrl !== null && imageUrl !== void 0 ? imageUrl : null, {
14393
- mimeType: inferredType,
14394
- timingData: {
14395
- recordingStartRequestedAt: recordingStartRequestedAt,
14396
- recordingStartedAt: recordingStartedAt,
14397
- firstChunkReceivedAt: firstChunkReceivedAt,
14398
- signatureStartedAt: signatureStartedAt,
14399
- signatureEndedAt: signatureEndedAt,
14400
- recordingStopRequestedAt: recordingStopRequestedAt,
14401
- recordingStoppedAt: recordingStoppedAt,
14402
- lastChunkReceivedAt: lastChunkReceivedAt
14403
- }
14390
+ recordingStopRequestedAt: performance.now()
14404
14391
  });
14392
+ if (!signatureRecorder) return [2 /*return*/];
14393
+ return [4 /*yield*/, waitForOneMoreChunk()];
14394
+ case 1:
14395
+ _a.sent();
14396
+ signatureRecorder.onstop = function () {
14397
+ return __awaiter(_this, void 0, void 0, function () {
14398
+ var recordingStoppedAt, mimeType, blob, _a, onSignatureVideoCaptured, recordingStartRequestedAt, recordingStartedAt, firstChunkReceivedAt, signatureStartedAt, signatureEndedAt, recordingStopRequestedAt, lastChunkReceivedAt;
14399
+ return __generator(this, function (_b) {
14400
+ recordingStoppedAt = performance.now();
14401
+ set({
14402
+ recordingStoppedAt: recordingStoppedAt
14403
+ });
14404
+ mimeType = inferBlobType(signatureChunks[0]) || (signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.mimeType) || 'video/mp4';
14405
+ blob = new Blob(signatureChunks, {
14406
+ type: mimeType
14407
+ });
14408
+ signatureChunks = [];
14409
+ signatureRecorder = null;
14410
+ _a = get(), onSignatureVideoCaptured = _a.onSignatureVideoCaptured, recordingStartRequestedAt = _a.recordingStartRequestedAt, recordingStartedAt = _a.recordingStartedAt, firstChunkReceivedAt = _a.firstChunkReceivedAt, signatureStartedAt = _a.signatureStartedAt, signatureEndedAt = _a.signatureEndedAt, recordingStopRequestedAt = _a.recordingStopRequestedAt, lastChunkReceivedAt = _a.lastChunkReceivedAt;
14411
+ onSignatureVideoCaptured(blob, signatureData !== null && signatureData !== void 0 ? signatureData : null, imageUrl !== null && imageUrl !== void 0 ? imageUrl : null, {
14412
+ mimeType: mimeType,
14413
+ timingData: {
14414
+ recordingStartRequestedAt: recordingStartRequestedAt,
14415
+ recordingStartedAt: recordingStartedAt,
14416
+ firstChunkReceivedAt: firstChunkReceivedAt,
14417
+ signatureStartedAt: signatureStartedAt,
14418
+ signatureEndedAt: signatureEndedAt,
14419
+ recordingStopRequestedAt: recordingStopRequestedAt,
14420
+ recordingStoppedAt: recordingStoppedAt,
14421
+ lastChunkReceivedAt: lastChunkReceivedAt
14422
+ }
14423
+ });
14424
+ return [2 /*return*/];
14425
+ });
14426
+ });
14427
+ };
14428
+ signatureRecorder.stop();
14405
14429
  return [2 /*return*/];
14406
- });
14407
- });
14408
- };
14430
+ }
14431
+ });
14409
14432
  });
14410
14433
  },
14411
14434
  clearRecordedData: function clearRecordedData() {
@@ -14425,28 +14448,40 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14425
14448
  }
14426
14449
  });
14427
14450
  }));
14428
- function waitForOneMoreChunk(timeoutMs) {
14451
+ /**
14452
+ * Wait for one more chunk to be received after the recording has stopped.
14453
+ * @param delayMs - The delay in milliseconds before the first check -- this is used to make sure we get at least one extra second of video.
14454
+ * @param checkEveryMs - The interval in milliseconds between checks after the initial delay has passed.
14455
+ * @param timeoutMs - The maximum time in milliseconds to wait for the chunk -- this is used to prevent infinite loops.
14456
+ * @returns A promise that resolves when the delay has passed and at least one chunk has been received received.
14457
+ */
14458
+ function waitForOneMoreChunk(delayMs, checkEveryMs, timeoutMs) {
14459
+ if (delayMs === void 0) {
14460
+ delayMs = 1000;
14461
+ }
14462
+ if (checkEveryMs === void 0) {
14463
+ checkEveryMs = 100;
14464
+ }
14429
14465
  if (timeoutMs === void 0) {
14430
14466
  timeoutMs = 3000;
14431
14467
  }
14432
14468
  var start = performance.now();
14433
14469
  return new Promise(function (resolve) {
14434
14470
  var initialLastChunkReceivedAt = useVideoSignatureStore.getState().lastChunkReceivedAt;
14435
- if (!initialLastChunkReceivedAt) return resolve();
14436
14471
  function gotAChunk() {
14437
14472
  var lastChunkReceivedAt = useVideoSignatureStore.getState().lastChunkReceivedAt;
14438
14473
  return performance.now() - start > timeoutMs || !lastChunkReceivedAt || !initialLastChunkReceivedAt || lastChunkReceivedAt > initialLastChunkReceivedAt;
14439
14474
  }
14440
14475
  setTimeout(function () {
14441
14476
  if (gotAChunk()) return resolve(); // check immediately
14442
- // otherwise, check every 100ms
14477
+ // otherwise, check on a configured interval
14443
14478
  var interval = setInterval(function () {
14444
14479
  if (gotAChunk()) {
14445
14480
  clearInterval(interval);
14446
14481
  resolve();
14447
14482
  }
14448
- }, 100);
14449
- }, 0);
14483
+ }, checkEveryMs);
14484
+ }, delayMs);
14450
14485
  });
14451
14486
  }
14452
14487
  function VideoSignatureContextProvider(_a) {
@@ -14552,23 +14587,37 @@ function isCanvasBlank(canvas) {
14552
14587
  }
14553
14588
  function requestVideoFrameCallback(video, onFrame) {
14554
14589
  if (typeof (video === null || video === void 0 ? void 0 : video.requestVideoFrameCallback) === 'function') {
14555
- video.requestVideoFrameCallback(onFrame);
14590
+ var rafId_1 = video.requestVideoFrameCallback(onFrame);
14591
+ return function () {
14592
+ return video.cancelVideoFrameCallback(rafId_1);
14593
+ };
14556
14594
  } else {
14557
- requestAnimationFrame(onFrame);
14595
+ var rafId_2 = requestAnimationFrame(onFrame);
14596
+ return function () {
14597
+ return cancelAnimationFrame(rafId_2);
14598
+ };
14558
14599
  }
14559
14600
  }
14560
14601
  function videoFrameLoop(video, onFrame) {
14561
14602
  if (!video) return;
14603
+ var cancelFn;
14604
+ var canceled = false;
14562
14605
  function onFrameRecursive() {
14606
+ if (canceled) return;
14563
14607
  onFrame();
14564
- requestVideoFrameCallback(video, onFrameRecursive);
14608
+ cancelFn = requestVideoFrameCallback(video, onFrameRecursive);
14565
14609
  }
14566
14610
  function onPlay() {
14567
- requestVideoFrameCallback(video, onFrameRecursive);
14611
+ if (canceled) return;
14612
+ cancelFn = requestVideoFrameCallback(video, onFrameRecursive);
14568
14613
  }
14569
14614
  video.addEventListener('play', onPlay);
14615
+ // If video already playing, start immediately
14616
+ if (!video.paused && video.readyState >= 2) onPlay();
14570
14617
  return function () {
14618
+ canceled = true;
14571
14619
  video.removeEventListener('play', onPlay);
14620
+ if (cancelFn !== undefined) cancelFn();
14572
14621
  };
14573
14622
  }
14574
14623
  function useVideoFrameLoop(ref, onFrame) {
@@ -14818,7 +14867,7 @@ var VideoSignatureCapture = function VideoSignatureCapture(_a) {
14818
14867
  useEffect(function () {
14819
14868
  useVideoSignatureStore.getState().startRecording(captureAudio);
14820
14869
  return function () {
14821
- return useVideoSignatureStore.getState().stopRecording();
14870
+ return void useVideoSignatureStore.getState().stopRecording();
14822
14871
  };
14823
14872
  }, [captureAudio]);
14824
14873
  useEffect(function () {
@@ -15291,7 +15340,7 @@ var VideoSignatureWizard = function VideoSignatureWizard(_a) {
15291
15340
  }).then(onSelfieCaptured);
15292
15341
  }, [logCaptureMetadata, onSelfieCaptured, setSelfieImage, uploadDocument]);
15293
15342
  var onSignatureCaptureCompleted = useCallback(function (videoData, signatureData, signatureImageData, metadata) {
15294
- setSignatureData(signatureData);
15343
+ if (signatureData) setSignatureData(signatureData);
15295
15344
  setSignatureVideoUrl(URL.createObjectURL(videoData));
15296
15345
  setSignatureVideoMetadata(metadata);
15297
15346
  setCaptureState('SUCCESS');