idmission-web-sdk 1.0.350 → 1.0.351

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.
@@ -39,6 +39,7 @@ export type CaptureDevice = {
39
39
  videoDevice: MediaDeviceInfo | null;
40
40
  videoLoaded: boolean;
41
41
  setVideoLoaded: (value: boolean) => void;
42
+ onVideoUnmounted: (videoElement: HTMLVideoElement) => void;
42
43
  cameraRef: MutableRefObject<Camera | null>;
43
44
  cameraReady: boolean;
44
45
  cameraAccessDenied: boolean;
@@ -51,7 +51,7 @@ var LanguageDetector__default = /*#__PURE__*/_interopDefaultLegacy(LanguageDetec
51
51
  var i18n__default = /*#__PURE__*/_interopDefaultLegacy(i18n);
52
52
  var SignatureCanvas__default = /*#__PURE__*/_interopDefaultLegacy(SignatureCanvas);
53
53
 
54
- var webSdkVersion = '1.0.350';
54
+ var webSdkVersion = '1.0.351';
55
55
 
56
56
  function getPlatform() {
57
57
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -1902,6 +1902,7 @@ function usePreferredCaptureDevice(_a) {
1902
1902
  _h = _b.debugMode,
1903
1903
  debugMode = _h === void 0 ? false : _h;
1904
1904
  var videoRef = React.useRef(null);
1905
+ var videoRefStack = React.useRef([]);
1905
1906
  var cameraRef = React.useRef(null);
1906
1907
  var _j = React.useState(false),
1907
1908
  cameraReady = _j[0],
@@ -1933,6 +1934,23 @@ function usePreferredCaptureDevice(_a) {
1933
1934
  var _t = React.useState(false),
1934
1935
  microphoneAccessDenied = _t[0],
1935
1936
  setMicrophoneAccessDenied = _t[1];
1937
+ var videoRefElement = videoRef.current;
1938
+ React.useEffect(function pushVideoRefToStackWhenChanged() {
1939
+ // proceed if the video element being mounted is not already at the top of the videoRefStack.
1940
+ var topOfStack = videoRefStack.current.slice(-1)[0];
1941
+ if (videoRefElement && videoRefElement !== topOfStack) {
1942
+ log('adding video to stack', videoRefElement);
1943
+ videoRefStack.current.push(videoRefElement);
1944
+ }
1945
+ }, [videoRefElement]);
1946
+ var onVideoUnmounted = React.useCallback(function (videoElement) {
1947
+ log('removing video from stack', videoElement);
1948
+ videoRefStack.current = videoRefStack.current.filter(function (v) {
1949
+ return v !== videoElement;
1950
+ });
1951
+ videoRef.current = videoRefStack.current.slice(-1)[0]; // top of stack.
1952
+ log('new videoRef is', videoRef.current);
1953
+ }, []);
1936
1954
  React.useEffect(function resetCameraOnContinuityPreferenceChanged() {
1937
1955
  if (debugMode) {
1938
1956
  log('iphone continuity camera allowed changed', iphoneContinuityCameraAllowed);
@@ -2222,6 +2240,7 @@ function usePreferredCaptureDevice(_a) {
2222
2240
  videoDevice: videoDevice,
2223
2241
  videoLoaded: videoLoaded,
2224
2242
  setVideoLoaded: setVideoLoaded,
2243
+ onVideoUnmounted: onVideoUnmounted,
2225
2244
  cameraRef: cameraRef,
2226
2245
  cameraReady: cameraReady,
2227
2246
  cameraAccessDenied: cameraAccessDenied,
@@ -2236,7 +2255,7 @@ function usePreferredCaptureDevice(_a) {
2236
2255
  microphoneAccessDenied: microphoneAccessDenied,
2237
2256
  requestMicrophoneAccess: requestMicrophoneAccess
2238
2257
  };
2239
- }, [audioStream, cameraAccessDenied, cameraReady, iphoneContinuityCameraAllowed, iphoneContinuityCameraAvailable, microphoneAccessDenied, microphoneReady, requestCameraAccess, requestMicrophoneAccess, takePhoto, videoDevice, videoLoaded]);
2258
+ }, [audioStream, cameraAccessDenied, cameraReady, iphoneContinuityCameraAllowed, iphoneContinuityCameraAvailable, microphoneAccessDenied, microphoneReady, onVideoUnmounted, requestCameraAccess, requestMicrophoneAccess, takePhoto, videoDevice, videoLoaded]);
2240
2259
  }
2241
2260
 
2242
2261
  var CameraStateContext = /*#__PURE__*/React.createContext({
@@ -2267,6 +2286,9 @@ var CameraStateContext = /*#__PURE__*/React.createContext({
2267
2286
  setVideoLoaded: function setVideoLoaded() {
2268
2287
  return null;
2269
2288
  },
2289
+ onVideoUnmounted: function onVideoUnmounted() {
2290
+ return null;
2291
+ },
2270
2292
  audioStream: null,
2271
2293
  microphoneReady: false,
2272
2294
  microphoneAccessDenied: false,
@@ -12116,11 +12138,19 @@ var CameraVideoTag = function CameraVideoTag(_a) {
12116
12138
  var _c = React.useContext(CameraStateContext),
12117
12139
  videoRef = _c.videoRef,
12118
12140
  setVideoLoaded = _c.setVideoLoaded,
12141
+ onVideoUnmounted = _c.onVideoUnmounted,
12119
12142
  cameraRef = _c.cameraRef;
12120
- React.useEffect(function () {
12143
+ React.useEffect(function notifyCameraProviderOfUnmount() {
12144
+ var videoElement = videoRef.current;
12145
+ if (!videoElement) return;
12146
+ return function () {
12147
+ onVideoUnmounted(videoElement);
12148
+ };
12149
+ }, [onVideoUnmounted, videoRef]);
12150
+ React.useEffect(function setVideoLoadedToFalseOnMount() {
12121
12151
  setVideoLoaded(false);
12122
12152
  }, [setVideoLoaded]);
12123
- React.useEffect(function () {
12153
+ React.useEffect(function attachCameraStreamToVideoTagWhenReady() {
12124
12154
  var _a;
12125
12155
  if (videoRef.current && ((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.stream)) {
12126
12156
  videoRef.current.srcObject = cameraRef.current.stream;
@@ -13162,47 +13192,56 @@ var Canvas = styled__default['default'].canvas(templateObject_2$h || (templateOb
13162
13192
  var templateObject_1$n, templateObject_2$h;
13163
13193
 
13164
13194
  var DocumentCaptureScreen = function DocumentCaptureScreen(_a) {
13165
- var _b, _c, _d, _e, _f;
13195
+ var _b, _c, _d, _e, _f, _g, _h;
13166
13196
  var onCaptureClicked = _a.onCaptureClicked,
13167
- _g = _a.classNames,
13168
- classNames = _g === void 0 ? {} : _g,
13169
- _h = _a.verbiage,
13170
- rawVerbiage = _h === void 0 ? {} : _h;
13171
- var _j = useDocumentCaptureState(),
13172
- _k = _j[0],
13173
- documents = _k.documents,
13174
- currentDocumentIndex = _k.currentDocumentIndex,
13175
- rectX = _k.rectX,
13176
- rectY = _k.rectY,
13177
- rectWidth = _k.rectWidth,
13178
- rectHeight = _k.rectHeight,
13179
- rectOffsetTop = _k.rectOffsetTop,
13180
- capturing = _k.capturing,
13181
- uploadCapturedDocument = _k.uploadCapturedDocument,
13182
- dispatch = _j[1];
13183
- var _l = (_b = documents[currentDocumentIndex]) !== null && _b !== void 0 ? _b : {},
13184
- title = _l.title,
13185
- aspectRatio = _l.aspectRatio,
13186
- cameraFeedMode = _l.cameraFeedMode,
13187
- instructions = _l.instructions,
13188
- contentUrl = _l.contentUrl,
13189
- content = _l.content,
13190
- uploadState = _l.uploadState;
13191
- var _m = React.useContext(CameraStateContext),
13192
- cameraReady = _m.cameraReady,
13193
- cameraAccessDenied = _m.cameraAccessDenied,
13194
- requestCameraAccess = _m.requestCameraAccess;
13195
- var _o = React.useState(false),
13196
- cameraAccessRequested = _o[0],
13197
- setCameraAccessRequested = _o[1];
13198
- var cameraAccessNeeded = uploadState === 'not_started' && !cameraAccessRequested && !content;
13197
+ _j = _a.classNames,
13198
+ classNames = _j === void 0 ? {} : _j,
13199
+ _k = _a.verbiage,
13200
+ rawVerbiage = _k === void 0 ? {} : _k;
13201
+ var _l = useDocumentCaptureState(),
13202
+ _m = _l[0],
13203
+ documents = _m.documents,
13204
+ currentDocumentIndex = _m.currentDocumentIndex,
13205
+ rectX = _m.rectX,
13206
+ rectY = _m.rectY,
13207
+ rectWidth = _m.rectWidth,
13208
+ rectHeight = _m.rectHeight,
13209
+ rectOffsetTop = _m.rectOffsetTop,
13210
+ capturing = _m.capturing,
13211
+ uploadCapturedDocument = _m.uploadCapturedDocument,
13212
+ dispatch = _l[1];
13213
+ var _o = (_b = documents[currentDocumentIndex]) !== null && _b !== void 0 ? _b : {},
13214
+ title = _o.title,
13215
+ aspectRatio = _o.aspectRatio,
13216
+ cameraFeedMode = _o.cameraFeedMode,
13217
+ instructions = _o.instructions,
13218
+ contentUrl = _o.contentUrl,
13219
+ content = _o.content,
13220
+ uploadState = _o.uploadState;
13221
+ var _p = React.useContext(CameraStateContext),
13222
+ cameraRef = _p.cameraRef,
13223
+ cameraReady = _p.cameraReady,
13224
+ cameraAccessDenied = _p.cameraAccessDenied,
13225
+ requestCameraAccess = _p.requestCameraAccess;
13226
+ var _q = React.useState(false),
13227
+ cameraAccessRequested = _q[0],
13228
+ setCameraAccessRequested = _q[1];
13229
+ var cameraAccessNeeded =
13230
+ // we should force the browser to ask for camera access if...
13231
+ uploadState === 'not_started' &&
13232
+ // we aren't in the middle of uploading a document...
13233
+ !content &&
13234
+ // and the user hasn't passed a media blob for the current document...
13235
+ !cameraAccessRequested &&
13236
+ // and we haven't already tried to force a camera request...
13237
+ !((_d = (_c = cameraRef.current) === null || _c === void 0 ? void 0 : _c.stream) === null || _d === void 0 ? void 0 : _d.active); // and we don't already have camera access.
13199
13238
  React.useEffect(function requestCameraAccessIfNeeded() {
13200
13239
  if (!cameraAccessNeeded) return;
13201
13240
  setCameraAccessRequested(true);
13202
13241
  requestCameraAccess();
13203
13242
  }, [cameraAccessNeeded, requestCameraAccess]);
13204
13243
  var theme = styled.useTheme();
13205
- var maskColor = (_e = (_d = (_c = theme.documentCapture) === null || _c === void 0 ? void 0 : _c.guideBox) === null || _d === void 0 ? void 0 : _d.maskColor) !== null && _e !== void 0 ? _e : cameraFeedMode === 'snapToGuides' ? '#708090' : "rgba(0, 0, 0, 0.5)";
13244
+ var maskColor = (_g = (_f = (_e = theme.documentCapture) === null || _e === void 0 ? void 0 : _e.guideBox) === null || _f === void 0 ? void 0 : _f.maskColor) !== null && _g !== void 0 ? _g : cameraFeedMode === 'snapToGuides' ? '#708090' : "rgba(0, 0, 0, 0.5)";
13206
13245
  var verbiage = useTranslations(rawVerbiage, {
13207
13246
  headingText: title,
13208
13247
  loadingBtnText: 'Camera initializing...',
@@ -13235,7 +13274,7 @@ var DocumentCaptureScreen = function DocumentCaptureScreen(_a) {
13235
13274
  });
13236
13275
  }
13237
13276
  return /*#__PURE__*/React__default['default'].createElement(PageContainer, {
13238
- className: "flex ".concat((_f = classNames.container) !== null && _f !== void 0 ? _f : '')
13277
+ className: "flex ".concat((_h = classNames.container) !== null && _h !== void 0 ? _h : '')
13239
13278
  }, /*#__PURE__*/React__default['default'].createElement(CameraFeedWrapper, {
13240
13279
  className: classNames.cameraFeedWrapper,
13241
13280
  "$mode": cameraFeedMode !== null && cameraFeedMode !== void 0 ? cameraFeedMode : 'snapToGuides',
@@ -14629,9 +14668,12 @@ var SelfieCaptureFallback = function SelfieCaptureFallback(_a) {
14629
14668
  }],
14630
14669
  onDocumentCaptured: function onDocumentCaptured(document) {
14631
14670
  var imageData = document.contentUrl;
14632
- setImage(imageData);
14633
- setUsingDocumentCapture(false);
14634
14671
  onCapture === null || onCapture === void 0 ? void 0 : onCapture(imageData);
14672
+ // todo: this a hack to address what is probably some sub-optimal coupling - fix
14673
+ setTimeout(function () {
14674
+ setImage(imageData);
14675
+ setUsingDocumentCapture(false);
14676
+ }, 0);
14635
14677
  }
14636
14678
  });
14637
14679
  }