idmission-web-sdk 2.3.98 → 2.3.99

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
@@ -16,6 +16,7 @@ import { devtools } from 'zustand/middleware';
16
16
  import { useShallow } from 'zustand/react/shallow';
17
17
  import cn from 'clsx';
18
18
  import SignatureCanvas from 'react-signature-canvas';
19
+ import { mediaInfoFactory } from 'mediainfo.js';
19
20
  import { renderToString } from 'react-dom/server';
20
21
 
21
22
  /******************************************************************************
@@ -205,7 +206,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
205
206
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
206
207
  };
207
208
 
208
- var webSdkVersion = '2.3.98';
209
+ var webSdkVersion = '2.3.99';
209
210
 
210
211
  function getPlatform() {
211
212
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -14295,14 +14296,23 @@ function inferBlobType(blobPart) {
14295
14296
  return t.length > 0 ? t : undefined;
14296
14297
  }
14297
14298
 
14298
- // import { mediaInfoFactory } from 'mediainfo.js'
14299
- // import type { ReadChunkFunc, MediaInfo, MediaInfoResult } from 'mediainfo.js'
14300
- // import { DEFAULT_CDN_URL } from '../common/cdn'
14301
- // import { warn } from '../../lib/utils/logger'
14302
- // function makeReadChunk(file: File | Blob): ReadChunkFunc {
14303
- // return async (chunkSize: number, offset: number) =>
14304
- // new Uint8Array(await file.slice(offset, offset + chunkSize).arrayBuffer())
14305
- // }
14299
+ function makeReadChunk(file) {
14300
+ var _this = this;
14301
+ return function (chunkSize, offset) {
14302
+ return __awaiter(_this, void 0, void 0, function () {
14303
+ var _a;
14304
+ return __generator(this, function (_b) {
14305
+ switch (_b.label) {
14306
+ case 0:
14307
+ _a = Uint8Array.bind;
14308
+ return [4 /*yield*/, file.slice(offset, offset + chunkSize).arrayBuffer()];
14309
+ case 1:
14310
+ return [2 /*return*/, new (_a.apply(Uint8Array, [void 0, _b.sent()]))()];
14311
+ }
14312
+ });
14313
+ });
14314
+ };
14315
+ }
14306
14316
  var signatureRecorder = null;
14307
14317
  var signatureChunks = [];
14308
14318
  var videoSignatureInitialState = {
@@ -14337,9 +14347,8 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14337
14347
  if (!camera) throw new Error('Camera not found');
14338
14348
  // set our flag and clear whatever we have recorded so far.
14339
14349
  signatureChunks = [];
14340
- var outputCanvas = get().outputCanvas;
14341
14350
  // start recording from the output canvas to capture the signature
14342
- var outputStream = (_a = outputCanvas.current) === null || _a === void 0 ? void 0 : _a.captureStream(24);
14351
+ var outputStream = (_a = get().outputCanvas.current) === null || _a === void 0 ? void 0 : _a.captureStream(24);
14343
14352
  if (!outputStream) throw new Error('outputStream not found');
14344
14353
  var tracks = [outputStream.getVideoTracks()[0]];
14345
14354
  if (captureAudio) {
@@ -14384,39 +14393,42 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14384
14393
  signatureRecorder.stop();
14385
14394
  signatureRecorder.onstop = function () {
14386
14395
  return __awaiter(void 0, void 0, void 0, function () {
14387
- var recordingStoppedAt, inferredType, blob, _a, onSignatureVideoCaptured, recordingStartRequestedAt, recordingStartedAt, firstChunkReceivedAt, signatureStartedAt, signatureEndedAt, recordingStopRequestedAt, lastChunkReceivedAt;
14388
- return __generator(this, function (_b) {
14389
- recordingStoppedAt = performance.now();
14390
- set({
14391
- recordingStoppedAt: recordingStoppedAt
14392
- });
14393
- inferredType = inferBlobType(signatureChunks[0]) || (signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.mimeType) || 'video/mp4';
14394
- blob = new Blob(signatureChunks, {
14395
- type: inferredType
14396
- });
14397
- signatureChunks = [];
14398
- signatureRecorder = null;
14399
- if (!signatureData) return [2 /*return*/];
14400
- _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;
14401
- // const mediaInfo = await get().mediaInfo?.analyzeData(
14402
- // blob.size,
14403
- // makeReadChunk(blob),
14404
- // )
14405
- onSignatureVideoCaptured(blob, signatureData, imageUrl !== null && imageUrl !== void 0 ? imageUrl : null, {
14406
- // mediaInfo,
14407
- mimeType: inferredType,
14408
- timingData: {
14409
- recordingStartRequestedAt: recordingStartRequestedAt,
14410
- recordingStartedAt: recordingStartedAt,
14411
- firstChunkReceivedAt: firstChunkReceivedAt,
14412
- signatureStartedAt: signatureStartedAt,
14413
- signatureEndedAt: signatureEndedAt,
14414
- recordingStopRequestedAt: recordingStopRequestedAt,
14415
- recordingStoppedAt: recordingStoppedAt,
14416
- lastChunkReceivedAt: lastChunkReceivedAt
14417
- }
14418
- });
14419
- return [2 /*return*/];
14396
+ var recordingStoppedAt, inferredType, blob, _a, onSignatureVideoCaptured, recordingStartRequestedAt, recordingStartedAt, firstChunkReceivedAt, signatureStartedAt, signatureEndedAt, recordingStopRequestedAt, lastChunkReceivedAt, mediaInfo;
14397
+ var _b;
14398
+ return __generator(this, function (_c) {
14399
+ switch (_c.label) {
14400
+ case 0:
14401
+ recordingStoppedAt = performance.now();
14402
+ set({
14403
+ recordingStoppedAt: recordingStoppedAt
14404
+ });
14405
+ inferredType = inferBlobType(signatureChunks[0]) || (signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.mimeType) || 'video/mp4';
14406
+ blob = new Blob(signatureChunks, {
14407
+ type: inferredType
14408
+ });
14409
+ signatureChunks = [];
14410
+ signatureRecorder = null;
14411
+ if (!signatureData) return [2 /*return*/];
14412
+ _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;
14413
+ return [4 /*yield*/, (_b = get().mediaInfo) === null || _b === void 0 ? void 0 : _b.analyzeData(blob.size, makeReadChunk(blob))];
14414
+ case 1:
14415
+ mediaInfo = _c.sent();
14416
+ onSignatureVideoCaptured(blob, signatureData, imageUrl !== null && imageUrl !== void 0 ? imageUrl : null, {
14417
+ mediaInfo: mediaInfo,
14418
+ mimeType: inferredType,
14419
+ timingData: {
14420
+ recordingStartRequestedAt: recordingStartRequestedAt,
14421
+ recordingStartedAt: recordingStartedAt,
14422
+ firstChunkReceivedAt: firstChunkReceivedAt,
14423
+ signatureStartedAt: signatureStartedAt,
14424
+ signatureEndedAt: signatureEndedAt,
14425
+ recordingStopRequestedAt: recordingStopRequestedAt,
14426
+ recordingStoppedAt: recordingStoppedAt,
14427
+ lastChunkReceivedAt: lastChunkReceivedAt
14428
+ }
14429
+ });
14430
+ return [2 /*return*/];
14431
+ }
14420
14432
  });
14421
14433
  });
14422
14434
  };
@@ -14466,7 +14478,9 @@ function waitForOneMoreChunk(timeoutMs) {
14466
14478
  function VideoSignatureContextProvider(_a) {
14467
14479
  var _this = this;
14468
14480
  var _b, _c, _d, _e;
14469
- var children = _a.children;
14481
+ var children = _a.children,
14482
+ _f = _a.captureMediaInfo,
14483
+ captureMediaInfo = _f === void 0 ? false : _f;
14470
14484
  var videoRef = useCameraStore().videoRef;
14471
14485
  var outputCanvas = useRef(null);
14472
14486
  useEffect(function () {
@@ -14476,27 +14490,31 @@ function VideoSignatureContextProvider(_a) {
14476
14490
  }, []);
14477
14491
  var signatureVideoRef = useRef(null);
14478
14492
  var frameCheckCanvas = useRef(null);
14479
- // useEffect(() => {
14480
- // if (!captureMediaInfo) return
14481
- // mediaInfoFactory({
14482
- // format: 'object',
14483
- // full: true,
14484
- // locateFile: (filename) => `${DEFAULT_CDN_URL}/${filename}`,
14485
- // })
14486
- // .then((mediaInfo) => {
14487
- // useVideoSignatureStore.setState({ mediaInfo })
14488
- // })
14489
- // .catch((e) => {
14490
- // warn('error loading mediaInfo', e)
14491
- // })
14492
- // return () => {
14493
- // const mediaInfo = useVideoSignatureStore.getState().mediaInfo
14494
- // if (mediaInfo) {
14495
- // mediaInfo.close()
14496
- // useVideoSignatureStore.setState({ mediaInfo: undefined })
14497
- // }
14498
- // }
14499
- // }, [captureMediaInfo])
14493
+ useEffect(function () {
14494
+ if (!captureMediaInfo) return;
14495
+ mediaInfoFactory({
14496
+ format: 'object',
14497
+ full: true,
14498
+ locateFile: function locateFile(filename) {
14499
+ return "".concat(DEFAULT_CDN_URL, "/").concat(filename);
14500
+ }
14501
+ }).then(function (mediaInfo) {
14502
+ useVideoSignatureStore.setState({
14503
+ mediaInfo: mediaInfo
14504
+ });
14505
+ })["catch"](function (e) {
14506
+ warn('error loading mediaInfo', e);
14507
+ });
14508
+ return function () {
14509
+ var mediaInfo = useVideoSignatureStore.getState().mediaInfo;
14510
+ if (mediaInfo) {
14511
+ mediaInfo.close();
14512
+ useVideoSignatureStore.setState({
14513
+ mediaInfo: undefined
14514
+ });
14515
+ }
14516
+ };
14517
+ }, [captureMediaInfo]);
14500
14518
  var signaturePadEmpty = useVideoSignatureStore().signaturePadEmpty;
14501
14519
  var blankCheckPassed = useRef(false);
14502
14520
  useEffect(function () {
@@ -14537,40 +14555,15 @@ function VideoSignatureContextProvider(_a) {
14537
14555
  });
14538
14556
  });
14539
14557
  }, [videoRef, outputCanvas]);
14540
- useEffect(function () {
14541
- if (!signatureVideoRef.current) return;
14542
- var video = signatureVideoRef.current;
14543
- function onFrame() {
14544
- blankCheckPassed.current || (blankCheckPassed.current = !isVideoBlank(signatureVideoRef.current, frameCheckCanvas.current));
14545
- drawOutputFrame();
14546
- video.requestVideoFrameCallback(onFrame);
14547
- }
14548
- function onPlay() {
14549
- video.requestVideoFrameCallback(onFrame);
14550
- }
14551
- video.addEventListener('play', onPlay);
14552
- return function () {
14553
- video.removeEventListener('play', onPlay);
14554
- };
14555
- }, [drawOutputFrame]);
14556
- useEffect(function () {
14557
- if (!videoRef.current) return;
14558
- var video = videoRef.current;
14559
- function onFrame() {
14560
- drawOutputFrame();
14561
- video.requestVideoFrameCallback(onFrame);
14562
- }
14563
- function onPlay() {
14564
- video.requestVideoFrameCallback(onFrame);
14565
- }
14566
- video.addEventListener('play', onPlay);
14567
- return function () {
14568
- video.removeEventListener('play', onPlay);
14569
- };
14570
- }, [drawOutputFrame, videoRef]);
14571
- var _f = useVideoSignatureStore(),
14572
- signaturePad = _f.signaturePad,
14573
- recordingStartedAt = _f.recordingStartedAt;
14558
+ var checkBlankAndDrawOutputFrame = useCallback(function () {
14559
+ blankCheckPassed.current || (blankCheckPassed.current = !isVideoBlank(signatureVideoRef.current, frameCheckCanvas.current));
14560
+ drawOutputFrame();
14561
+ }, [drawOutputFrame, signatureVideoRef]);
14562
+ useVideoFrameLoop(signatureVideoRef, checkBlankAndDrawOutputFrame);
14563
+ useVideoFrameLoop(videoRef, drawOutputFrame);
14564
+ var _g = useVideoSignatureStore(),
14565
+ signaturePad = _g.signaturePad,
14566
+ recordingStartedAt = _g.recordingStartedAt;
14574
14567
  useEffect(function () {
14575
14568
  var _a;
14576
14569
  if (!signaturePad.current || !recordingStartedAt) return;
@@ -14610,6 +14603,32 @@ function isCanvasBlank(canvas) {
14610
14603
  });
14611
14604
  return result;
14612
14605
  }
14606
+ function requestVideoFrameCallback(video, onFrame) {
14607
+ if (typeof (video === null || video === void 0 ? void 0 : video.requestVideoFrameCallback) === 'function') {
14608
+ video.requestVideoFrameCallback(onFrame);
14609
+ } else {
14610
+ requestAnimationFrame(onFrame);
14611
+ }
14612
+ }
14613
+ function videoFrameLoop(video, onFrame) {
14614
+ if (!video) return;
14615
+ function onFrameRecursive() {
14616
+ onFrame();
14617
+ requestVideoFrameCallback(video, onFrameRecursive);
14618
+ }
14619
+ function onPlay() {
14620
+ requestVideoFrameCallback(video, onFrameRecursive);
14621
+ }
14622
+ video.addEventListener('play', onPlay);
14623
+ return function () {
14624
+ video.removeEventListener('play', onPlay);
14625
+ };
14626
+ }
14627
+ function useVideoFrameLoop(ref, onFrame) {
14628
+ useEffect(function () {
14629
+ return videoFrameLoop(ref.current, onFrame);
14630
+ }, [onFrame, ref]);
14631
+ }
14613
14632
 
14614
14633
  function VideoSignaturePad(_a) {
14615
14634
  var onAcceptBtnClicked = _a.onAcceptBtnClicked,