idmission-web-sdk 2.3.92 → 2.3.94

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.92';
209
+ var webSdkVersion = '2.3.94';
209
210
 
210
211
  function getPlatform() {
211
212
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -1153,10 +1154,7 @@ var SubmissionContext = /*#__PURE__*/createContext({
1153
1154
  setIdCaptureVideoUrl: function setIdCaptureVideoUrl() {
1154
1155
  return null;
1155
1156
  },
1156
- setSignatureStartTimestamp: function setSignatureStartTimestamp() {
1157
- return null;
1158
- },
1159
- setSignatureEndTimestamp: function setSignatureEndTimestamp() {
1157
+ setSignatureVideoMetadata: function setSignatureVideoMetadata() {
1160
1158
  return null;
1161
1159
  },
1162
1160
  setIdCaptureVideoIdFrontImage: function setIdCaptureVideoIdFrontImage() {
@@ -1326,50 +1324,47 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1326
1324
  signatureVideoUrl = _17[0],
1327
1325
  setSignatureVideoUrl = _17[1];
1328
1326
  var _18 = useState(null),
1329
- signatureStartTimestamp = _18[0],
1330
- setSignatureStartTimestamp = _18[1];
1327
+ signatureVideoMetadata = _18[0],
1328
+ setSignatureVideoMetadata = _18[1];
1331
1329
  var _19 = useState(null),
1332
- signatureEndTimestamp = _19[0],
1333
- setSignatureEndTimestamp = _19[1];
1330
+ idCaptureVideoUrl = _19[0],
1331
+ setIdCaptureVideoUrl = _19[1];
1334
1332
  var _20 = useState(null),
1335
- idCaptureVideoUrl = _20[0],
1336
- setIdCaptureVideoUrl = _20[1];
1333
+ idCaptureVideoIdFrontImage = _20[0],
1334
+ setIdCaptureVideoIdFrontImage = _20[1];
1337
1335
  var _21 = useState(null),
1338
- idCaptureVideoIdFrontImage = _21[0],
1339
- setIdCaptureVideoIdFrontImage = _21[1];
1336
+ idCaptureVideoIdBackImage = _21[0],
1337
+ setIdCaptureVideoIdBackImage = _21[1];
1340
1338
  var _22 = useState(null),
1341
- idCaptureVideoIdBackImage = _22[0],
1342
- setIdCaptureVideoIdBackImage = _22[1];
1339
+ idCaptureVideoAudioUrl = _22[0],
1340
+ setIdCaptureVideoAudioUrl = _22[1];
1343
1341
  var _23 = useState(null),
1344
- idCaptureVideoAudioUrl = _23[0],
1345
- setIdCaptureVideoAudioUrl = _23[1];
1342
+ idCaptureVideoAudioStartsAt = _23[0],
1343
+ setIdCaptureVideoAudioStartsAt = _23[1];
1346
1344
  var _24 = useState(null),
1347
- idCaptureVideoAudioStartsAt = _24[0],
1348
- setIdCaptureVideoAudioStartsAt = _24[1];
1345
+ expectedAudioText = _24[0],
1346
+ setExpectedAudioText = _24[1];
1349
1347
  var _25 = useState(null),
1350
- expectedAudioText = _25[0],
1351
- setExpectedAudioText = _25[1];
1348
+ additionalDocuments = _25[0],
1349
+ setAdditionalDocuments = _25[1];
1352
1350
  var _26 = useState(null),
1353
- additionalDocuments = _26[0],
1354
- setAdditionalDocuments = _26[1];
1355
- var _27 = useState(null),
1356
- geolocationResult = _27[0],
1357
- setGeolocationResult = _27[1];
1358
- var _28 = useState(0),
1359
- geolocationAttempts = _28[0],
1360
- setGeolocationAttempts = _28[1];
1361
- var _29 = useState(false),
1362
- geolocationBlocked = _29[0],
1363
- setGeolocationBlocked = _29[1];
1351
+ geolocationResult = _26[0],
1352
+ setGeolocationResult = _26[1];
1353
+ var _27 = useState(0),
1354
+ geolocationAttempts = _27[0],
1355
+ setGeolocationAttempts = _27[1];
1356
+ var _28 = useState(false),
1357
+ geolocationBlocked = _28[0],
1358
+ setGeolocationBlocked = _28[1];
1359
+ var _29 = useState([]),
1360
+ idFrontCaptureAttempts = _29[0],
1361
+ setIdFrontCaptureAttempts = _29[1];
1364
1362
  var _30 = useState([]),
1365
- idFrontCaptureAttempts = _30[0],
1366
- setIdFrontCaptureAttempts = _30[1];
1363
+ idBackCaptureAttempts = _30[0],
1364
+ setIdBackCaptureAttempts = _30[1];
1367
1365
  var _31 = useState([]),
1368
- idBackCaptureAttempts = _31[0],
1369
- setIdBackCaptureAttempts = _31[1];
1370
- var _32 = useState([]),
1371
- selfieCaptureAttempts = _32[0],
1372
- setSelfieCaptureAttempts = _32[1];
1366
+ selfieCaptureAttempts = _31[0],
1367
+ setSelfieCaptureAttempts = _31[1];
1373
1368
  var logIdFrontCaptureAttempt = useCallback(function (attempt) {
1374
1369
  setIdFrontCaptureAttempts(function (attempts) {
1375
1370
  return __spreadArray(__spreadArray([], attempts, true), [attempt], false);
@@ -1466,19 +1461,22 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1466
1461
  var buildSubmissionPayload = useCallback(function () {
1467
1462
  return __awaiter(void 0, void 0, void 0, function () {
1468
1463
  function uploadIfPossible(src_1, filename_1) {
1469
- return __awaiter(this, arguments, void 0, function (src, filename, filetype) {
1464
+ return __awaiter(this, arguments, void 0, function (src, filename, filetype, metadata) {
1470
1465
  if (filetype === void 0) {
1471
1466
  filetype = 'image/jpeg';
1472
1467
  }
1468
+ if (metadata === void 0) {
1469
+ metadata = {};
1470
+ }
1473
1471
  return __generator(this, function (_a) {
1474
1472
  switch (_a.label) {
1475
1473
  case 0:
1476
1474
  if (!documentServiceUrl) return [2 /*return*/, src];
1477
1475
  if (!src.startsWith('data:')) src = "data:".concat(filetype, ";base64,").concat(src);
1478
- return [4 /*yield*/, uploadDocument(src, {
1476
+ return [4 /*yield*/, uploadDocument(src, _assign({
1479
1477
  filename: filename,
1480
1478
  filetype: filetype
1481
- })];
1479
+ }, metadata))];
1482
1480
  case 1:
1483
1481
  return [2 /*return*/, _a.sent()];
1484
1482
  }
@@ -1487,9 +1485,9 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1487
1485
  }
1488
1486
  var documents, _a, _b, _c, submissionRequest, onBeforeSubmitResult;
1489
1487
  var _d;
1490
- var _e, _f, _g, _h;
1491
- return __generator(this, function (_j) {
1492
- switch (_j.label) {
1488
+ var _e, _f, _g, _h, _j;
1489
+ return __generator(this, function (_k) {
1490
+ switch (_k.label) {
1493
1491
  case 0:
1494
1492
  _d = {
1495
1493
  idFrontImage: idFrontImage,
@@ -1502,24 +1500,24 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1502
1500
  if (!_a) return [3 /*break*/, 2];
1503
1501
  return [4 /*yield*/, videoDataUrlToB64(signatureVideoUrl)];
1504
1502
  case 1:
1505
- _a = _j.sent();
1506
- _j.label = 2;
1503
+ _a = _k.sent();
1504
+ _k.label = 2;
1507
1505
  case 2:
1508
1506
  _d.signatureVideo = _a;
1509
1507
  _b = idCaptureVideoUrl;
1510
1508
  if (!_b) return [3 /*break*/, 4];
1511
1509
  return [4 /*yield*/, videoDataUrlToB64(idCaptureVideoUrl)];
1512
1510
  case 3:
1513
- _b = _j.sent();
1514
- _j.label = 4;
1511
+ _b = _k.sent();
1512
+ _k.label = 4;
1515
1513
  case 4:
1516
1514
  _d.idCaptureVideo = _b;
1517
1515
  _c = idCaptureVideoAudioUrl;
1518
1516
  if (!_c) return [3 /*break*/, 6];
1519
1517
  return [4 /*yield*/, videoDataUrlToB64(idCaptureVideoAudioUrl)];
1520
1518
  case 5:
1521
- _c = _j.sent();
1522
- _j.label = 6;
1519
+ _c = _k.sent();
1520
+ _k.label = 6;
1523
1521
  case 6:
1524
1522
  documents = (_d.idCaptureVideoAudio = _c, _d.idCaptureVideoIdFrontImage = idCaptureVideoIdFrontImage, _d.idCaptureVideoIdBackImage = idCaptureVideoIdBackImage, _d.idFrontIrImage = idFrontIrImage, _d.idBackIrImage = idBackIrImage, _d.idFrontUvImage = idFrontUvImage, _d.idBackUvImage = idBackUvImage, _d);
1525
1523
  if (signatureData) {
@@ -1528,15 +1526,18 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1528
1526
  if (!documentServiceUrl) return [3 /*break*/, 8];
1529
1527
  return [4 /*yield*/, Promise.all(Object.keys(documents).map(function (k) {
1530
1528
  return __awaiter(void 0, void 0, void 0, function () {
1531
- var filetype, _a, _b;
1529
+ var filetype, metadata, _a, _b;
1532
1530
  return __generator(this, function (_c) {
1533
1531
  switch (_c.label) {
1534
1532
  case 0:
1535
1533
  if (!documents[k]) return [3 /*break*/, 2];
1536
1534
  filetype = k.endsWith('Video') ? 'video/mp4' : k.endsWith('Audio') ? 'audio/mp4' : 'image/jpeg';
1535
+ metadata = k === 'signatureVideo' ? {
1536
+ filemetadata: JSON.stringify(signatureVideoMetadata)
1537
+ } : {};
1537
1538
  _a = documents;
1538
1539
  _b = k;
1539
- return [4 /*yield*/, uploadIfPossible(documents[k], k, filetype)];
1540
+ return [4 /*yield*/, uploadIfPossible(documents[k], k, filetype, metadata)];
1540
1541
  case 1:
1541
1542
  _a[_b] = _c.sent();
1542
1543
  _c.label = 2;
@@ -1549,8 +1550,8 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1549
1550
  throw new NetworkError(e.message);
1550
1551
  })];
1551
1552
  case 7:
1552
- _j.sent();
1553
- _j.label = 8;
1553
+ _k.sent();
1554
+ _k.label = 8;
1554
1555
  case 8:
1555
1556
  submissionRequest = {
1556
1557
  securityData: {
@@ -1650,11 +1651,9 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1650
1651
  submissionRequest.customerData.signatureData.signatureVideo = documents.signatureVideo;
1651
1652
  }
1652
1653
  }
1653
- if (signatureStartTimestamp) {
1654
- submissionRequest.customerData.signatureStartTimestamp = signatureStartTimestamp;
1655
- }
1656
- if (signatureEndTimestamp) {
1657
- submissionRequest.customerData.signatureEndTimestamp = signatureEndTimestamp;
1654
+ if (signatureVideoMetadata) {
1655
+ (_g = submissionRequest.customerData).signatureData || (_g.signatureData = {});
1656
+ submissionRequest.customerData.signatureData.signatureVideoMetadata = signatureVideoMetadata;
1658
1657
  }
1659
1658
  if (additionalDocuments) {
1660
1659
  submissionRequest.customerData.additionalDocuments = additionalDocuments.map(function (d) {
@@ -1666,11 +1665,11 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1666
1665
  });
1667
1666
  }
1668
1667
  if (documents.idCaptureVideo) {
1669
- (_g = submissionRequest.customerData).biometricData || (_g.biometricData = {});
1668
+ (_h = submissionRequest.customerData).biometricData || (_h.biometricData = {});
1670
1669
  submissionRequest.customerData.biometricData.videoData = documents.idCaptureVideo;
1671
1670
  }
1672
1671
  if (documents.idCaptureVideoAudio) {
1673
- (_h = submissionRequest.customerData).biometricData || (_h.biometricData = {});
1672
+ (_j = submissionRequest.customerData).biometricData || (_j.biometricData = {});
1674
1673
  submissionRequest.customerData.biometricData.voiceData = documents.idCaptureVideoAudio;
1675
1674
  submissionRequest.customerData.biometricData.voiceStartTime = idCaptureVideoAudioStartsAt !== null && idCaptureVideoAudioStartsAt !== void 0 ? idCaptureVideoAudioStartsAt : undefined;
1676
1675
  submissionRequest.customerData.biometricData.expectedAudioText = expectedAudioText !== null && expectedAudioText !== void 0 ? expectedAudioText : undefined;
@@ -1690,15 +1689,15 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1690
1689
  if (!onBeforeSubmit.current) return [3 /*break*/, 10];
1691
1690
  return [4 /*yield*/, onBeforeSubmit.current(submissionRequest)];
1692
1691
  case 9:
1693
- onBeforeSubmitResult = _j.sent();
1692
+ onBeforeSubmitResult = _k.sent();
1694
1693
  if (onBeforeSubmitResult) submissionRequest = onBeforeSubmitResult;
1695
- _j.label = 10;
1694
+ _k.label = 10;
1696
1695
  case 10:
1697
1696
  return [2 /*return*/, submissionRequest];
1698
1697
  }
1699
1698
  });
1700
1699
  });
1701
- }, [additionalDocuments, bypassAgeValidation, bypassNameMatching, cardData, clientRequestID, companyId, customerDataMatchConfig, deduplicationEnabled, deduplicationSynchronous, documentServiceUrl, enrollmentId, expectedAudioText, geolocationResult, idBackCaptureAttempts, idBackImage, idBackImageRequired, idBackIrImage, idBackUvImage, idBarcodeImage, idCaptureVideoAudioStartsAt, idCaptureVideoAudioUrl, idCaptureVideoIdBackImage, idCaptureVideoIdFrontImage, idCaptureVideoUrl, idCardForFaceMatch, idData, idFrontCaptureAttempts, idFrontImage, idFrontIrImage, idFrontUvImage, idImageResolutionCheck, jobId, manualReviewRequired, needImmediateResponse, passportImage, personalData, selfieCaptureAttempts, selfieImage, signatureData, signatureEndTimestamp, signatureStartTimestamp, signatureVideoUrl, uploadDocument, verifyIdWithExternalDatabases, webhooksClientTraceId, webhooksEnabled, webhooksFireOnReview, webhooksFireOnReviewURL, webhooksSendInputImages, webhooksSendProcessedImages, webhooksStripSpecialCharacters, webhooksURL]);
1700
+ }, [additionalDocuments, bypassAgeValidation, bypassNameMatching, cardData, clientRequestID, companyId, customerDataMatchConfig, deduplicationEnabled, deduplicationSynchronous, documentServiceUrl, enrollmentId, expectedAudioText, geolocationResult, idBackCaptureAttempts, idBackImage, idBackImageRequired, idBackIrImage, idBackUvImage, idBarcodeImage, idCaptureVideoAudioStartsAt, idCaptureVideoAudioUrl, idCaptureVideoIdBackImage, idCaptureVideoIdFrontImage, idCaptureVideoUrl, idCardForFaceMatch, idData, idFrontCaptureAttempts, idFrontImage, idFrontIrImage, idFrontUvImage, idImageResolutionCheck, jobId, manualReviewRequired, needImmediateResponse, passportImage, personalData, selfieCaptureAttempts, selfieImage, signatureData, signatureVideoUrl, signatureVideoMetadata, uploadDocument, verifyIdWithExternalDatabases, webhooksClientTraceId, webhooksEnabled, webhooksFireOnReview, webhooksFireOnReviewURL, webhooksSendInputImages, webhooksSendProcessedImages, webhooksStripSpecialCharacters, webhooksURL]);
1702
1701
  var defaultOnSubmit = useCallback(function () {
1703
1702
  return __awaiter(void 0, void 0, void 0, function () {
1704
1703
  var submissionResponse_1, payload, host, endpoint, response, statusMessage, submissionResponse_2, e_1, err;
@@ -1997,8 +1996,7 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1997
1996
  setSelfieImage: setSelfieImage,
1998
1997
  setSignatureData: setSignatureData,
1999
1998
  setSignatureVideoUrl: setSignatureVideoUrl,
2000
- setSignatureStartTimestamp: setSignatureStartTimestamp,
2001
- setSignatureEndTimestamp: setSignatureEndTimestamp,
1999
+ setSignatureVideoMetadata: setSignatureVideoMetadata,
2002
2000
  setIdCaptureVideoUrl: setIdCaptureVideoUrl,
2003
2001
  setIdCaptureVideoIdFrontImage: setIdCaptureVideoIdFrontImage,
2004
2002
  setIdCaptureVideoIdBackImage: setIdCaptureVideoIdBackImage,
@@ -14298,194 +14296,23 @@ function inferBlobType(blobPart) {
14298
14296
  return t.length > 0 ? t : undefined;
14299
14297
  }
14300
14298
 
14301
- var videoRecorder = null;
14302
- var audioRecorder = null;
14303
- var videoChunks = [];
14304
- var audioChunks = [];
14305
- function setVideoRecorder(recorder) {
14306
- videoRecorder = recorder;
14307
- }
14308
- function setAudioRecorder(recorder) {
14309
- audioRecorder = recorder;
14310
- }
14311
- function clearVideoChunks() {
14312
- videoChunks = [];
14313
- }
14314
- function clearAudioChunks() {
14315
- audioChunks = [];
14316
- }
14317
- var initialState$2 = {
14318
- videoUrl: null,
14319
- audioUrl: null,
14320
- isRecordingVideo: false,
14321
- isRecordingAudio: false,
14322
- videoRecordingStopped: false,
14323
- audioRecordingStopped: false,
14324
- videoRecordingIntentionallyStopped: false,
14325
- audioRecordingIntentionallyStopped: false,
14326
- mergeAVStreams: false
14327
- };
14328
- var useVideoRecorderStore = create()(devtools(function (set, get) {
14329
- return _assign(_assign({}, initialState$2), {
14330
- startRecordingVideo: function startRecordingVideo(captureAudio) {
14331
- var _a, _b, _c;
14332
- if (captureAudio === void 0) {
14333
- captureAudio = false;
14334
- }
14335
- if (!camera) throw new Error('Camera not found');
14336
- var _d = get(),
14337
- mergeAVStreams = _d.mergeAVStreams,
14338
- startRecordingAudio = _d.startRecordingAudio;
14339
- var videoStream = mergeAVStreams ? new MediaStream(__spreadArray(__spreadArray([], (_b = (_a = camera === null || camera === void 0 ? void 0 : camera.stream) === null || _a === void 0 ? void 0 : _a.getTracks()) !== null && _b !== void 0 ? _b : [], true), captureAudio ? (_c = audioStream === null || audioStream === void 0 ? void 0 : audioStream.getTracks()) !== null && _c !== void 0 ? _c : [] : [], true)) : camera.stream;
14340
- if (!videoStream) return;
14341
- clearVideoChunks();
14342
- videoRecorder = null;
14343
- set({
14344
- isRecordingVideo: true,
14345
- videoRecordingStopped: false,
14346
- videoRecordingIntentionallyStopped: false
14347
- });
14348
- videoRecorder = new MediaRecorder(videoStream, {
14349
- videoBitsPerSecond: 270000,
14350
- audioBitsPerSecond: 32000
14351
- });
14352
- videoRecorder.ondataavailable = function (e) {
14353
- videoChunks.push(e.data);
14354
- };
14355
- videoRecorder.onstop = function () {
14356
- set({
14357
- videoRecordingStopped: true
14358
- });
14359
- };
14360
- videoRecorder.start(100);
14361
- setTimeout(function () {
14362
- if (!videoRecorder || videoRecorder.state === 'inactive') {
14363
- log('media recorder is inactive!');
14364
- // TODO: figure out what to do here
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()]))()];
14365
14311
  }
14366
- }, 100);
14367
- if (captureAudio && !mergeAVStreams) {
14368
- startRecordingAudio();
14369
- }
14370
- },
14371
- stopRecordingVideo: function stopRecordingVideo() {
14372
- set({
14373
- videoRecordingIntentionallyStopped: true
14374
14312
  });
14375
- if ((videoRecorder === null || videoRecorder === void 0 ? void 0 : videoRecorder.state) !== 'inactive') {
14376
- videoRecorder === null || videoRecorder === void 0 ? void 0 : videoRecorder.stop(); // if you call this while state === 'inactive', an exception is thrown.
14377
- }
14378
- },
14379
- startRecordingAudio: function startRecordingAudio() {
14380
- if (get().mergeAVStreams) return;
14381
- if (!audioStream) return;
14382
- clearAudioChunks();
14383
- set({
14384
- isRecordingAudio: true,
14385
- audioRecordingStopped: false,
14386
- audioRecordingIntentionallyStopped: false
14387
- });
14388
- var audioRecorder = new MediaRecorder(audioStream, {
14389
- audioBitsPerSecond: 32000
14390
- });
14391
- setAudioRecorder(audioRecorder);
14392
- audioRecorder.ondataavailable = function (e) {
14393
- audioChunks.push(e.data);
14394
- };
14395
- audioRecorder.onstop = function () {
14396
- set({
14397
- audioRecordingStopped: true
14398
- });
14399
- };
14400
- audioRecorder.start(100);
14401
- },
14402
- stopRecordingAudio: function stopRecordingAudio() {
14403
- set({
14404
- audioRecordingIntentionallyStopped: true
14405
- });
14406
- if ((audioRecorder === null || audioRecorder === void 0 ? void 0 : audioRecorder.state) !== 'inactive') {
14407
- audioRecorder === null || audioRecorder === void 0 ? void 0 : audioRecorder.stop(); // if you call this while state === 'inactive', an exception is thrown.
14408
- }
14409
- },
14410
- stopRecording: function stopRecording() {
14411
- get().stopRecordingVideo();
14412
- get().stopRecordingAudio();
14413
- },
14414
- clearRecordedData: function clearRecordedData() {
14415
- clearVideoChunks();
14416
- clearAudioChunks();
14417
- }
14418
- });
14419
- }));
14420
- var useVideoRecorder = function useVideoRecorder(mergeAVStreams) {
14421
- if (mergeAVStreams === void 0) {
14422
- mergeAVStreams = false;
14423
- }
14424
- useEffect(function () {
14425
- return useVideoRecorderStore.setState({
14426
- mergeAVStreams: mergeAVStreams
14427
- });
14428
- }, [mergeAVStreams]);
14429
- useEffect(function () {
14430
- // clear recorded data when the component is mounted
14431
- useVideoRecorderStore.getState().clearRecordedData();
14432
- }, []);
14433
- var processVideo = useCallback(function () {
14434
- var inferredType = inferBlobType(videoChunks[0]) || (videoRecorder === null || videoRecorder === void 0 ? void 0 : videoRecorder.mimeType) || 'video/mp4';
14435
- var videoBlob = new Blob(videoChunks, {
14436
- type: inferredType
14437
- });
14438
- useVideoRecorderStore.setState({
14439
- videoUrl: URL.createObjectURL(videoBlob),
14440
- isRecordingVideo: false
14441
14313
  });
14442
- clearVideoChunks();
14443
- setVideoRecorder(null);
14444
- }, []);
14445
- var processAudio = useCallback(function () {
14446
- var inferredType = inferBlobType(audioChunks[0]) || (audioRecorder === null || audioRecorder === void 0 ? void 0 : audioRecorder.mimeType) || 'audio/mp4';
14447
- var audioBlob = new Blob(audioChunks, {
14448
- type: inferredType
14449
- });
14450
- useVideoRecorderStore.setState({
14451
- audioUrl: URL.createObjectURL(audioBlob),
14452
- isRecordingAudio: false
14453
- });
14454
- clearAudioChunks();
14455
- setAudioRecorder(null);
14456
- }, []);
14457
- var _a = useVideoRecorderStore(),
14458
- videoUrl = _a.videoUrl,
14459
- audioUrl = _a.audioUrl,
14460
- isRecordingVideo = _a.isRecordingVideo,
14461
- isRecordingAudio = _a.isRecordingAudio,
14462
- videoRecordingStopped = _a.videoRecordingStopped,
14463
- videoRecordingIntentionallyStopped = _a.videoRecordingIntentionallyStopped,
14464
- audioRecordingStopped = _a.audioRecordingStopped,
14465
- audioRecordingIntentionallyStopped = _a.audioRecordingIntentionallyStopped;
14466
- useEffect(function () {
14467
- if (videoRecordingStopped && videoRecordingIntentionallyStopped) {
14468
- processVideo();
14469
- }
14470
- }, [processVideo, videoRecordingIntentionallyStopped, videoRecordingStopped]);
14471
- useEffect(function () {
14472
- if (audioRecordingStopped && audioRecordingIntentionallyStopped) {
14473
- processAudio();
14474
- }
14475
- }, [audioRecordingIntentionallyStopped, audioRecordingStopped, processAudio]);
14476
- return useMemo(function () {
14477
- return {
14478
- isRecordingVideo: isRecordingVideo,
14479
- isRecordingAudio: isRecordingAudio,
14480
- videoRecordingUnintentionallyStopped: videoRecordingStopped && !videoRecordingIntentionallyStopped,
14481
- audioRecordingUnintentionallyStopped: audioRecordingStopped && !audioRecordingIntentionallyStopped,
14482
- videoUrl: videoUrl,
14483
- audioUrl: audioUrl
14484
- };
14485
- }, [audioRecordingIntentionallyStopped, audioRecordingStopped, audioUrl, isRecordingAudio, isRecordingVideo, videoRecordingIntentionallyStopped, videoRecordingStopped, videoUrl]);
14486
- };
14487
-
14488
- var RECORDING_TIMESTAMP_PADDING_MS = 1000;
14314
+ };
14315
+ }
14489
14316
  var signatureRecorder = null;
14490
14317
  var signatureChunks = [];
14491
14318
  var videoSignatureInitialState = {
@@ -14513,27 +14340,31 @@ var videoSignatureInitialState = {
14513
14340
  var useVideoSignatureStore = create()(devtools(function (set, get) {
14514
14341
  return _assign(_assign({}, videoSignatureInitialState), {
14515
14342
  startRecording: function startRecording(captureAudio) {
14516
- var _a;
14343
+ var _a, _b;
14517
14344
  if (captureAudio === void 0) {
14518
14345
  captureAudio = false;
14519
14346
  }
14520
14347
  if (!camera) throw new Error('Camera not found');
14521
14348
  // set our flag and clear whatever we have recorded so far.
14522
- set({
14523
- recordingStartedAt: performance.now()
14524
- });
14525
14349
  signatureChunks = [];
14526
- // start recording video and audio
14527
- useVideoRecorderStore.getState().startRecordingVideo(captureAudio);
14350
+ var outputCanvas = get().outputCanvas;
14528
14351
  // start recording from the output canvas to capture the signature
14529
- var videoStream = get().outputCanvas.current.captureStream(24); // fps
14530
- var tracks = [videoStream.getVideoTracks()[0]];
14531
- var audioTrack = (_a = audioStream === null || audioStream === void 0 ? void 0 : audioStream.getAudioTracks()) === null || _a === void 0 ? void 0 : _a[0];
14532
- if (audioTrack) tracks.push(audioTrack);
14352
+ var outputStream = (_a = outputCanvas.current) === null || _a === void 0 ? void 0 : _a.captureStream(24);
14353
+ if (!outputStream) throw new Error('outputStream not found');
14354
+ var tracks = [outputStream.getVideoTracks()[0]];
14355
+ if (captureAudio) {
14356
+ var audioTrack = (_b = audioStream === null || audioStream === void 0 ? void 0 : audioStream.getAudioTracks()) === null || _b === void 0 ? void 0 : _b[0];
14357
+ if (audioTrack) tracks.push(audioTrack);
14358
+ }
14533
14359
  signatureRecorder = new MediaRecorder(new MediaStream(tracks), {
14534
- videoBitsPerSecond: 270000,
14360
+ videoBitsPerSecond: 650000,
14535
14361
  audioBitsPerSecond: 32000
14536
14362
  });
14363
+ signatureRecorder.onstart = function () {
14364
+ set({
14365
+ recordingStartedAt: performance.now()
14366
+ });
14367
+ };
14537
14368
  var hasFirstChunk = false;
14538
14369
  signatureRecorder.ondataavailable = function (event) {
14539
14370
  signatureChunks.push(event.data);
@@ -14552,39 +14383,101 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14552
14383
  signatureRecorder.start(100);
14553
14384
  },
14554
14385
  stopRecording: function stopRecording(signatureData, imageUrl) {
14555
- set({
14556
- firstChunkReceivedAt: undefined,
14557
- recordingStoppedAt: performance.now()
14558
- });
14559
14386
  waitForOneMoreChunk().then(function () {
14560
14387
  if (!signatureRecorder) return;
14561
14388
  signatureRecorder.stop();
14562
14389
  signatureRecorder.onstop = function () {
14563
- var inferredType = inferBlobType(signatureChunks[0]) || (signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.mimeType) || 'video/mp4';
14564
- var blob = new Blob(signatureChunks, {
14565
- type: inferredType
14390
+ return __awaiter(void 0, void 0, void 0, function () {
14391
+ var recordingStoppedAt, inferredType, blob, _a, onSignatureVideoCaptured, recordingStartedAt, firstChunkReceivedAt, signatureStartedAt, signatureEndedAt, lastChunkReceivedAt, mediaInfo;
14392
+ var _b;
14393
+ return __generator(this, function (_c) {
14394
+ switch (_c.label) {
14395
+ case 0:
14396
+ recordingStoppedAt = performance.now();
14397
+ set({
14398
+ recordingStoppedAt: recordingStoppedAt
14399
+ });
14400
+ inferredType = inferBlobType(signatureChunks[0]) || (signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.mimeType) || 'video/mp4';
14401
+ blob = new Blob(signatureChunks, {
14402
+ type: inferredType
14403
+ });
14404
+ signatureChunks = [];
14405
+ signatureRecorder = null;
14406
+ if (!signatureData) return [2 /*return*/];
14407
+ _a = get(), onSignatureVideoCaptured = _a.onSignatureVideoCaptured, recordingStartedAt = _a.recordingStartedAt, firstChunkReceivedAt = _a.firstChunkReceivedAt, signatureStartedAt = _a.signatureStartedAt, signatureEndedAt = _a.signatureEndedAt, lastChunkReceivedAt = _a.lastChunkReceivedAt;
14408
+ return [4 /*yield*/, (_b = get().mediaInfo) === null || _b === void 0 ? void 0 : _b.analyzeData(blob.size, makeReadChunk(blob))
14409
+ // const endMs = Math.min(
14410
+ // signatureEndedAt ?? Infinity,
14411
+ // lastChunkReceivedAt ?? Infinity,
14412
+ // )
14413
+ // const signatureStartTimestamp =
14414
+ // signatureStartedAt && recordingStartedAt
14415
+ // ? formatTimestamp(
14416
+ // Math.max(
14417
+ // 0,
14418
+ // signatureStartedAt -
14419
+ // recordingStartedAt -
14420
+ // RECORDING_TIMESTAMP_PADDING_MS,
14421
+ // ),
14422
+ // )
14423
+ // : undefined
14424
+ // const signatureEndTimestamp =
14425
+ // endMs !== Infinity && recordingStartedAt
14426
+ // ? formatTimestamp(
14427
+ // Math.min(
14428
+ // endMs - recordingStartedAt + RECORDING_TIMESTAMP_PADDING_MS,
14429
+ // lastChunkReceivedAt ?? Infinity,
14430
+ // ),
14431
+ // )
14432
+ // : undefined
14433
+ ];
14434
+ case 1:
14435
+ mediaInfo = _c.sent();
14436
+ // const endMs = Math.min(
14437
+ // signatureEndedAt ?? Infinity,
14438
+ // lastChunkReceivedAt ?? Infinity,
14439
+ // )
14440
+ // const signatureStartTimestamp =
14441
+ // signatureStartedAt && recordingStartedAt
14442
+ // ? formatTimestamp(
14443
+ // Math.max(
14444
+ // 0,
14445
+ // signatureStartedAt -
14446
+ // recordingStartedAt -
14447
+ // RECORDING_TIMESTAMP_PADDING_MS,
14448
+ // ),
14449
+ // )
14450
+ // : undefined
14451
+ // const signatureEndTimestamp =
14452
+ // endMs !== Infinity && recordingStartedAt
14453
+ // ? formatTimestamp(
14454
+ // Math.min(
14455
+ // endMs - recordingStartedAt + RECORDING_TIMESTAMP_PADDING_MS,
14456
+ // lastChunkReceivedAt ?? Infinity,
14457
+ // ),
14458
+ // )
14459
+ // : undefined
14460
+ onSignatureVideoCaptured(blob, signatureData, imageUrl !== null && imageUrl !== void 0 ? imageUrl : null, {
14461
+ mediaInfo: mediaInfo,
14462
+ mimeType: inferredType,
14463
+ timingData: {
14464
+ recordingStartedAt: recordingStartedAt,
14465
+ firstChunkReceivedAt: firstChunkReceivedAt,
14466
+ signatureStartedAt: signatureStartedAt,
14467
+ signatureEndedAt: signatureEndedAt,
14468
+ recordingStoppedAt: recordingStoppedAt,
14469
+ lastChunkReceivedAt: lastChunkReceivedAt
14470
+ }
14471
+ });
14472
+ return [2 /*return*/];
14473
+ }
14474
+ });
14566
14475
  });
14567
- signatureChunks = [];
14568
- signatureRecorder = null;
14569
- if (!signatureData) return;
14570
- var _a = get(),
14571
- onSignatureVideoCaptured = _a.onSignatureVideoCaptured,
14572
- recordingStartedAt = _a.recordingStartedAt,
14573
- signatureStartedAt = _a.signatureStartedAt,
14574
- signatureEndedAt = _a.signatureEndedAt,
14575
- lastChunkReceivedAt = _a.lastChunkReceivedAt;
14576
- var endMs = Math.min(signatureEndedAt !== null && signatureEndedAt !== void 0 ? signatureEndedAt : Infinity, lastChunkReceivedAt !== null && lastChunkReceivedAt !== void 0 ? lastChunkReceivedAt : Infinity);
14577
- var signatureStartTimestamp = signatureStartedAt && recordingStartedAt ? formatTimestamp(Math.max(0, signatureStartedAt - recordingStartedAt - RECORDING_TIMESTAMP_PADDING_MS)) : undefined;
14578
- var signatureEndTimestamp = endMs !== Infinity && recordingStartedAt ? formatTimestamp(Math.min(endMs - recordingStartedAt + RECORDING_TIMESTAMP_PADDING_MS, lastChunkReceivedAt !== null && lastChunkReceivedAt !== void 0 ? lastChunkReceivedAt : Infinity)) : undefined;
14579
- onSignatureVideoCaptured(blob, signatureData, imageUrl !== null && imageUrl !== void 0 ? imageUrl : null, signatureStartTimestamp, signatureEndTimestamp);
14580
14476
  };
14581
- useVideoRecorderStore.getState().stopRecording();
14582
14477
  });
14583
14478
  },
14584
14479
  clearRecordedData: function clearRecordedData() {
14585
14480
  signatureChunks = [];
14586
- useVideoRecorderStore.getState().stopRecordingVideo();
14587
- useVideoRecorderStore.getState().clearRecordedData();
14588
14481
  signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.stop();
14589
14482
  signatureRecorder = null;
14590
14483
  set({
@@ -14626,75 +14519,180 @@ function waitForOneMoreChunk(timeoutMs) {
14626
14519
  }
14627
14520
  function VideoSignatureContextProvider(_a) {
14628
14521
  var _this = this;
14629
- var _b, _c;
14522
+ var _b, _c, _d, _e;
14630
14523
  var children = _a.children,
14631
- _d = _a.captureAudio,
14632
- captureAudio = _d === void 0 ? false : _d;
14524
+ _f = _a.captureMediaInfo,
14525
+ captureMediaInfo = _f === void 0 ? false : _f;
14633
14526
  var videoRef = useCameraStore().videoRef;
14634
- useVideoRecorder(captureAudio);
14635
14527
  var outputCanvas = useRef(null);
14636
14528
  useEffect(function () {
14637
14529
  return useVideoSignatureStore.setState({
14638
14530
  outputCanvas: outputCanvas
14639
14531
  });
14640
14532
  }, []);
14533
+ var signatureVideoRef = useRef(null);
14534
+ var frameCheckCanvas = useRef(null);
14641
14535
  useEffect(function () {
14642
- // clear recorded data when the component is mounted
14643
- useVideoSignatureStore.getState().clearRecordedData();
14644
- }, []);
14645
- var _e = useVideoSignatureStore(useShallow(function (state) {
14646
- return {
14647
- recordingStartedAt: state.recordingStartedAt,
14648
- recordingStoppedAt: state.recordingStoppedAt
14649
- };
14650
- })),
14651
- recordingStartedAt = _e.recordingStartedAt,
14652
- recordingStoppedAt = _e.recordingStoppedAt;
14653
- useFrameLoop(useCallback(function () {
14536
+ if (!captureMediaInfo) return;
14537
+ mediaInfoFactory({
14538
+ format: 'object',
14539
+ full: true,
14540
+ locateFile: function locateFile(filename) {
14541
+ return "".concat(DEFAULT_CDN_URL, "/").concat(filename);
14542
+ }
14543
+ }).then(function (mediaInfo) {
14544
+ useVideoSignatureStore.setState({
14545
+ mediaInfo: mediaInfo
14546
+ });
14547
+ })["catch"](function (e) {
14548
+ warn('error loading mediaInfo', e);
14549
+ });
14550
+ return function () {
14551
+ var mediaInfo = useVideoSignatureStore.getState().mediaInfo;
14552
+ if (mediaInfo) {
14553
+ mediaInfo.close();
14554
+ useVideoSignatureStore.setState({
14555
+ mediaInfo: undefined
14556
+ });
14557
+ }
14558
+ };
14559
+ }, [captureMediaInfo]);
14560
+ var signaturePadEmpty = useVideoSignatureStore().signaturePadEmpty;
14561
+ var blankCheckPassed = useRef(false);
14562
+ useEffect(function () {
14563
+ if (signaturePadEmpty) blankCheckPassed.current = false;
14564
+ }, [signaturePadEmpty]);
14565
+ var drawOutputFrame = useCallback(function () {
14654
14566
  return __awaiter(_this, void 0, void 0, function () {
14655
- var signaturePad, ctx, _a, w, h, isPortrait, rect;
14567
+ var ctx, _a, w, h, isPortrait, rect;
14656
14568
  return __generator(this, function (_b) {
14657
- signaturePad = useVideoSignatureStore.getState().signaturePad;
14658
- if (!outputCanvas.current || !signaturePad.current || !videoRef.current) return [2 /*return*/];
14569
+ if (!outputCanvas.current || !signatureVideoRef.current || !videoRef.current) return [2 /*return*/];
14659
14570
  ctx = outputCanvas.current.getContext('2d');
14660
14571
  if (!ctx) return [2 /*return*/];
14661
14572
  _a = [videoRef.current.videoWidth, videoRef.current.videoHeight], w = _a[0], h = _a[1];
14662
14573
  isPortrait = w < h;
14663
14574
  outputCanvas.current.width = w;
14664
14575
  outputCanvas.current.height = h;
14665
- rect = [w * (isPortrait ? 0.02 : 0.15), h * (isPortrait ? 0.15 : 0.25), w * (isPortrait ? 0.96 : 0.7), h * (isPortrait ? 0.7 : 0.5)];
14666
- // draw the current video frame
14576
+ rect = [w * (isPortrait ? 0.02 : 0.15),
14577
+ // x
14578
+ h * (isPortrait ? 0.15 : 0.25),
14579
+ // y
14580
+ w * (isPortrait ? 0.96 : 0.7),
14581
+ // width
14582
+ h * (isPortrait ? 0.7 : 0.5) // height
14583
+ ];
14667
14584
  ctx.drawImage(videoRef.current, 0, 0, w, h);
14668
- // draw a semi-transparent white rectangle over the video to simulate a signature pad
14669
14585
  ctx.beginPath();
14670
14586
  ctx.fillStyle = 'rgba(255,255,255,0.5)';
14671
- ctx.roundRect.apply(ctx, __spreadArray(__spreadArray([], rect, false), [16], false));
14587
+ if (typeof ctx.roundRect === 'function') {
14588
+ ctx.roundRect.apply(ctx, __spreadArray(__spreadArray([], rect, false), [16], false));
14589
+ } else if (typeof ctx.rect === 'function') {
14590
+ ctx.rect.apply(ctx, rect);
14591
+ }
14672
14592
  ctx.fill();
14673
- // draw whatever the user has drawn on the signature pad
14674
- ctx.drawImage.apply(ctx, __spreadArray([signaturePad.current.getCanvas()], rect, false));
14593
+ if (signatureVideoRef.current && blankCheckPassed.current) {
14594
+ ctx.drawImage.apply(ctx, __spreadArray([signatureVideoRef.current], rect, false));
14595
+ }
14675
14596
  return [2 /*return*/];
14676
14597
  });
14677
14598
  });
14678
- }, [videoRef]), {
14679
- autoStart: !!recordingStartedAt && !recordingStoppedAt,
14680
- throttleMs: 1000 / 24
14681
- });
14682
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, children, /*#__PURE__*/React__default.createElement(InvisibleCanvas, {
14683
- ref: outputCanvas,
14599
+ }, [videoRef, outputCanvas]);
14600
+ useEffect(function () {
14601
+ if (!signatureVideoRef.current) return;
14602
+ var video = signatureVideoRef.current;
14603
+ function onFrame() {
14604
+ blankCheckPassed.current || (blankCheckPassed.current = !isVideoBlank(signatureVideoRef.current, frameCheckCanvas.current));
14605
+ drawOutputFrame();
14606
+ video.requestVideoFrameCallback(onFrame);
14607
+ }
14608
+ function onPlay() {
14609
+ video.requestVideoFrameCallback(onFrame);
14610
+ }
14611
+ video.addEventListener('play', onPlay);
14612
+ return function () {
14613
+ video.removeEventListener('play', onPlay);
14614
+ };
14615
+ }, [drawOutputFrame]);
14616
+ useEffect(function () {
14617
+ if (!videoRef.current) return;
14618
+ var video = videoRef.current;
14619
+ function onFrame() {
14620
+ drawOutputFrame();
14621
+ video.requestVideoFrameCallback(onFrame);
14622
+ }
14623
+ function onPlay() {
14624
+ video.requestVideoFrameCallback(onFrame);
14625
+ }
14626
+ video.addEventListener('play', onPlay);
14627
+ return function () {
14628
+ video.removeEventListener('play', onPlay);
14629
+ };
14630
+ }, [drawOutputFrame, videoRef]);
14631
+ var _g = useVideoSignatureStore(),
14632
+ signaturePad = _g.signaturePad,
14633
+ recordingStartedAt = _g.recordingStartedAt;
14634
+ useEffect(function () {
14635
+ var _a;
14636
+ if (!signaturePad.current || !recordingStartedAt) return;
14637
+ (_a = signatureVideoRef.current).srcObject || (_a.srcObject = signaturePad.current.getCanvas().captureStream(24));
14638
+ }, [recordingStartedAt, signaturePad]);
14639
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, children, /*#__PURE__*/React__default.createElement("video", {
14640
+ ref: signatureVideoRef,
14641
+ autoPlay: true,
14642
+ playsInline: true,
14643
+ muted: true,
14644
+ style: {
14645
+ display: 'none'
14646
+ // position: 'absolute',
14647
+ // top: 0,
14648
+ // left: 0,
14649
+ // width: '100%',
14650
+ // height: '100%',
14651
+ // zIndex: 1000,
14652
+ // pointerEvents: 'none',
14653
+ // opacity: 0.5,
14654
+ }
14655
+ }), /*#__PURE__*/React__default.createElement(InvisibleCanvas, {
14656
+ ref: frameCheckCanvas,
14684
14657
  width: (_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.videoWidth,
14685
14658
  height: (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.videoHeight
14659
+ }), /*#__PURE__*/React__default.createElement(InvisibleCanvas, {
14660
+ ref: outputCanvas,
14661
+ width: (_d = videoRef.current) === null || _d === void 0 ? void 0 : _d.videoWidth,
14662
+ height: (_e = videoRef.current) === null || _e === void 0 ? void 0 : _e.videoHeight
14686
14663
  }));
14687
14664
  }
14688
- function formatTimestamp(durationMs) {
14689
- // should be in the format of 00:00:00:00 (hh:mm:ss:cs)
14690
- var hours = Math.floor(durationMs / 3600000);
14691
- var minutes = Math.floor(durationMs % 3600000 / 60000);
14692
- var seconds = Math.floor(durationMs % 60000 / 1000);
14693
- var milliseconds = durationMs % 1000;
14694
- // Convert milliseconds to centiseconds (1/100th of a second)
14695
- var centiseconds = Math.floor(milliseconds / 10);
14696
- var csString = centiseconds.toString().padStart(2, '0');
14697
- return "".concat(hours.toString().padStart(2, '0'), ":") + "".concat(minutes.toString().padStart(2, '0'), ":") + "".concat(seconds.toString().padStart(2, '0'), ":") + "".concat(csString);
14665
+ // function formatTimestamp(durationMs: number): string {
14666
+ // // should be in the format of 00:00:00:00 (hh:mm:ss:cs)
14667
+ // const hours = Math.floor(durationMs / 3600000)
14668
+ // const minutes = Math.floor((durationMs % 3600000) / 60000)
14669
+ // const seconds = Math.floor((durationMs % 60000) / 1000)
14670
+ // const milliseconds = durationMs % 1000
14671
+ // // Convert milliseconds to centiseconds (1/100th of a second)
14672
+ // const centiseconds = Math.floor(milliseconds / 10)
14673
+ // const csString = centiseconds.toString().padStart(2, '0')
14674
+ // return (
14675
+ // `${hours.toString().padStart(2, '0')}:` +
14676
+ // `${minutes.toString().padStart(2, '0')}:` +
14677
+ // `${seconds.toString().padStart(2, '0')}:` +
14678
+ // `${csString}`
14679
+ // )
14680
+ // }
14681
+ function isVideoBlank(video, canvas) {
14682
+ if (!video || !canvas) return true;
14683
+ var ctx2 = canvas.getContext('2d');
14684
+ if (!ctx2) return true;
14685
+ ctx2.drawImage(video, 0, 0, canvas.width, canvas.height);
14686
+ return isCanvasBlank(canvas);
14687
+ }
14688
+ function isCanvasBlank(canvas) {
14689
+ var context = canvas.getContext('2d');
14690
+ if (!context) return true;
14691
+ var pixelBuffer = new Uint32Array(context.getImageData(0, 0, canvas.width, canvas.height).data.buffer);
14692
+ var result = !pixelBuffer.some(function (color) {
14693
+ return color !== 0;
14694
+ });
14695
+ return result;
14698
14696
  }
14699
14697
 
14700
14698
  function VideoSignaturePad(_a) {
@@ -15034,8 +15032,8 @@ var AssetSelectorOption = styled.div(templateObject_4$3 || (templateObject_4$3 =
15034
15032
  var templateObject_1$8, templateObject_2$8, templateObject_3$7, templateObject_4$3;
15035
15033
 
15036
15034
  var assetSelectorOpts$1 = [{
15037
- value: 'video',
15038
- label: 'Video'
15035
+ value: 'signatureVideo',
15036
+ label: 'Signature Video'
15039
15037
  }, {
15040
15038
  value: 'selfieImage',
15041
15039
  label: 'Selfie Image'
@@ -15050,7 +15048,7 @@ var VideoSignatureSuccess = function VideoSignatureSuccess(_a) {
15050
15048
  _d = _a.verbiage,
15051
15049
  rawVerbiage = _d === void 0 ? {} : _d;
15052
15050
  var ctx = useSubmissionContext();
15053
- var _e = useState('video'),
15051
+ var _e = useState('signatureVideo'),
15054
15052
  displayedAsset = _e[0],
15055
15053
  setDisplayedAsset = _e[1];
15056
15054
  var verbiage = useTranslations(rawVerbiage, {
@@ -15088,7 +15086,7 @@ var VideoSignatureSuccess = function VideoSignatureSuccess(_a) {
15088
15086
  }, option.label));
15089
15087
  })), /*#__PURE__*/React__default.createElement(OverlayImageContainer, {
15090
15088
  className: classNames.videoContainer
15091
- }, displayedAsset === 'video' && ctx.signatureVideoUrl && ( /*#__PURE__*/React__default.createElement(StyledVideo, {
15089
+ }, displayedAsset === 'signatureVideo' && ctx.signatureVideoUrl && ( /*#__PURE__*/React__default.createElement(StyledVideo, {
15092
15090
  className: classNames.video,
15093
15091
  src: ctx.signatureVideoUrl,
15094
15092
  poster: ctx.signatureVideoUrl + '#t=0.1',
@@ -15315,59 +15313,60 @@ var VideoSignatureWizard = function VideoSignatureWizard(_a) {
15315
15313
  skipSuccessScreen = _c === void 0 ? false : _c,
15316
15314
  _d = _a.captureAudio,
15317
15315
  captureAudio = _d === void 0 ? false : _d,
15318
- _e = _a.minSignaturePadPoints,
15319
- minSignaturePadPoints = _e === void 0 ? DEFAULT_MIN_SIGNATURE_PAD_POINTS : _e,
15320
- _f = _a.headTrackingDisabled,
15321
- headTrackingDisabled = _f === void 0 ? false : _f,
15322
- _g = _a.headTrackingBoundaryPercentage,
15323
- headTrackingBoundaryPercentage = _g === void 0 ? DEFAULT_HEAD_TRACKING_BOUNDARY_PERCENTAGE : _g,
15324
- _h = _a.headTrackingBoundaryType,
15325
- headTrackingBoundaryType = _h === void 0 ? DEFAULT_HEAD_TRACKING_BOUNDARY_TYPE : _h,
15326
- _j = _a.allowSignatureAfterLivenessCheckFailure,
15327
- allowSignatureAfterLivenessCheckFailure = _j === void 0 ? false : _j,
15328
- _k = _a.restartVideoOnSignaturePadCleared,
15329
- restartVideoOnSignaturePadCleared = _k === void 0 ? true : _k,
15330
- _l = _a.skipLivenessValidation,
15331
- skipLivenessValidation = _l === void 0 ? false : _l,
15332
- _m = _a.allowManualSelfieCaptureOnLoadingError,
15333
- allowManualSelfieCaptureOnLoadingError = _m === void 0 ? false : _m,
15316
+ _e = _a.captureMediaInfo,
15317
+ captureMediaInfo = _e === void 0 ? false : _e,
15318
+ _f = _a.minSignaturePadPoints,
15319
+ minSignaturePadPoints = _f === void 0 ? DEFAULT_MIN_SIGNATURE_PAD_POINTS : _f,
15320
+ _g = _a.headTrackingDisabled,
15321
+ headTrackingDisabled = _g === void 0 ? false : _g,
15322
+ _h = _a.headTrackingBoundaryPercentage,
15323
+ headTrackingBoundaryPercentage = _h === void 0 ? DEFAULT_HEAD_TRACKING_BOUNDARY_PERCENTAGE : _h,
15324
+ _j = _a.headTrackingBoundaryType,
15325
+ headTrackingBoundaryType = _j === void 0 ? DEFAULT_HEAD_TRACKING_BOUNDARY_TYPE : _j,
15326
+ _k = _a.allowSignatureAfterLivenessCheckFailure,
15327
+ allowSignatureAfterLivenessCheckFailure = _k === void 0 ? false : _k,
15328
+ _l = _a.restartVideoOnSignaturePadCleared,
15329
+ restartVideoOnSignaturePadCleared = _l === void 0 ? true : _l,
15330
+ _m = _a.skipLivenessValidation,
15331
+ skipLivenessValidation = _m === void 0 ? false : _m,
15332
+ _o = _a.allowManualSelfieCaptureOnLoadingError,
15333
+ allowManualSelfieCaptureOnLoadingError = _o === void 0 ? false : _o,
15334
15334
  faceLivenessProps = _a.faceLivenessProps,
15335
15335
  guidesComponent = _a.guidesComponent,
15336
- _o = _a.showFaceGuideThenSignaturePad,
15337
- showFaceGuideThenSignaturePad = _o === void 0 ? false : _o,
15338
- _p = _a.assets,
15339
- assets = _p === void 0 ? {} : _p,
15340
- _q = _a.classNames,
15341
- classNames = _q === void 0 ? {} : _q,
15342
- _r = _a.colors,
15343
- colors = _r === void 0 ? {} : _r,
15344
- _s = _a.verbiage,
15345
- verbiage = _s === void 0 ? {} : _s,
15346
- _t = _a.debugMode,
15347
- debugMode = _t === void 0 ? false : _t;
15348
- var _u = useSubmissionContext(),
15349
- selfieImage = _u.selfieImage,
15350
- setSelfieImage = _u.setSelfieImage,
15351
- setSignatureData = _u.setSignatureData,
15352
- setSignatureVideoUrl = _u.setSignatureVideoUrl,
15353
- setSignatureStartTimestamp = _u.setSignatureStartTimestamp,
15354
- setSignatureEndTimestamp = _u.setSignatureEndTimestamp,
15355
- logSelfieCaptureAttempt = _u.logSelfieCaptureAttempt,
15356
- uploadDocument = _u.uploadDocument;
15336
+ _p = _a.showFaceGuideThenSignaturePad,
15337
+ showFaceGuideThenSignaturePad = _p === void 0 ? false : _p,
15338
+ _q = _a.assets,
15339
+ assets = _q === void 0 ? {} : _q,
15340
+ _r = _a.classNames,
15341
+ classNames = _r === void 0 ? {} : _r,
15342
+ _s = _a.colors,
15343
+ colors = _s === void 0 ? {} : _s,
15344
+ _t = _a.verbiage,
15345
+ verbiage = _t === void 0 ? {} : _t,
15346
+ _u = _a.debugMode,
15347
+ debugMode = _u === void 0 ? false : _u;
15348
+ var _v = useSubmissionContext(),
15349
+ selfieImage = _v.selfieImage,
15350
+ setSelfieImage = _v.setSelfieImage,
15351
+ setSignatureData = _v.setSignatureData,
15352
+ setSignatureVideoUrl = _v.setSignatureVideoUrl,
15353
+ setSignatureVideoMetadata = _v.setSignatureVideoMetadata,
15354
+ logSelfieCaptureAttempt = _v.logSelfieCaptureAttempt,
15355
+ uploadDocument = _v.uploadDocument;
15357
15356
  var cameraAccessDenied = useCameraStore(useShallow(function (state) {
15358
15357
  return {
15359
15358
  cameraAccessDenied: state.cameraAccessDenied
15360
15359
  };
15361
15360
  })).cameraAccessDenied;
15362
- var _v = useState(skipLivenessValidation ? 'CAPTURING_SELFIE' : 'CHECKING_LIVENESS'),
15363
- captureState = _v[0],
15364
- setCaptureState = _v[1];
15361
+ var _w = useState(skipLivenessValidation ? 'CAPTURING_SELFIE' : 'CHECKING_LIVENESS'),
15362
+ captureState = _w[0],
15363
+ setCaptureState = _w[1];
15365
15364
  var operationStartedAt = useRef();
15366
15365
  var captureStartedAt = useRef();
15367
15366
  var captureEndedAt = useRef();
15368
- var _w = useSelfieGuidanceModelsContext(),
15369
- start = _w.start,
15370
- stop = _w.stop;
15367
+ var _x = useSelfieGuidanceModelsContext(),
15368
+ start = _x.start,
15369
+ stop = _x.stop;
15371
15370
  useEffect(function () {
15372
15371
  operationStartedAt.current = new Date();
15373
15372
  }, []);
@@ -15411,25 +15410,24 @@ var VideoSignatureWizard = function VideoSignatureWizard(_a) {
15411
15410
  filetype: 'image/jpeg'
15412
15411
  }).then(onSelfieCaptured);
15413
15412
  }, [logCaptureMetadata, onSelfieCaptured, setSelfieImage, uploadDocument]);
15414
- var onSignatureCaptureCompleted = useCallback(function (videoData, signatureData, signatureImageData, signatureStartTimestamp, signatureEndTimestamp) {
15413
+ var onSignatureCaptureCompleted = useCallback(function (videoData, signatureData, signatureImageData, metadata) {
15415
15414
  setSignatureData(signatureData);
15416
15415
  setSignatureVideoUrl(URL.createObjectURL(videoData));
15417
- if (signatureStartTimestamp) setSignatureStartTimestamp(signatureStartTimestamp);
15418
- if (signatureEndTimestamp) setSignatureEndTimestamp(signatureEndTimestamp);
15416
+ setSignatureVideoMetadata(metadata);
15419
15417
  setCaptureState('SUCCESS');
15420
- onVideoCaptured === null || onVideoCaptured === void 0 ? void 0 : onVideoCaptured(videoData, signatureData, signatureImageData, signatureStartTimestamp, signatureEndTimestamp);
15421
- }, [onVideoCaptured, setSignatureData, setSignatureEndTimestamp, setSignatureStartTimestamp, setSignatureVideoUrl]);
15422
- var _x = useState(true),
15423
- showLoadingOverlay = _x[0],
15424
- setShowLoadingOverlay = _x[1];
15418
+ onVideoCaptured === null || onVideoCaptured === void 0 ? void 0 : onVideoCaptured(videoData, signatureData, signatureImageData, metadata);
15419
+ }, [onVideoCaptured, setSignatureData, setSignatureVideoMetadata, setSignatureVideoUrl]);
15420
+ var _y = useState(true),
15421
+ showLoadingOverlay = _y[0],
15422
+ setShowLoadingOverlay = _y[1];
15425
15423
  var onSignatureCaptureFacesNotDetected = useCallback(function () {
15426
15424
  setShowLoadingOverlay(false);
15427
15425
  setCaptureState(skipLivenessValidation ? 'CAPTURING_SELFIE' : 'CHECKING_LIVENESS');
15428
15426
  useVideoSignatureStore.getState().clearRecordedData();
15429
15427
  }, [skipLivenessValidation]);
15430
- var _y = useState(0),
15431
- attempt = _y[0],
15432
- setAttempt = _y[1];
15428
+ var _z = useState(0),
15429
+ attempt = _z[0],
15430
+ setAttempt = _z[1];
15433
15431
  var onRetry = useCallback(function () {
15434
15432
  onRetryClicked === null || onRetryClicked === void 0 ? void 0 : onRetryClicked();
15435
15433
  setAttempt(function (n) {
@@ -15478,7 +15476,7 @@ var VideoSignatureWizard = function VideoSignatureWizard(_a) {
15478
15476
  }, [faceLivenessOnLoadingOverlayDismissed, onLoadingOverlayDismissed]);
15479
15477
  return /*#__PURE__*/React__default.createElement(VideoSignatureContextProvider, {
15480
15478
  key: "video-signature-context-".concat(attempt),
15481
- captureAudio: captureAudio
15479
+ captureMediaInfo: captureMediaInfo
15482
15480
  }, /*#__PURE__*/React__default.createElement(CameraVideoTag, {
15483
15481
  className: classNames.cameraFeed
15484
15482
  }), function () {
@@ -15775,6 +15773,196 @@ var IdCardGuideInstructionsContainer = styled.div(templateObject_7 || (templateO
15775
15773
  var IdCardGuideInstructions = styled(GuidanceMessage)(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n align-content: center;\n padding: 8px 12px;\n font-weight: bold;\n font-size: 18px;\n"], ["\n align-content: center;\n padding: 8px 12px;\n font-weight: bold;\n font-size: 18px;\n"])));
15776
15774
  var templateObject_1$7, templateObject_2$7, templateObject_3$6, templateObject_4$2, templateObject_5$2, templateObject_6$1, templateObject_7, templateObject_8;
15777
15775
 
15776
+ var videoRecorder = null;
15777
+ var audioRecorder = null;
15778
+ var videoChunks = [];
15779
+ var audioChunks = [];
15780
+ function setVideoRecorder(recorder) {
15781
+ videoRecorder = recorder;
15782
+ }
15783
+ function setAudioRecorder(recorder) {
15784
+ audioRecorder = recorder;
15785
+ }
15786
+ function clearVideoChunks() {
15787
+ videoChunks = [];
15788
+ }
15789
+ function clearAudioChunks() {
15790
+ audioChunks = [];
15791
+ }
15792
+ var initialState$2 = {
15793
+ videoUrl: null,
15794
+ audioUrl: null,
15795
+ isRecordingVideo: false,
15796
+ isRecordingAudio: false,
15797
+ videoRecordingStopped: false,
15798
+ audioRecordingStopped: false,
15799
+ videoRecordingIntentionallyStopped: false,
15800
+ audioRecordingIntentionallyStopped: false,
15801
+ mergeAVStreams: false,
15802
+ onVideoCaptured: function onVideoCaptured() {}
15803
+ };
15804
+ var useVideoRecorderStore = create()(devtools(function (set, get) {
15805
+ return _assign(_assign({}, initialState$2), {
15806
+ startRecordingVideo: function startRecordingVideo(captureAudio) {
15807
+ var _a, _b, _c;
15808
+ if (captureAudio === void 0) {
15809
+ captureAudio = false;
15810
+ }
15811
+ if (!camera) throw new Error('Camera not found');
15812
+ var _d = get(),
15813
+ mergeAVStreams = _d.mergeAVStreams,
15814
+ startRecordingAudio = _d.startRecordingAudio;
15815
+ var videoStream = mergeAVStreams ? new MediaStream(__spreadArray(__spreadArray([], (_b = (_a = camera === null || camera === void 0 ? void 0 : camera.stream) === null || _a === void 0 ? void 0 : _a.getTracks()) !== null && _b !== void 0 ? _b : [], true), captureAudio ? (_c = audioStream === null || audioStream === void 0 ? void 0 : audioStream.getTracks()) !== null && _c !== void 0 ? _c : [] : [], true)) : camera.stream;
15816
+ if (!videoStream) return;
15817
+ clearVideoChunks();
15818
+ videoRecorder = null;
15819
+ set({
15820
+ isRecordingVideo: true,
15821
+ videoRecordingStopped: false,
15822
+ videoRecordingIntentionallyStopped: false
15823
+ });
15824
+ videoRecorder = new MediaRecorder(videoStream, {
15825
+ videoBitsPerSecond: 270000,
15826
+ audioBitsPerSecond: 32000
15827
+ });
15828
+ videoRecorder.ondataavailable = function (e) {
15829
+ videoChunks.push(e.data);
15830
+ };
15831
+ videoRecorder.onstop = function () {
15832
+ set({
15833
+ videoRecordingStopped: true
15834
+ });
15835
+ };
15836
+ videoRecorder.start(100);
15837
+ setTimeout(function () {
15838
+ if (!videoRecorder || videoRecorder.state === 'inactive') {
15839
+ log('media recorder is inactive!');
15840
+ // TODO: figure out what to do here
15841
+ }
15842
+ }, 100);
15843
+ if (captureAudio && !mergeAVStreams) {
15844
+ startRecordingAudio();
15845
+ }
15846
+ },
15847
+ stopRecordingVideo: function stopRecordingVideo() {
15848
+ set({
15849
+ videoRecordingIntentionallyStopped: true
15850
+ });
15851
+ if (videoRecorder && videoRecorder.state !== 'inactive') {
15852
+ videoRecorder.stop();
15853
+ }
15854
+ },
15855
+ startRecordingAudio: function startRecordingAudio() {
15856
+ if (get().mergeAVStreams) return;
15857
+ if (!audioStream) return;
15858
+ clearAudioChunks();
15859
+ set({
15860
+ isRecordingAudio: true,
15861
+ audioRecordingStopped: false,
15862
+ audioRecordingIntentionallyStopped: false
15863
+ });
15864
+ var audioRecorder = new MediaRecorder(audioStream, {
15865
+ audioBitsPerSecond: 32000
15866
+ });
15867
+ setAudioRecorder(audioRecorder);
15868
+ audioRecorder.ondataavailable = function (e) {
15869
+ audioChunks.push(e.data);
15870
+ };
15871
+ audioRecorder.onstop = function () {
15872
+ set({
15873
+ audioRecordingStopped: true
15874
+ });
15875
+ };
15876
+ audioRecorder.start(100);
15877
+ },
15878
+ stopRecordingAudio: function stopRecordingAudio() {
15879
+ set({
15880
+ audioRecordingIntentionallyStopped: true
15881
+ });
15882
+ if ((audioRecorder === null || audioRecorder === void 0 ? void 0 : audioRecorder.state) !== 'inactive') {
15883
+ audioRecorder === null || audioRecorder === void 0 ? void 0 : audioRecorder.stop(); // if you call this while state === 'inactive', an exception is thrown.
15884
+ }
15885
+ },
15886
+ stopRecording: function stopRecording() {
15887
+ get().stopRecordingVideo();
15888
+ get().stopRecordingAudio();
15889
+ },
15890
+ clearRecordedData: function clearRecordedData() {
15891
+ clearVideoChunks();
15892
+ clearAudioChunks();
15893
+ }
15894
+ });
15895
+ }));
15896
+ var useVideoRecorder = function useVideoRecorder(mergeAVStreams) {
15897
+ if (mergeAVStreams === void 0) {
15898
+ mergeAVStreams = false;
15899
+ }
15900
+ useEffect(function () {
15901
+ return useVideoRecorderStore.setState({
15902
+ mergeAVStreams: mergeAVStreams
15903
+ });
15904
+ }, [mergeAVStreams]);
15905
+ useEffect(function () {
15906
+ // clear recorded data when the component is mounted
15907
+ useVideoRecorderStore.getState().clearRecordedData();
15908
+ }, []);
15909
+ var processVideo = useCallback(function () {
15910
+ var inferredType = inferBlobType(videoChunks[0]) || (videoRecorder === null || videoRecorder === void 0 ? void 0 : videoRecorder.mimeType) || 'video/mp4';
15911
+ var videoBlob = new Blob(videoChunks, {
15912
+ type: inferredType
15913
+ });
15914
+ var videoUrl = URL.createObjectURL(videoBlob);
15915
+ useVideoRecorderStore.setState({
15916
+ videoUrl: videoUrl,
15917
+ isRecordingVideo: false
15918
+ });
15919
+ clearVideoChunks();
15920
+ setVideoRecorder(null);
15921
+ useVideoRecorderStore.getState().onVideoCaptured(videoUrl);
15922
+ }, []);
15923
+ var processAudio = useCallback(function () {
15924
+ var inferredType = inferBlobType(audioChunks[0]) || (audioRecorder === null || audioRecorder === void 0 ? void 0 : audioRecorder.mimeType) || 'audio/mp4';
15925
+ var audioBlob = new Blob(audioChunks, {
15926
+ type: inferredType
15927
+ });
15928
+ useVideoRecorderStore.setState({
15929
+ audioUrl: URL.createObjectURL(audioBlob),
15930
+ isRecordingAudio: false
15931
+ });
15932
+ clearAudioChunks();
15933
+ setAudioRecorder(null);
15934
+ }, []);
15935
+ var _a = useVideoRecorderStore(),
15936
+ videoUrl = _a.videoUrl,
15937
+ audioUrl = _a.audioUrl,
15938
+ isRecordingVideo = _a.isRecordingVideo,
15939
+ isRecordingAudio = _a.isRecordingAudio,
15940
+ videoRecordingStopped = _a.videoRecordingStopped,
15941
+ videoRecordingIntentionallyStopped = _a.videoRecordingIntentionallyStopped,
15942
+ audioRecordingStopped = _a.audioRecordingStopped,
15943
+ audioRecordingIntentionallyStopped = _a.audioRecordingIntentionallyStopped;
15944
+ useEffect(function () {
15945
+ if (videoRecordingStopped && videoRecordingIntentionallyStopped) {
15946
+ processVideo();
15947
+ }
15948
+ }, [processVideo, videoRecordingIntentionallyStopped, videoRecordingStopped]);
15949
+ useEffect(function () {
15950
+ if (audioRecordingStopped && audioRecordingIntentionallyStopped) {
15951
+ processAudio();
15952
+ }
15953
+ }, [audioRecordingIntentionallyStopped, audioRecordingStopped, processAudio]);
15954
+ return useMemo(function () {
15955
+ return {
15956
+ isRecordingVideo: isRecordingVideo,
15957
+ isRecordingAudio: isRecordingAudio,
15958
+ videoRecordingUnintentionallyStopped: videoRecordingStopped && !videoRecordingIntentionallyStopped,
15959
+ audioRecordingUnintentionallyStopped: audioRecordingStopped && !audioRecordingIntentionallyStopped,
15960
+ videoUrl: videoUrl,
15961
+ audioUrl: audioUrl
15962
+ };
15963
+ }, [audioRecordingIntentionallyStopped, audioRecordingStopped, audioUrl, isRecordingAudio, isRecordingVideo, videoRecordingIntentionallyStopped, videoRecordingStopped, videoUrl]);
15964
+ };
15965
+
15778
15966
  var ReadTextPrompt = function ReadTextPrompt(_a) {
15779
15967
  var onComplete = _a.onComplete,
15780
15968
  _b = _a.durationMs,