idmission-web-sdk 0.0.27 → 0.0.29

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.
@@ -9,8 +9,6 @@ export type Camera = {
9
9
  };
10
10
  export type CameraResolution = 'LOW' | 'MID' | 'MAX';
11
11
  export declare function selectAndOpenCamera(resolution?: CameraResolution): Promise<Camera>;
12
- export declare function drawFrameToCanvas(videoElement: HTMLVideoElement, canvasElement: HTMLCanvasElement): CanvasRenderingContext2D | null;
13
- export declare function getFrameFromVideo(videoElement: HTMLVideoElement, canvasElement: HTMLCanvasElement | null): ImageData | null;
14
12
  export declare function getVideoDeviceMaxDimensions(deviceInfo: MediaDeviceInfo): Promise<{
15
13
  width: number;
16
14
  height: number;
@@ -22,6 +20,7 @@ type Resolution = {
22
20
  ratio: string;
23
21
  };
24
22
  export declare const quickScan: Resolution[];
23
+ declare function releaseCameraAccess(): void;
25
24
  export declare const useHighestResCaptureDevice: ({ preferFrontFacingCamera, preferContinuityCamera, requestMicrophoneAccess, }?: {
26
25
  preferFrontFacingCamera: boolean;
27
26
  preferContinuityCamera: boolean;
@@ -34,7 +33,7 @@ export declare const useHighestResCaptureDevice: ({ preferFrontFacingCamera, pre
34
33
  cameraRef: import("react").MutableRefObject<Camera | null>;
35
34
  cameraAccessDenied: boolean;
36
35
  retryCameraAccess: () => void;
37
- releaseCameraAccess: () => void;
36
+ releaseCameraAccess: typeof releaseCameraAccess;
38
37
  iphoneContinuityCameraAvailable: boolean;
39
38
  iphoneContinuityCameraAllowed: boolean;
40
39
  setIphoneContinuityCameraAllowed: import("react").Dispatch<import("react").SetStateAction<boolean>>;
@@ -10664,34 +10664,13 @@ function smallerSideIos() {
10664
10664
  return window.screen.width < window.screen.height ? window.screen.width : window.screen.height;
10665
10665
  }
10666
10666
 
10667
- var streamToCamera = function streamToCamera(stream, deviceLabel) {
10668
- var _a = stream.getVideoTracks()[0].getSettings(),
10669
- width = _a.width,
10670
- height = _a.height;
10671
- var label = deviceLabel.toLocaleLowerCase().split(' ').join('');
10672
- console.log('CAMERA LABEL', label);
10673
- var isRearFacing = label.includes('back') || label.includes('iphonecamera');
10674
- var release = function release() {
10675
- stream.getTracks().forEach(function (track) {
10676
- track.stop();
10677
- });
10678
- };
10679
- if (!width) width = 0;
10680
- if (!height) height = 0;
10681
- return {
10682
- stream: stream,
10683
- width: width,
10684
- height: height,
10685
- isRearFacing: isRearFacing,
10686
- release: release
10687
- };
10688
- };
10689
10667
  function listAvailableCameras() {
10690
10668
  return tslib.__awaiter(this, void 0, void 0, function () {
10691
10669
  var cameraEnumerationStream, videoDevices;
10692
10670
  return tslib.__generator(this, function (_a) {
10693
10671
  switch (_a.label) {
10694
10672
  case 0:
10673
+ console.log('enumerating cameras...');
10695
10674
  return [4, navigator.mediaDevices.getUserMedia({
10696
10675
  video: true,
10697
10676
  audio: false
@@ -10705,8 +10684,10 @@ function listAvailableCameras() {
10705
10684
  return kind === 'videoinput';
10706
10685
  });
10707
10686
  cameraEnumerationStream.getVideoTracks().forEach(function (track) {
10687
+ track.enabled = false;
10708
10688
  track.stop();
10709
10689
  });
10690
+ cameraEnumerationStream = null;
10710
10691
  return [2, videoDevices];
10711
10692
  }
10712
10693
  });
@@ -10715,42 +10696,82 @@ function listAvailableCameras() {
10715
10696
  var getDeviceLabel = function getDeviceLabel(deviceInfo) {
10716
10697
  return deviceInfo.label.toLocaleLowerCase().split(' ').join('');
10717
10698
  };
10699
+ var currentCamera;
10700
+ function obtainCameraAccess(stream, deviceLabel, video) {
10701
+ releaseCameraAccess();
10702
+ console.log('obtaining camera access...');
10703
+ var _a = stream.getVideoTracks()[0].getSettings(),
10704
+ width = _a.width,
10705
+ height = _a.height;
10706
+ var label = deviceLabel.toLocaleLowerCase().split(' ').join('');
10707
+ var isRearFacing = label.includes('back') || label.includes('iphonecamera');
10708
+ var release = function release() {
10709
+ stream.getTracks().forEach(function (track) {
10710
+ track.enabled = false;
10711
+ track.stop();
10712
+ });
10713
+ if (video) {
10714
+ video.pause();
10715
+ video.srcObject = null;
10716
+ video.src = '';
10717
+ }
10718
+ };
10719
+ width || (width = 0);
10720
+ height || (height = 0);
10721
+ currentCamera = {
10722
+ stream: stream,
10723
+ width: width,
10724
+ height: height,
10725
+ isRearFacing: isRearFacing,
10726
+ release: release
10727
+ };
10728
+ if (video) video.srcObject = stream;
10729
+ return currentCamera;
10730
+ }
10731
+ function releaseCameraAccess() {
10732
+ if (!currentCamera) return;
10733
+ console.log('releasing camera access...');
10734
+ currentCamera.release();
10735
+ currentCamera = undefined;
10736
+ }
10718
10737
  var useHighestResCaptureDevice = function useHighestResCaptureDevice(_a) {
10719
10738
  var _b = _a === void 0 ? {
10720
10739
  preferFrontFacingCamera: false,
10721
10740
  preferContinuityCamera: true,
10722
10741
  requestMicrophoneAccess: false
10723
10742
  } : _a,
10724
- preferFrontFacingCamera = _b.preferFrontFacingCamera,
10725
- preferContinuityCamera = _b.preferContinuityCamera,
10726
- requestMicrophoneAccess = _b.requestMicrophoneAccess;
10743
+ _c = _b.preferFrontFacingCamera,
10744
+ preferFrontFacingCamera = _c === void 0 ? false : _c,
10745
+ _d = _b.preferContinuityCamera,
10746
+ preferContinuityCamera = _d === void 0 ? true : _d,
10747
+ _e = _b.requestMicrophoneAccess,
10748
+ requestMicrophoneAccess = _e === void 0 ? false : _e;
10727
10749
  var videoRef = React.useRef(null);
10728
10750
  var cameraRef = React.useRef(null);
10729
- var _c = React.useState(null),
10730
- videoDevice = _c[0],
10731
- setVideoDevice = _c[1];
10732
- var _d = React.useState(false),
10733
- videoLoaded = _d[0],
10734
- setVideoLoaded = _d[1];
10735
- var _e = React.useState(null),
10736
- captureDevice = _e[0],
10737
- setCaptureDevice = _e[1];
10738
- var _f = React.useState(false),
10739
- iphoneContinuityCameraAvailable = _f[0],
10740
- setIphoneContinuityCameraAvailable = _f[1];
10741
- var _g = React.useState(preferContinuityCamera),
10742
- iphoneContinuityCameraAllowed = _g[0],
10743
- setIphoneContinuityCameraAllowed = _g[1];
10744
- var _h = React.useState(false),
10745
- iphoneContinuityCameraDenied = _h[0],
10746
- setIphoneContinuityCameraDenied = _h[1];
10751
+ var _f = React.useState(null),
10752
+ videoDevice = _f[0],
10753
+ setVideoDevice = _f[1];
10754
+ var _g = React.useState(false),
10755
+ videoLoaded = _g[0],
10756
+ setVideoLoaded = _g[1];
10757
+ var _h = React.useState(null),
10758
+ captureDevice = _h[0],
10759
+ setCaptureDevice = _h[1];
10747
10760
  var _j = React.useState(false),
10748
- cameraAccessDenied = _j[0],
10749
- setCameraAccessDenied = _j[1];
10761
+ iphoneContinuityCameraAvailable = _j[0],
10762
+ setIphoneContinuityCameraAvailable = _j[1];
10763
+ var _k = React.useState(preferContinuityCamera),
10764
+ iphoneContinuityCameraAllowed = _k[0],
10765
+ setIphoneContinuityCameraAllowed = _k[1];
10766
+ var _l = React.useState(false),
10767
+ iphoneContinuityCameraDenied = _l[0],
10768
+ setIphoneContinuityCameraDenied = _l[1];
10769
+ var _m = React.useState(false),
10770
+ cameraAccessDenied = _m[0],
10771
+ setCameraAccessDenied = _m[1];
10750
10772
  React.useEffect(function () {
10751
- var _a;
10752
10773
  console.log('iphone continuity camera allowed changed', iphoneContinuityCameraAllowed);
10753
- (_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.release();
10774
+ releaseCameraAccess();
10754
10775
  cameraRef.current = null;
10755
10776
  setVideoLoaded(false);
10756
10777
  }, [iphoneContinuityCameraAllowed]);
@@ -10796,13 +10817,11 @@ var useHighestResCaptureDevice = function useHighestResCaptureDevice(_a) {
10796
10817
  } else throw e;
10797
10818
  });
10798
10819
  }, [cameraAccessDenied, iphoneContinuityCameraAllowed, iphoneContinuityCameraDenied, preferFrontFacingCamera]);
10799
- var videoReady = !!videoRef.current;
10800
10820
  React.useEffect(function () {
10801
10821
  var _a;
10802
10822
  if (!videoDevice) return;
10803
10823
  var cleanup = function cleanup() {
10804
- var _a;
10805
- (_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.release();
10824
+ releaseCameraAccess();
10806
10825
  cameraRef.current = null;
10807
10826
  setVideoLoaded(false);
10808
10827
  };
@@ -10880,15 +10899,14 @@ var useHighestResCaptureDevice = function useHighestResCaptureDevice(_a) {
10880
10899
  setCaptureDevice(null);
10881
10900
  }
10882
10901
  };
10883
- cameraRef.current = streamToCamera(stream, videoDevice.label);
10884
- if (videoRef.current) videoRef.current.srcObject = stream;
10902
+ cameraRef.current = obtainCameraAccess(stream, videoDevice.label, videoRef.current);
10885
10903
  return [2];
10886
10904
  }
10887
10905
  });
10888
10906
  });
10889
10907
  })();
10890
10908
  return cleanup;
10891
- }, [iphoneContinuityCameraAllowed, iphoneContinuityCameraAvailable, requestMicrophoneAccess, videoDevice, videoReady]);
10909
+ }, [iphoneContinuityCameraAllowed, iphoneContinuityCameraAvailable, requestMicrophoneAccess, videoDevice]);
10892
10910
  React.useEffect(function () {
10893
10911
  setCaptureDevice(null);
10894
10912
  if (!videoLoaded) return;
@@ -10942,13 +10960,6 @@ var useHighestResCaptureDevice = function useHighestResCaptureDevice(_a) {
10942
10960
  });
10943
10961
  });
10944
10962
  }, []);
10945
- var releaseCameraAccess = React.useCallback(function () {
10946
- var _a, _b;
10947
- if (!cameraRef.current) return;
10948
- console.log('releasing camera access!');
10949
- (_b = (_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.release) === null || _b === void 0 ? void 0 : _b.call(_a);
10950
- cameraRef.current = null;
10951
- }, []);
10952
10963
  return {
10953
10964
  videoRef: videoRef,
10954
10965
  videoDevice: videoDevice,
@@ -11000,11 +11011,8 @@ var CameraProvider = function CameraProvider(_a) {
11000
11011
  setCameraReady(false);
11001
11012
  if (captureDevice) {
11002
11013
  setCameraReady(true);
11003
- takePhoto().then(function () {
11004
- setCameraReady(true);
11005
- });
11006
11014
  }
11007
- }, [captureDevice, takePhoto]);
11015
+ }, [captureDevice]);
11008
11016
  React.useEffect(function () {
11009
11017
  return function () {
11010
11018
  releaseCameraAccess();