idmission-web-sdk 2.3.11 → 2.3.13

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
@@ -204,7 +204,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
204
204
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
205
205
  };
206
206
 
207
- var webSdkVersion = '2.3.11';
207
+ var webSdkVersion = '2.3.13';
208
208
 
209
209
  function getPlatform() {
210
210
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -13326,14 +13326,29 @@ var Container$4 = styled.div(templateObject_1$c || (templateObject_1$c = __makeT
13326
13326
  var AcceptBtn$1 = styled(LoaderButton)(templateObject_2$a || (templateObject_2$a = __makeTemplateObject(["\n margin-left: auto;\n"], ["\n margin-left: auto;\n"])));
13327
13327
  var templateObject_1$c, templateObject_2$a;
13328
13328
 
13329
+ var videoRecorder = null;
13330
+ var audioRecorder = null;
13331
+ var videoChunks = [];
13332
+ var audioChunks = [];
13333
+ function getVideoRecorder() {
13334
+ return videoRecorder;
13335
+ }
13336
+ function setVideoRecorder(recorder) {
13337
+ videoRecorder = recorder;
13338
+ }
13339
+ function setAudioRecorder(recorder) {
13340
+ audioRecorder = recorder;
13341
+ }
13342
+ function clearVideoChunks() {
13343
+ videoChunks = [];
13344
+ }
13345
+ function clearAudioChunks() {
13346
+ audioChunks = [];
13347
+ }
13329
13348
  var useVideoRecorder = function useVideoRecorder(camera, audioStream, mergeAVStreams) {
13330
13349
  if (mergeAVStreams === void 0) {
13331
13350
  mergeAVStreams = false;
13332
13351
  }
13333
- var videoRecorder = useRef(null);
13334
- var audioRecorder = useRef(null);
13335
- var videoChunks = useRef([]);
13336
- var audioChunks = useRef([]);
13337
13352
  var _a = useState(null),
13338
13353
  videoUrl = _a[0],
13339
13354
  setVideoUrl = _a[1];
@@ -13366,45 +13381,48 @@ var useVideoRecorder = function useVideoRecorder(camera, audioStream, mergeAVStr
13366
13381
  return new MediaStream(__spreadArray(__spreadArray([], videoTracks, true), audioTracks, true));
13367
13382
  }, [audioStream, camera === null || camera === void 0 ? void 0 : camera.stream, mergeAVStreams]);
13368
13383
  var processVideo = useCallback(function () {
13369
- var videoBlob = new Blob(videoChunks.current, {
13384
+ var videoBlob = new Blob(videoChunks, {
13370
13385
  type: 'video/mp4'
13371
13386
  });
13372
- videoChunks.current = [];
13373
13387
  setVideoUrl(URL.createObjectURL(videoBlob));
13388
+ clearVideoChunks();
13374
13389
  setIsRecordingVideo(false);
13390
+ setVideoRecorder(null);
13375
13391
  camera === null || camera === void 0 ? void 0 : camera.release();
13376
13392
  }, [camera]);
13377
13393
  var processAudio = useCallback(function () {
13378
13394
  var _a;
13379
- var audioBlob = new Blob(audioChunks.current, {
13395
+ var audioBlob = new Blob(audioChunks, {
13380
13396
  type: 'audio/mp4'
13381
13397
  });
13382
- audioChunks.current = [];
13383
13398
  setAudioUrl(URL.createObjectURL(audioBlob));
13399
+ clearAudioChunks();
13384
13400
  setIsRecordingAudio(false);
13401
+ setAudioRecorder(null);
13385
13402
  (_a = audioStream === null || audioStream === void 0 ? void 0 : audioStream.stop) === null || _a === void 0 ? void 0 : _a.call(audioStream);
13386
13403
  }, [audioStream]);
13387
13404
  var startRecordingVideo = useCallback(function () {
13388
13405
  var videoStream = getVideoStream();
13389
13406
  if (!videoStream) return;
13390
- videoChunks.current = [];
13407
+ clearVideoChunks();
13391
13408
  setIsRecordingVideo(true);
13392
13409
  setVideoRecordingStopped(false);
13393
13410
  setVideoRecordingIntentionallyStopped(false);
13394
- videoRecorder.current = new MediaRecorder(videoStream, {
13411
+ var videoRecorder = new MediaRecorder(videoStream, {
13395
13412
  videoBitsPerSecond: 270000,
13396
13413
  audioBitsPerSecond: 32000
13397
13414
  });
13398
- videoRecorder.current.ondataavailable = function (e) {
13399
- videoChunks.current.push(e.data);
13415
+ setVideoRecorder(videoRecorder);
13416
+ videoRecorder.ondataavailable = function (e) {
13417
+ videoChunks.push(e.data);
13400
13418
  };
13401
- videoRecorder.current.onstop = function () {
13419
+ videoRecorder.onstop = function () {
13402
13420
  setVideoRecordingStopped(true);
13403
13421
  };
13404
- videoRecorder.current.start(1000);
13422
+ videoRecorder.start(1000);
13405
13423
  setTimeout(function () {
13406
13424
  var _a;
13407
- if (((_a = videoRecorder.current) === null || _a === void 0 ? void 0 : _a.state) === 'inactive') {
13425
+ if (((_a = getVideoRecorder()) === null || _a === void 0 ? void 0 : _a.state) === 'inactive') {
13408
13426
  log('media recorder is inactive!');
13409
13427
  // TODO: figure out what to do here
13410
13428
  }
@@ -13413,33 +13431,32 @@ var useVideoRecorder = function useVideoRecorder(camera, audioStream, mergeAVStr
13413
13431
  var startRecordingAudio = useCallback(function () {
13414
13432
  if (mergeAVStreams) return;
13415
13433
  if (!audioStream) return;
13416
- audioChunks.current = [];
13434
+ clearAudioChunks();
13417
13435
  setIsRecordingAudio(true);
13418
13436
  setAudioRecordingStopped(false);
13419
13437
  setAudioRecordingIntentionallyStopped(false);
13420
- audioRecorder.current = new MediaRecorder(audioStream, {
13438
+ var audioRecorder = new MediaRecorder(audioStream, {
13421
13439
  audioBitsPerSecond: 32000
13422
13440
  });
13423
- audioRecorder.current.ondataavailable = function (e) {
13424
- audioChunks.current.push(e.data);
13441
+ setAudioRecorder(audioRecorder);
13442
+ audioRecorder.ondataavailable = function (e) {
13443
+ audioChunks.push(e.data);
13425
13444
  };
13426
- audioRecorder.current.onstop = function () {
13445
+ audioRecorder.onstop = function () {
13427
13446
  setAudioRecordingStopped(true);
13428
13447
  };
13429
- audioRecorder.current.start(1000);
13448
+ audioRecorder.start(1000);
13430
13449
  }, [audioStream, mergeAVStreams]);
13431
13450
  var stopRecordingVideo = useCallback(function () {
13432
- var _a, _b;
13433
13451
  setVideoRecordingIntentionallyStopped(true);
13434
- if (((_a = videoRecorder.current) === null || _a === void 0 ? void 0 : _a.state) !== 'inactive') {
13435
- (_b = videoRecorder.current) === null || _b === void 0 ? void 0 : _b.stop(); // if you call this while state === 'inactive', an exception is thrown.
13452
+ if ((videoRecorder === null || videoRecorder === void 0 ? void 0 : videoRecorder.state) !== 'inactive') {
13453
+ videoRecorder === null || videoRecorder === void 0 ? void 0 : videoRecorder.stop(); // if you call this while state === 'inactive', an exception is thrown.
13436
13454
  }
13437
13455
  }, []);
13438
13456
  var stopRecordingAudio = useCallback(function () {
13439
- var _a, _b;
13440
13457
  setAudioRecordingIntentionallyStopped(true);
13441
- if (((_a = audioRecorder.current) === null || _a === void 0 ? void 0 : _a.state) !== 'inactive') {
13442
- (_b = audioRecorder.current) === null || _b === void 0 ? void 0 : _b.stop(); // if you call this while state === 'inactive', an exception is thrown.
13458
+ if ((audioRecorder === null || audioRecorder === void 0 ? void 0 : audioRecorder.state) !== 'inactive') {
13459
+ audioRecorder === null || audioRecorder === void 0 ? void 0 : audioRecorder.stop(); // if you call this while state === 'inactive', an exception is thrown.
13443
13460
  }
13444
13461
  }, []);
13445
13462
  useEffect(function () {
@@ -13453,8 +13470,8 @@ var useVideoRecorder = function useVideoRecorder(camera, audioStream, mergeAVStr
13453
13470
  }
13454
13471
  }, [audioRecordingIntentionallyStopped, audioRecordingStopped, processAudio]);
13455
13472
  var clearRecordedData = useCallback(function () {
13456
- videoChunks.current = [];
13457
- audioChunks.current = [];
13473
+ clearVideoChunks();
13474
+ clearAudioChunks();
13458
13475
  }, []);
13459
13476
  return useMemo(function () {
13460
13477
  return {
@@ -13473,6 +13490,36 @@ var useVideoRecorder = function useVideoRecorder(camera, audioStream, mergeAVStr
13473
13490
  }, [audioRecordingIntentionallyStopped, audioRecordingStopped, audioUrl, clearRecordedData, isRecordingAudio, isRecordingVideo, startRecordingAudio, startRecordingVideo, stopRecordingAudio, stopRecordingVideo, videoRecordingIntentionallyStopped, videoRecordingStopped, videoUrl]);
13474
13491
  };
13475
13492
 
13493
+ var signatureRecorder = null;
13494
+ var getSignatureRecorder = function getSignatureRecorder() {
13495
+ return signatureRecorder;
13496
+ };
13497
+ var setSignatureRecorder = function setSignatureRecorder(recorder) {
13498
+ return signatureRecorder = recorder;
13499
+ };
13500
+ var signatureChunks = [];
13501
+ var clearSignatureChunks = function clearSignatureChunks() {
13502
+ return signatureChunks = [];
13503
+ };
13504
+ var recordingLock = false;
13505
+ var setRecordingLock = function setRecordingLock(lock) {
13506
+ return recordingLock = lock;
13507
+ };
13508
+ var recordingLockEngaged = function recordingLockEngaged() {
13509
+ return recordingLock;
13510
+ };
13511
+ function waitForCanvasAvailable(canvasRef) {
13512
+ if (canvasRef.current) return Promise.resolve(null);
13513
+ return new Promise(function (resolve) {
13514
+ var interval = setInterval(function () {
13515
+ debug('VideoSignatureContext: waiting for output canvas');
13516
+ if (canvasRef.current) {
13517
+ clearInterval(interval);
13518
+ resolve(null);
13519
+ }
13520
+ }, 100);
13521
+ });
13522
+ }
13476
13523
  var videoSignatureInitialState = {
13477
13524
  startRecording: function startRecording() {
13478
13525
  return null;
@@ -13491,7 +13538,7 @@ var videoSignatureInitialState = {
13491
13538
  onAcceptClicked: function onAcceptClicked() {
13492
13539
  return __awaiter(void 0, void 0, void 0, function () {
13493
13540
  return __generator(this, function (_a) {
13494
- return [2 /*return*/, void 0];
13541
+ return [2 /*return*/];
13495
13542
  });
13496
13543
  });
13497
13544
  }
@@ -13516,8 +13563,6 @@ function VideoSignatureContextProvider(_a) {
13516
13563
  var _h = useState(null),
13517
13564
  signatureVideoUrl = _h[0],
13518
13565
  setSignatureVideoUrl = _h[1];
13519
- var signatureRecorder = useRef(null);
13520
- var recordedChunks = useRef([]);
13521
13566
  var _j = useCameraStore(),
13522
13567
  camera = _j.camera,
13523
13568
  videoRef = _j.videoRef,
@@ -13530,7 +13575,6 @@ function VideoSignatureContextProvider(_a) {
13530
13575
  stopRecordingAudio = _k.stopRecordingAudio,
13531
13576
  clearRecordedVideoData = _k.clearRecordedData;
13532
13577
  var outputCanvas = useRef(null);
13533
- var recordingLock = useRef(false);
13534
13578
  var onRecordingStopped = useRef(function () {});
13535
13579
  var _l = useState(false),
13536
13580
  isRecording = _l[0],
@@ -13549,67 +13593,45 @@ function VideoSignatureContextProvider(_a) {
13549
13593
  setIsRecording(true);
13550
13594
  onRecordingStopped.current = function () {};
13551
13595
  };
13552
- recordingLock.current = false;
13596
+ setRecordingLock(false);
13553
13597
  setIsRecording(false);
13554
- (_a = signatureRecorder.current) === null || _a === void 0 ? void 0 : _a.stop();
13598
+ (_a = getSignatureRecorder()) === null || _a === void 0 ? void 0 : _a.stop();
13599
+ setSignatureRecorder(null);
13555
13600
  }, []);
13556
13601
  useEffect(function () {
13557
13602
  if (!isRecording) return;
13558
- if (recordingLock.current) return;
13559
- recordingLock.current = true;
13560
- (function () {
13561
- return __awaiter(_this, void 0, void 0, function () {
13562
- var stream, tracks, audioTrack;
13563
- var _a;
13564
- return __generator(this, function (_b) {
13565
- switch (_b.label) {
13566
- case 0:
13567
- if (!!outputCanvas.current) return [3 /*break*/, 2];
13568
- return [4 /*yield*/, new Promise(function (resolve) {
13569
- var interval = setInterval(function () {
13570
- if (outputCanvas.current) {
13571
- clearInterval(interval);
13572
- resolve(null);
13573
- }
13574
- }, 10);
13575
- })];
13576
- case 1:
13577
- _b.sent();
13578
- _b.label = 2;
13579
- case 2:
13580
- recordedChunks.current = [];
13581
- clearRecordedVideoData();
13582
- startRecordingVideo();
13583
- if (captureAudio) startRecordingAudio();
13584
- stream = outputCanvas.current.captureStream(24 /* fps */);
13585
- tracks = [stream.getVideoTracks()[0]];
13586
- audioTrack = (_a = audioStream === null || audioStream === void 0 ? void 0 : audioStream.getAudioTracks()) === null || _a === void 0 ? void 0 : _a[0];
13587
- if (audioTrack) tracks.push(audioTrack);
13588
- signatureRecorder.current = new MediaRecorder(new MediaStream(tracks), {
13589
- videoBitsPerSecond: 270000,
13590
- audioBitsPerSecond: 32000
13591
- });
13592
- signatureRecorder.current.start();
13593
- signatureRecorder.current.ondataavailable = function (event) {
13594
- var _a;
13595
- recordedChunks.current.push(event.data);
13596
- if (((_a = signatureRecorder.current) === null || _a === void 0 ? void 0 : _a.state) === 'recording') {
13597
- signatureRecorder.current.stop();
13598
- }
13599
- };
13600
- signatureRecorder.current.onstop = function () {
13601
- var blob = new Blob(recordedChunks.current, {
13602
- type: 'video/mp4'
13603
- });
13604
- setSignatureVideoData(blob);
13605
- setSignatureVideoUrl(URL.createObjectURL(blob));
13606
- onRecordingStopped.current();
13607
- };
13608
- return [2 /*return*/];
13609
- }
13610
- });
13603
+ if (recordingLockEngaged()) return;
13604
+ setRecordingLock(true);
13605
+ waitForCanvasAvailable(outputCanvas).then(function () {
13606
+ var _a;
13607
+ clearSignatureChunks();
13608
+ clearRecordedVideoData();
13609
+ startRecordingVideo();
13610
+ if (captureAudio) startRecordingAudio();
13611
+ var stream = outputCanvas.current.captureStream(24 /* fps */);
13612
+ var tracks = [stream.getVideoTracks()[0]];
13613
+ var audioTrack = (_a = audioStream === null || audioStream === void 0 ? void 0 : audioStream.getAudioTracks()) === null || _a === void 0 ? void 0 : _a[0];
13614
+ if (audioTrack) tracks.push(audioTrack);
13615
+ var signatureRecorder = new MediaRecorder(new MediaStream(tracks), {
13616
+ videoBitsPerSecond: 270000,
13617
+ audioBitsPerSecond: 32000
13611
13618
  });
13612
- })();
13619
+ setSignatureRecorder(signatureRecorder);
13620
+ signatureRecorder.ondataavailable = function (event) {
13621
+ signatureChunks.push(event.data);
13622
+ };
13623
+ signatureRecorder.onstop = function () {
13624
+ var blob = new Blob(signatureChunks, {
13625
+ type: 'video/mp4'
13626
+ });
13627
+ setSignatureVideoData(blob);
13628
+ setSignatureVideoUrl(URL.createObjectURL(blob));
13629
+ clearSignatureChunks();
13630
+ setSignatureRecorder(null);
13631
+ onRecordingStopped.current();
13632
+ };
13633
+ signatureRecorder.start(1000);
13634
+ });
13613
13635
  }, [audioStream, captureAudio, clearRecordedVideoData, isRecording, startRecordingAudio, startRecordingVideo]);
13614
13636
  var animationFrame = useRef(0);
13615
13637
  useEffect(function () {
@@ -13651,17 +13673,23 @@ function VideoSignatureContextProvider(_a) {
13651
13673
  return __generator(this, function (_b) {
13652
13674
  switch (_b.label) {
13653
13675
  case 0:
13676
+ debug('VideoSignatureContext: onAcceptClicked');
13654
13677
  if (!signaturePad.current) return [2 /*return*/];
13678
+ debug('VideoSignatureContext: building signature data...');
13655
13679
  signatureData = buildSignatureData(signaturePad.current);
13680
+ debug('VideoSignatureContext: exporting signature image...');
13656
13681
  return [4 /*yield*/, exportSignatureImage(signaturePad.current)];
13657
13682
  case 1:
13658
13683
  imageUrl = _b.sent();
13659
13684
  if (imageUrl) signatureData.fileContent = dataUrlToBase64Sync(imageUrl);
13685
+ debug('VideoSignatureContext: setting signature data url...');
13660
13686
  setSignatureDataUrl(imageUrl);
13661
13687
  setSignatureData(signatureData);
13688
+ debug('VideoSignatureContext: stopping recording...');
13662
13689
  stopRecordingVideo();
13663
13690
  stopRecordingAudio();
13664
- (_a = signatureRecorder.current) === null || _a === void 0 ? void 0 : _a.stop();
13691
+ debug('VideoSignatureContext: stopping signature recorder...');
13692
+ (_a = getSignatureRecorder()) === null || _a === void 0 ? void 0 : _a.stop();
13665
13693
  return [2 /*return*/];
13666
13694
  }
13667
13695
  });