idmission-web-sdk 2.3.124 → 2.3.125

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.124';
208
+ var webSdkVersion = '2.3.125';
209
209
 
210
210
  function getPlatform() {
211
211
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -14378,6 +14378,9 @@ function inferBlobType(blobPart) {
14378
14378
 
14379
14379
  var signatureRecorder = null;
14380
14380
  var signatureChunks = [];
14381
+ var ondataavailableInvocations = [];
14382
+ var ondataavailableStartTime;
14383
+ var lastCalculatedVideoChunkRate;
14381
14384
  var videoSignatureInitialState = {
14382
14385
  startRecording: function startRecording() {
14383
14386
  return null;
@@ -14402,6 +14405,10 @@ var videoSignatureInitialState = {
14402
14405
  signatureValid: false,
14403
14406
  supportsRequestVideoFrameCallback: undefined,
14404
14407
  supportsRoundRect: undefined,
14408
+ nullChunksReceived: 0,
14409
+ timesSignatureCleared: 0,
14410
+ finalChunkReceived: false,
14411
+ requestDataInterval: undefined,
14405
14412
  onSignatureVideoCaptured: function onSignatureVideoCaptured() {
14406
14413
  return null;
14407
14414
  }
@@ -14414,8 +14421,11 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14414
14421
  captureAudio = false;
14415
14422
  }
14416
14423
  if (!camera) throw new Error('Camera not found');
14417
- // set our flag and clear whatever we have recorded so far.
14424
+ // clear whatever we have recorded so far.
14418
14425
  signatureChunks = [];
14426
+ ondataavailableInvocations = [];
14427
+ ondataavailableStartTime = undefined;
14428
+ lastCalculatedVideoChunkRate = undefined;
14419
14429
  // start recording from the output canvas to capture the signature
14420
14430
  var outputStream = (_a = get().outputCanvas.current) === null || _a === void 0 ? void 0 : _a.captureStream(24);
14421
14431
  if (!outputStream) throw new Error('outputStream not found');
@@ -14433,77 +14443,123 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14433
14443
  recordingStartedAt: e.timeStamp
14434
14444
  });
14435
14445
  };
14436
- var hasFirstChunk = false;
14437
14446
  signatureRecorder.ondataavailable = function (event) {
14447
+ var now = performance.now();
14438
14448
  signatureChunks.push(event.data);
14439
- if (!hasFirstChunk) {
14440
- hasFirstChunk = true;
14441
- set({
14442
- firstChunkReceivedAt: performance.now(),
14443
- lastChunkReceivedAt: performance.now()
14449
+ trackVideoChunkRate(now);
14450
+ if (event.data.size > 0) {
14451
+ set(function (state) {
14452
+ var _a;
14453
+ return {
14454
+ firstChunkReceivedAt: (_a = state.firstChunkReceivedAt) !== null && _a !== void 0 ? _a : now,
14455
+ lastChunkReceivedAt: now
14456
+ };
14444
14457
  });
14445
14458
  } else {
14446
- set({
14447
- lastChunkReceivedAt: performance.now()
14459
+ set(function (state) {
14460
+ var _a;
14461
+ return {
14462
+ nullChunksReceived: state.nullChunksReceived + 1,
14463
+ firstNullChunkReceivedAt: (_a = state.firstNullChunkReceivedAt) !== null && _a !== void 0 ? _a : now,
14464
+ lastNullChunkReceivedAt: now
14465
+ };
14448
14466
  });
14449
14467
  }
14450
14468
  };
14451
- signatureRecorder.start(250);
14469
+ signatureRecorder.start();
14470
+ var interval = setInterval(function () {
14471
+ return signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.requestData();
14472
+ }, 250);
14452
14473
  set({
14474
+ requestDataInterval: interval,
14453
14475
  recordingStartRequestedAt: performance.now()
14454
14476
  });
14455
14477
  },
14456
14478
  stopRecording: function stopRecording(signatureData, imageUrl) {
14457
14479
  return __awaiter(this, void 0, void 0, function () {
14458
- var _this = this;
14459
- return __generator(this, function (_a) {
14460
- switch (_a.label) {
14480
+ function processVideo() {
14481
+ return __awaiter(this, void 0, void 0, function () {
14482
+ var recordingStoppedAt, mimeType, blob, _a, onSignatureVideoCaptured, recordingStartRequestedAt, recordingStartedAt, firstChunkReceivedAt, signatureStartedAt, signatureEndedAt, acceptClickedAt, clearClickedAt, recordingStopRequestedAt, lastChunkReceivedAt, supportsRequestVideoFrameCallback, supportsRoundRect, nullChunksReceived, firstNullChunkReceivedAt, lastNullChunkReceivedAt, timesSignatureCleared, metadata;
14483
+ return __generator(this, function (_b) {
14484
+ if (get().recordingStoppedAt) return [2 /*return*/];
14485
+ recordingStoppedAt = performance.now();
14486
+ set({
14487
+ recordingStoppedAt: recordingStoppedAt
14488
+ });
14489
+ mimeType = inferBlobType(signatureChunks[0]) || (signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.mimeType) || 'video/mp4';
14490
+ blob = new Blob(signatureChunks, {
14491
+ type: mimeType
14492
+ });
14493
+ signatureChunks = [];
14494
+ signatureRecorder = null;
14495
+ _a = get(), onSignatureVideoCaptured = _a.onSignatureVideoCaptured, recordingStartRequestedAt = _a.recordingStartRequestedAt, recordingStartedAt = _a.recordingStartedAt, firstChunkReceivedAt = _a.firstChunkReceivedAt, signatureStartedAt = _a.signatureStartedAt, signatureEndedAt = _a.signatureEndedAt, acceptClickedAt = _a.acceptClickedAt, clearClickedAt = _a.clearClickedAt, recordingStopRequestedAt = _a.recordingStopRequestedAt, lastChunkReceivedAt = _a.lastChunkReceivedAt, supportsRequestVideoFrameCallback = _a.supportsRequestVideoFrameCallback, supportsRoundRect = _a.supportsRoundRect, nullChunksReceived = _a.nullChunksReceived, firstNullChunkReceivedAt = _a.firstNullChunkReceivedAt, lastNullChunkReceivedAt = _a.lastNullChunkReceivedAt, timesSignatureCleared = _a.timesSignatureCleared;
14496
+ metadata = {
14497
+ mimeType: mimeType,
14498
+ browserFeatures: {
14499
+ supportsRoundRect: supportsRoundRect,
14500
+ supportsRequestVideoFrameCallback: supportsRequestVideoFrameCallback
14501
+ },
14502
+ diagnostics: {
14503
+ nullChunksReceived: nullChunksReceived,
14504
+ firstNullChunkReceivedAt: firstNullChunkReceivedAt ? Math.ceil(firstNullChunkReceivedAt) : 0,
14505
+ lastNullChunkReceivedAt: lastNullChunkReceivedAt ? Math.ceil(lastNullChunkReceivedAt) : 0,
14506
+ finalChunkReceived: finalChunkReceived,
14507
+ finalChunkTimedOut: timedOut,
14508
+ finalChunkWaitedMs: Math.ceil(waitedMs),
14509
+ videoChunkRate: lastCalculatedVideoChunkRate,
14510
+ timesSignatureCleared: timesSignatureCleared
14511
+ },
14512
+ timingData: {
14513
+ recordingStartRequestedAt: recordingStartRequestedAt ? Math.ceil(recordingStartRequestedAt) : 0,
14514
+ recordingStartedAt: recordingStartedAt ? Math.ceil(recordingStartedAt) : 0,
14515
+ firstChunkReceivedAt: firstChunkReceivedAt ? Math.ceil(firstChunkReceivedAt) : 0,
14516
+ signatureStartedAt: signatureStartedAt ? Math.ceil(signatureStartedAt) : 0,
14517
+ signatureEndedAt: signatureEndedAt ? Math.ceil(signatureEndedAt) : 0,
14518
+ acceptClickedAt: acceptClickedAt ? Math.ceil(acceptClickedAt) : 0,
14519
+ clearClickedAt: clearClickedAt ? Math.ceil(clearClickedAt) : 0,
14520
+ recordingStopRequestedAt: recordingStopRequestedAt ? Math.ceil(recordingStopRequestedAt) : 0,
14521
+ recordingStoppedAt: Math.ceil(recordingStoppedAt),
14522
+ lastChunkReceivedAt: lastChunkReceivedAt ? Math.ceil(lastChunkReceivedAt) : 0
14523
+ }
14524
+ };
14525
+ debug('signature video metadata', metadata);
14526
+ onSignatureVideoCaptured(blob, signatureData !== null && signatureData !== void 0 ? signatureData : null, imageUrl !== null && imageUrl !== void 0 ? imageUrl : null, metadata);
14527
+ return [2 /*return*/];
14528
+ });
14529
+ });
14530
+ }
14531
+ var _a, recordingStartedAt, recordingStopRequestedAt, isRecording, _b, finalChunkReceived, timedOut, waitedMs;
14532
+ return __generator(this, function (_c) {
14533
+ switch (_c.label) {
14461
14534
  case 0:
14535
+ _a = get(), recordingStartedAt = _a.recordingStartedAt, recordingStopRequestedAt = _a.recordingStopRequestedAt;
14536
+ isRecording = !!recordingStartedAt && !recordingStopRequestedAt;
14537
+ if (!isRecording) return [2 /*return*/];
14462
14538
  set({
14463
- recordingStopRequestedAt: performance.now()
14539
+ recordingStopRequestedAt: performance.now(),
14540
+ recordingStoppedAt: undefined
14464
14541
  });
14465
- if (!signatureRecorder) return [2 /*return*/];
14466
- return [4 /*yield*/, waitForOneMoreChunk()];
14542
+ clearInterval(get().requestDataInterval);
14543
+ return [4 /*yield*/, waitForOneMoreChunk()
14544
+ // this represents the time that it is safe to release the camera access
14545
+ ];
14467
14546
  case 1:
14468
- _a.sent();
14469
- signatureRecorder.onstop = function () {
14470
- return __awaiter(_this, void 0, void 0, function () {
14471
- var recordingStoppedAt, mimeType, blob, _a, onSignatureVideoCaptured, recordingStartRequestedAt, recordingStartedAt, firstChunkReceivedAt, signatureStartedAt, signatureEndedAt, acceptClickedAt, recordingStopRequestedAt, lastChunkReceivedAt, supportsRequestVideoFrameCallback, supportsRoundRect;
14472
- return __generator(this, function (_b) {
14473
- recordingStoppedAt = performance.now();
14474
- set({
14475
- recordingStoppedAt: recordingStoppedAt
14476
- });
14477
- mimeType = inferBlobType(signatureChunks[0]) || (signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.mimeType) || 'video/mp4';
14478
- blob = new Blob(signatureChunks, {
14479
- type: mimeType
14480
- });
14481
- signatureChunks = [];
14482
- signatureRecorder = null;
14483
- _a = get(), onSignatureVideoCaptured = _a.onSignatureVideoCaptured, recordingStartRequestedAt = _a.recordingStartRequestedAt, recordingStartedAt = _a.recordingStartedAt, firstChunkReceivedAt = _a.firstChunkReceivedAt, signatureStartedAt = _a.signatureStartedAt, signatureEndedAt = _a.signatureEndedAt, acceptClickedAt = _a.acceptClickedAt, recordingStopRequestedAt = _a.recordingStopRequestedAt, lastChunkReceivedAt = _a.lastChunkReceivedAt, supportsRequestVideoFrameCallback = _a.supportsRequestVideoFrameCallback, supportsRoundRect = _a.supportsRoundRect;
14484
- onSignatureVideoCaptured(blob, signatureData !== null && signatureData !== void 0 ? signatureData : null, imageUrl !== null && imageUrl !== void 0 ? imageUrl : null, {
14485
- mimeType: mimeType,
14486
- browserFeatures: {
14487
- supportsRoundRect: supportsRoundRect,
14488
- supportsRequestVideoFrameCallback: supportsRequestVideoFrameCallback
14489
- },
14490
- timingData: {
14491
- recordingStartRequestedAt: recordingStartRequestedAt ? Math.ceil(recordingStartRequestedAt) : 0,
14492
- recordingStartedAt: recordingStartedAt ? Math.ceil(recordingStartedAt) : 0,
14493
- firstChunkReceivedAt: firstChunkReceivedAt ? Math.ceil(firstChunkReceivedAt) : 0,
14494
- signatureStartedAt: signatureStartedAt ? Math.ceil(signatureStartedAt) : 0,
14495
- signatureEndedAt: signatureEndedAt ? Math.ceil(signatureEndedAt) : 0,
14496
- acceptClickedAt: acceptClickedAt ? Math.ceil(acceptClickedAt) : 0,
14497
- recordingStopRequestedAt: recordingStopRequestedAt ? Math.ceil(recordingStopRequestedAt) : 0,
14498
- recordingStoppedAt: Math.ceil(recordingStoppedAt),
14499
- lastChunkReceivedAt: lastChunkReceivedAt ? Math.ceil(lastChunkReceivedAt) : 0
14500
- }
14501
- });
14502
- return [2 /*return*/];
14503
- });
14504
- });
14505
- };
14547
+ _b = _c.sent(), finalChunkReceived = _b.finalChunkReceived, timedOut = _b.timedOut, waitedMs = _b.waitedMs;
14548
+ // this represents the time that it is safe to release the camera access
14549
+ set({
14550
+ finalChunkReceived: true
14551
+ });
14552
+ if (!signatureRecorder) return [3 /*break*/, 2];
14553
+ signatureRecorder.onstop = processVideo;
14506
14554
  signatureRecorder.stop();
14555
+ return [3 /*break*/, 4];
14556
+ case 2:
14557
+ warn('signature recorder not found, processing video immediately');
14558
+ return [4 /*yield*/, processVideo()];
14559
+ case 3:
14560
+ _c.sent();
14561
+ _c.label = 4;
14562
+ case 4:
14507
14563
  return [2 /*return*/];
14508
14564
  }
14509
14565
  });
@@ -14511,6 +14567,9 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14511
14567
  },
14512
14568
  clearRecordedData: function clearRecordedData() {
14513
14569
  signatureChunks = [];
14570
+ ondataavailableInvocations = [];
14571
+ ondataavailableStartTime = undefined;
14572
+ lastCalculatedVideoChunkRate = undefined;
14514
14573
  signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.stop();
14515
14574
  signatureRecorder = null;
14516
14575
  set({
@@ -14525,8 +14584,13 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14525
14584
  signatureStartedAt: undefined,
14526
14585
  signatureEndedAt: undefined,
14527
14586
  acceptClickedAt: undefined,
14587
+ // Note: clearClickedAt is intentionally preserved for telemetry metadata
14528
14588
  supportsRequestVideoFrameCallback: undefined,
14529
- supportsRoundRect: undefined
14589
+ supportsRoundRect: undefined,
14590
+ nullChunksReceived: 0,
14591
+ firstNullChunkReceivedAt: undefined,
14592
+ lastNullChunkReceivedAt: undefined,
14593
+ finalChunkReceived: false
14530
14594
  });
14531
14595
  }
14532
14596
  });
@@ -14536,11 +14600,11 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14536
14600
  * @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.
14537
14601
  * @param checkEveryMs - The interval in milliseconds between checks after the initial delay has passed.
14538
14602
  * @param timeoutMs - The maximum time in milliseconds to wait for the chunk -- this is used to prevent infinite loops.
14539
- * @returns A promise that resolves when the delay has passed and at least one chunk has been received received.
14603
+ * @returns A promise that resolves when the delay has passed and at least one chunk has been received received. The return value is the number of milliseconds that we waited, whether we received a chunk, and whether we timed out.
14540
14604
  */
14541
14605
  function waitForOneMoreChunk(delayMs, checkEveryMs, timeoutMs) {
14542
14606
  if (delayMs === void 0) {
14543
- delayMs = 1000;
14607
+ delayMs = 250;
14544
14608
  }
14545
14609
  if (checkEveryMs === void 0) {
14546
14610
  checkEveryMs = 100;
@@ -14548,29 +14612,44 @@ function waitForOneMoreChunk(delayMs, checkEveryMs, timeoutMs) {
14548
14612
  if (timeoutMs === void 0) {
14549
14613
  timeoutMs = 3000;
14550
14614
  }
14551
- var start = performance.now();
14552
14615
  return new Promise(function (resolve) {
14553
- var initialLastChunkReceivedAt = useVideoSignatureStore.getState().lastChunkReceivedAt;
14554
- function gotAChunk() {
14616
+ var _a;
14617
+ var start = performance.now();
14618
+ var initialLastChunkReceivedAt = (_a = useVideoSignatureStore.getState().lastChunkReceivedAt) !== null && _a !== void 0 ? _a : start;
14619
+ signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.requestData();
14620
+ function checkForChunk() {
14555
14621
  var lastChunkReceivedAt = useVideoSignatureStore.getState().lastChunkReceivedAt;
14556
- return performance.now() - start > timeoutMs || !lastChunkReceivedAt || !initialLastChunkReceivedAt || lastChunkReceivedAt > initialLastChunkReceivedAt;
14622
+ var waitedMs = performance.now() - start;
14623
+ var timedOut = waitedMs > timeoutMs;
14624
+ var finalChunkReceived = !!lastChunkReceivedAt && !!initialLastChunkReceivedAt && lastChunkReceivedAt > initialLastChunkReceivedAt;
14625
+ return {
14626
+ waitedMs: waitedMs,
14627
+ finalChunkReceived: finalChunkReceived,
14628
+ timedOut: timedOut
14629
+ };
14557
14630
  }
14558
14631
  setTimeout(function () {
14559
- if (gotAChunk()) return resolve(); // check immediately
14632
+ // check immediately
14633
+ var result = checkForChunk();
14634
+ if (result.finalChunkReceived || result.timedOut) return resolve(result);
14560
14635
  // otherwise, check on a configured interval
14561
14636
  var interval = setInterval(function () {
14562
- if (gotAChunk()) {
14637
+ var result = checkForChunk();
14638
+ if (result.finalChunkReceived || result.timedOut) {
14563
14639
  clearInterval(interval);
14564
- resolve();
14640
+ resolve(result);
14565
14641
  }
14566
14642
  }, checkEveryMs);
14567
14643
  }, delayMs);
14568
14644
  });
14569
14645
  }
14570
14646
  function VideoSignatureContextProvider(_a) {
14571
- var _b, _c;
14572
14647
  var children = _a.children;
14573
- var videoRef = useCameraStore().videoRef;
14648
+ var _b = useCameraStore(),
14649
+ videoRef = _b.videoRef,
14650
+ videoWidth = _b.videoWidth,
14651
+ videoHeight = _b.videoHeight,
14652
+ releaseCameraAccess = _b.releaseCameraAccess;
14574
14653
  var outputCanvas = useRef(null);
14575
14654
  useEffect(function () {
14576
14655
  return useVideoSignatureStore.setState({
@@ -14578,18 +14657,13 @@ function VideoSignatureContextProvider(_a) {
14578
14657
  });
14579
14658
  }, []);
14580
14659
  var drawOutputFrame = useCallback(function () {
14581
- if (!outputCanvas.current || !videoRef.current) return;
14660
+ if (!outputCanvas.current) return;
14582
14661
  var ctx = outputCanvas.current.getContext('2d');
14583
14662
  if (!ctx) return;
14584
- var _a = [videoRef.current.videoWidth, videoRef.current.videoHeight],
14663
+ var _a = [outputCanvas.current.width, outputCanvas.current.height],
14585
14664
  w = _a[0],
14586
14665
  h = _a[1];
14587
14666
  var isPortrait = w < h;
14588
- // Only update canvas dimensions if they changed (setting dimensions clears the canvas!)
14589
- if (outputCanvas.current.width !== w || outputCanvas.current.height !== h) {
14590
- outputCanvas.current.width = w;
14591
- outputCanvas.current.height = h;
14592
- }
14593
14667
  var rect = [w * (isPortrait ? 0.02 : 0.15),
14594
14668
  // x
14595
14669
  h * (isPortrait ? 0.15 : 0.25),
@@ -14598,7 +14672,9 @@ function VideoSignatureContextProvider(_a) {
14598
14672
  // width
14599
14673
  h * (isPortrait ? 0.7 : 0.5) // height
14600
14674
  ];
14601
- ctx.drawImage(videoRef.current, 0, 0, w, h);
14675
+ if (videoRef.current) {
14676
+ ctx.drawImage(videoRef.current, 0, 0, w, h);
14677
+ }
14602
14678
  ctx.beginPath();
14603
14679
  ctx.fillStyle = 'rgba(255,255,255,0.5)';
14604
14680
  var supportsRoundRect = typeof ctx.roundRect === 'function';
@@ -14620,11 +14696,15 @@ function VideoSignatureContextProvider(_a) {
14620
14696
  ctx.drawImage.apply(ctx, __spreadArray([signatureCanvas], rect, false));
14621
14697
  }
14622
14698
  }, [videoRef]);
14623
- useVideoFrameLoop(videoRef, drawOutputFrame);
14699
+ var finalChunkReceived = useVideoSignatureStore().finalChunkReceived;
14700
+ useEffect(function () {
14701
+ if (finalChunkReceived) releaseCameraAccess();
14702
+ }, [finalChunkReceived, releaseCameraAccess]);
14703
+ useVideoFrameLoop(videoRef, drawOutputFrame, !finalChunkReceived);
14624
14704
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, children, /*#__PURE__*/React__default.createElement(InvisibleCanvas, {
14625
14705
  ref: outputCanvas,
14626
- width: (_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.videoWidth,
14627
- height: (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.videoHeight
14706
+ width: videoWidth,
14707
+ height: videoHeight
14628
14708
  }));
14629
14709
  }
14630
14710
  function requestVideoFrameCallback(video, onFrame) {
@@ -14644,8 +14724,11 @@ function requestVideoFrameCallback(video, onFrame) {
14644
14724
  };
14645
14725
  }
14646
14726
  }
14647
- function videoFrameLoop(video, onFrame) {
14648
- if (!video) return;
14727
+ function videoFrameLoop(video, onFrame, running) {
14728
+ if (running === void 0) {
14729
+ running = true;
14730
+ }
14731
+ if (!video || !running) return;
14649
14732
  var cancelFn;
14650
14733
  var canceled = false;
14651
14734
  function onFrameRecursive() {
@@ -14666,10 +14749,51 @@ function videoFrameLoop(video, onFrame) {
14666
14749
  if (cancelFn !== undefined) cancelFn();
14667
14750
  };
14668
14751
  }
14669
- function useVideoFrameLoop(ref, onFrame) {
14752
+ function useVideoFrameLoop(ref, onFrame, running) {
14753
+ if (running === void 0) {
14754
+ running = true;
14755
+ }
14670
14756
  useEffect(function () {
14671
- return videoFrameLoop(ref.current, onFrame);
14672
- }, [onFrame, ref]);
14757
+ return videoFrameLoop(ref.current, onFrame, running);
14758
+ }, [onFrame, ref, running]);
14759
+ }
14760
+ function calculateAndStoreOndataavailableRate() {
14761
+ if (ondataavailableInvocations.length < 2 || !ondataavailableStartTime) {
14762
+ lastCalculatedVideoChunkRate = {
14763
+ averageRate: 0,
14764
+ minRate: 0,
14765
+ maxRate: 0,
14766
+ totalChunksReceived: ondataavailableInvocations.length,
14767
+ recordingDurationMs: 0
14768
+ };
14769
+ return;
14770
+ }
14771
+ var totalDuration = ondataavailableInvocations[ondataavailableInvocations.length - 1] - ondataavailableStartTime;
14772
+ var averageRate = (ondataavailableInvocations.length - 1) / (totalDuration / 1000); // invocations per second
14773
+ // Calculate rates for each interval between invocations
14774
+ var rates = [];
14775
+ for (var i = 1; i < ondataavailableInvocations.length; i++) {
14776
+ var intervalMs = ondataavailableInvocations[i] - ondataavailableInvocations[i - 1];
14777
+ var rate = 1000 / intervalMs; // invocations per second for this interval
14778
+ rates.push(rate);
14779
+ }
14780
+ var minRate = Math.min.apply(Math, rates);
14781
+ var maxRate = Math.max.apply(Math, rates);
14782
+ lastCalculatedVideoChunkRate = {
14783
+ averageRate: Math.round(averageRate * 100) / 100,
14784
+ // Round to 2 decimal places
14785
+ minRate: Math.round(minRate * 100) / 100,
14786
+ maxRate: Math.round(maxRate * 100) / 100,
14787
+ totalChunksReceived: ondataavailableInvocations.length,
14788
+ recordingDurationMs: Math.round(totalDuration)
14789
+ };
14790
+ }
14791
+ function trackVideoChunkRate(now) {
14792
+ // Track ondataavailable invocations for rate calculation
14793
+ ondataavailableStartTime !== null && ondataavailableStartTime !== void 0 ? ondataavailableStartTime : ondataavailableStartTime = now;
14794
+ ondataavailableInvocations.push(now);
14795
+ // Calculate and store the current rate
14796
+ calculateAndStoreOndataavailableRate();
14673
14797
  }
14674
14798
 
14675
14799
  function VideoSignaturePad(_a) {
@@ -15607,13 +15731,18 @@ function VideoSignatureWizardGuides(_a) {
15607
15731
  });
15608
15732
  }, []);
15609
15733
  var onClearBtnClicked = useCallback(function () {
15610
- var _a, _b;
15734
+ var _a;
15735
+ var _b = useVideoSignatureStore.getState(),
15736
+ timesSignatureCleared = _b.timesSignatureCleared,
15737
+ signaturePad = _b.signaturePad;
15611
15738
  useVideoSignatureStore.setState({
15739
+ clearClickedAt: performance.now(),
15740
+ timesSignatureCleared: timesSignatureCleared + 1,
15612
15741
  signatureStartedAt: undefined,
15613
15742
  signaturePadEmpty: true,
15614
15743
  signatureValid: false
15615
15744
  });
15616
- (_b = (_a = useVideoSignatureStore.getState().signaturePad) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.clear();
15745
+ (_a = signaturePad.current) === null || _a === void 0 ? void 0 : _a.clear();
15617
15746
  if (restartVideoOnSignaturePadCleared) {
15618
15747
  setTimeout(function () {
15619
15748
  useVideoSignatureStore.getState().clearRecordedData();