@regulaforensics/ionic-native-document-reader 6.9.1 → 7.2.0

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.
Files changed (83) hide show
  1. package/README.md +10 -9
  2. package/example/README.md +8 -6
  3. package/example/config.xml +5 -8
  4. package/example/package.json +14 -23
  5. package/example/src/app/home/home.module.ts +2 -4
  6. package/example/src/app/home/home.page.ts +81 -158
  7. package/index.d.ts +785 -491
  8. package/index.js +933 -277
  9. package/ngx/index.d.ts +785 -491
  10. package/ngx/index.js +937 -281
  11. package/package.json +1 -1
  12. package/reactExample/.browserslistrc +6 -0
  13. package/reactExample/.eslintrc.js +17 -0
  14. package/reactExample/README.md +9 -6
  15. package/reactExample/android/app/build.gradle +3 -0
  16. package/reactExample/android/app/capacitor.build.gradle +22 -0
  17. package/reactExample/android/app/src/main/AndroidManifest.xml +4 -7
  18. package/reactExample/android/app/src/main/assets/Regula/.gitkeep +0 -0
  19. package/reactExample/android/app/src/main/res/values/styles.xml +2 -2
  20. package/reactExample/android/build.gradle +9 -5
  21. package/reactExample/android/capacitor.settings.gradle +15 -0
  22. package/reactExample/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  23. package/reactExample/android/gradle/wrapper/gradle-wrapper.properties +2 -1
  24. package/reactExample/android/gradle.properties +0 -2
  25. package/reactExample/android/gradlew +164 -105
  26. package/reactExample/android/gradlew.bat +92 -89
  27. package/reactExample/android/variables.gradle +14 -12
  28. package/reactExample/capacitor.config.ts +4 -2
  29. package/reactExample/cypress/e2e/test.cy.ts +6 -0
  30. package/reactExample/cypress/fixtures/example.json +5 -0
  31. package/reactExample/cypress/support/commands.ts +37 -0
  32. package/reactExample/cypress/support/e2e.ts +20 -0
  33. package/reactExample/cypress.config.ts +10 -0
  34. package/reactExample/index.html +116 -0
  35. package/reactExample/ionic.config.json +6 -6
  36. package/reactExample/ios/App/App/App.entitlements +0 -1
  37. package/reactExample/ios/App/App/AppDelegate.swift +0 -11
  38. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/Contents.json +6 -108
  39. package/reactExample/ios/App/App/Info.plist +4 -4
  40. package/reactExample/ios/App/App.xcodeproj/project.pbxproj +14 -22
  41. package/reactExample/ios/App/Podfile +7 -3
  42. package/reactExample/package.json +58 -82
  43. package/reactExample/public/assets/.gitkeep +0 -0
  44. package/reactExample/src/components/ExploreContainer.css +24 -0
  45. package/reactExample/src/components/ExploreContainer.tsx +14 -0
  46. package/reactExample/src/main.tsx +11 -0
  47. package/reactExample/src/pages/Home.tsx +90 -161
  48. package/reactExample/src/theme/variables.css +6 -0
  49. package/reactExample/src/vite-env.d.ts +1 -0
  50. package/reactExample/tsconfig.json +10 -16
  51. package/reactExample/tsconfig.node.json +9 -0
  52. package/reactExample/vite.config.ts +16 -0
  53. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-20x20@1x.png +0 -0
  54. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-20x20@2x-1.png +0 -0
  55. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-20x20@2x.png +0 -0
  56. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-20x20@3x.png +0 -0
  57. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-29x29@1x.png +0 -0
  58. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-29x29@2x-1.png +0 -0
  59. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-29x29@2x.png +0 -0
  60. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-29x29@3x.png +0 -0
  61. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-40x40@1x.png +0 -0
  62. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-40x40@2x-1.png +0 -0
  63. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-40x40@2x.png +0 -0
  64. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-40x40@3x.png +0 -0
  65. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-60x60@2x.png +0 -0
  66. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-60x60@3x.png +0 -0
  67. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-76x76@1x.png +0 -0
  68. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-76x76@2x.png +0 -0
  69. package/reactExample/ios/App/App/Assets.xcassets/AppIcon.appiconset/AppIcon-83.5x83.5@2x.png +0 -0
  70. package/reactExample/ios/App/App/capacitor.config.json +0 -6
  71. package/reactExample/ios/App/App/config.xml +0 -19
  72. package/reactExample/ios/App/App.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  73. package/reactExample/public/assets/icon/icon.png +0 -0
  74. package/reactExample/public/assets/shapes.svg +0 -1
  75. package/reactExample/public/index.html +0 -114
  76. package/reactExample/src/assets/img/id.png +0 -0
  77. package/reactExample/src/assets/img/portrait.png +0 -0
  78. package/reactExample/src/index.tsx +0 -22
  79. package/reactExample/src/react-app-env.d.ts +0 -1
  80. package/reactExample/src/reportWebVitals.ts +0 -15
  81. package/reactExample/src/service-worker.ts +0 -80
  82. package/reactExample/src/serviceWorkerRegistration.ts +0 -142
  83. /package/reactExample/public/{assets/icon/favicon.png → favicon.png} +0 -0
package/README.md CHANGED
@@ -1,18 +1,19 @@
1
- # Regula Document Reader (Ionic)
1
+ # Regula Document Reader SDK for Ionic
2
+
2
3
  Regula Document Reader SDK allows you to read various kinds of identification documents, passports, driving licenses, ID cards, etc. All processing is performed completely _**offline**_ on your device. No any data leaving your device.
3
4
 
4
5
  You can use native camera to scan the documents or image from gallery for extract all data from it.
5
6
 
6
7
  This repository contains the source code of the Document Reader API, and the sample application that demonstrates the _**API**_ calls you can use to interact with the Document Reader library.
7
8
 
8
- # Contents
9
- * [Documentation](#documentation)
10
- * [Additional information](#additional-information)
11
-
12
9
  ## Documentation
13
- You can find documentation on API [here](https://docs.regulaforensics.com/develop/doc-reader-sdk/mobile/ionic).
14
10
 
15
- ## Additional information
16
- If you have any technical questions, feel free to [contact](mailto:dev.support@regulaforensics.com) us or create issue [here](https://github.com/regulaforensics/DocumentReader-Ionic-Plugin/issues).
11
+ You can find documentation [here](https://docs.regulaforensics.com/develop/doc-reader-sdk/mobile/ionic).
12
+
13
+ ## License
14
+
15
+ To obtaining the production license or other purchasing information, please [submit an inquiry](https://regulaforensics.com/talk-to-an-expert) and our sales team will contact you shortly.
16
+
17
+ ## Support
17
18
 
18
- To use our SDK in your own app you need to [purchase](https://pipedrivewebforms.com/form/394a3706041290a04fbd0d18e7d7810f1841159) a commercial license.
19
+ Please do not hesitate to [contact us](https://support.regulaforensics.com/hc/requests/new), if you need any assistance or want to report a bug / suggest an improvement.
package/example/README.md CHANGED
@@ -1,19 +1,21 @@
1
1
  # How to build demo application
2
- 1. Visit [licensing.regulaforensics.com](https://licensing.regulaforensics.com) to get a trial license (`regula.license` file). The license creation wizard will guide you through the necessary steps.
3
- 2. Download or clone this repository using the command `git clone https://github.com/regulaforensics/DocumentReader-Ionic-Plugin.git`.
4
- 3. Run the following commands in Terminal:
2
+ 1. Get the trial license at [client.regulaforensics.com](https://client.regulaforensics.com/) (`regula.license` file). The license creation wizard will guide you through the necessary steps.
3
+ 2. Get the trial database at [client.regulaforensics.com/customer/databases](https://client.regulaforensics.com/customer/databases) (`db.dat`)
4
+ 3. Download or clone this repository using the command `git clone https://github.com/regulaforensics/DocumentReader-Ionic-Plugin.git`.
5
+ 4. Copy the `regula.license` file to the `example/src/assets/` folder.
6
+ 5. Copy the `db.dat` file to the `example/src/assets/` folder.
7
+ 6. Run the following commands in Terminal:
5
8
  ```bash
6
9
  $ cd example
7
10
  $ npm install
8
11
  $ npx jetify
9
12
  $ ionic cordova prepare
10
13
  ```
11
- 4. Copy the `regula.license` file to the `example/src/assets` folder.
12
14
 
13
- 5. Android:
15
+ 7. Android:
14
16
  * Run `ionic cordova build android`, then`ionic cordova run android` inside `example` folder - this is just one way to run the app. You can also run it directly from within Android Studio.
15
17
 
16
- 6. iOS:
18
+ 8. iOS:
17
19
  * Run `ionic cordova build ios`, then `ionic cordova run ios` inside `example` folder - this is just one way to run the app. You can also run it directly from within Xcode.
18
20
 
19
21
 
@@ -19,22 +19,17 @@
19
19
  <preference name="SplashScreen" value="screen" />
20
20
  <preference name="SplashScreenDelay" value="3000" />
21
21
  <platform name="android">
22
+ <resource-file src="src/assets/db.dat" target="app/src/main/assets/Regula/db.dat"/>
22
23
  <framework src="com.android.support:appcompat-v7:+" />
23
24
  <config-file parent="/*" target="AndroidManifest.xml">
24
25
  <uses-permission android:name="android.permission.NFC" />
25
26
  <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
26
27
  <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
27
28
  </config-file>
28
- <config-file parent="/manifest/application" target="AndroidManifest.xml">
29
- <activity android:label="@string/multi_app_name" android:name="com.synconset.MultiImageChooserActivity" android:theme="@style/Theme.AppCompat.Light" />
30
- </config-file>
31
29
 
32
30
  <preference name="android-minSdkVersion" value="21" />
33
31
  <preference name="android-targetSdkVersion" value="33" />
34
- <preference name="AndroidXEnabled" value="true" />
35
32
  <preference name="GradlePluginKotlinEnabled" value="true" />
36
- <preference name="GradlePluginKotlinCodeStyle" value="official" />
37
- <preference name="GradlePluginKotlinVersion" value="1.7.10" />
38
33
 
39
34
  <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
40
35
  <allow-intent href="market:*" />
@@ -58,12 +53,15 @@
58
53
  <splash density="port-xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png" />
59
54
  </platform>
60
55
  <platform name="ios">
56
+ <resource-file src="src/assets/db.dat" />
61
57
  <allow-intent href="itms:*" />
62
58
  <allow-intent href="itms-apps:*" />
63
- <preference default=" " name="CAMERA_USAGE_DESCRIPTION" />
64
59
  <config-file parent="NSCameraUsageDescription" target="*-Info.plist">
65
60
  <string>To use camera</string>
66
61
  </config-file>
62
+ <config-file parent="NSPhotoLibraryUsageDescription" target="*-Info.plist">
63
+ <string>To pick images</string>
64
+ </config-file>
67
65
  <config-file parent="NFCReaderUsageDescription" target="*-Info.plist">
68
66
  <string>To use NFC</string>
69
67
  </config-file>
@@ -136,7 +134,6 @@
136
134
  <splash height="2436" src="resources/ios/splash/Default-2436h.png" width="1125" />
137
135
  <splash height="2732" src="resources/ios/splash/Default@2x~universal~anyany.png" width="2732" />
138
136
  </platform>
139
- <plugin name="cordova-plugin-whitelist" spec="1.3.3" />
140
137
  <plugin name="cordova-plugin-statusbar" spec="2.4.2" />
141
138
  <plugin name="cordova-plugin-device" spec="2.0.2" />
142
139
  <plugin name="cordova-plugin-splashscreen" spec="5.0.2" />
@@ -13,29 +13,27 @@
13
13
  },
14
14
  "private": true,
15
15
  "dependencies": {
16
+ "@regulaforensics/cordova-plugin-document-reader-api": "7.2.0",
17
+ "@regulaforensics/cordova-plugin-document-reader-core-fullrfid": "7.2.0",
18
+ "@regulaforensics/ionic-native-document-reader": "7.2.0",
19
+ "cordova-plugin-camera": "7.0.0",
20
+ "@awesome-cordova-plugins/camera": "6.6.0",
21
+ "@awesome-cordova-plugins/core": "6.6.0",
22
+ "@awesome-cordova-plugins/file": "6.6.0",
23
+ "@awesome-cordova-plugins/splash-screen": "6.6.0",
24
+ "@awesome-cordova-plugins/status-bar": "6.6.0",
16
25
  "@angular/common": "~13.3.2",
17
26
  "@angular/core": "~13.3.2",
18
27
  "@angular/forms": "~13.3.2",
19
28
  "@angular/platform-browser": "~13.3.2",
20
29
  "@angular/platform-browser-dynamic": "~13.3.2",
21
30
  "@angular/router": "~13.3.2",
22
- "@awesome-cordova-plugins/android-permissions": "^5.28.0",
23
- "@awesome-cordova-plugins/core": "^5.28.0",
24
- "@awesome-cordova-plugins/file": "^5.28.0",
25
- "@awesome-cordova-plugins/image-picker": "^5.28.0",
26
- "@awesome-cordova-plugins/splash-screen": "^5.28.0",
27
- "@awesome-cordova-plugins/status-bar": "^5.28.0",
28
31
  "@ionic/angular": "^6.0.15",
29
32
  "@ionic/cordova-builders": "^6.1.0",
30
- "cordova-ios": "^6.2.0",
31
- "@regulaforensics/cordova-plugin-document-reader-api": "6.9.1",
32
- "@regulaforensics/cordova-plugin-document-reader-core-fullrfid": "6.9.0",
33
- "@regulaforensics/ionic-native-document-reader": "6.9.1",
34
- "cordova-android": "^10.1.1",
33
+ "cordova-android": "12.0.1",
34
+ "cordova-ios": "6.3.0",
35
35
  "cordova-plugin-add-swift-support": "^2.0.2",
36
- "cordova-plugin-android-permissions": "^1.1.0",
37
- "cordova-plugin-file": "^6.0.2",
38
- "cordova-plugin-telerik-imagepicker": "^2.3.5",
36
+ "cordova-plugin-file": "8.0.1",
39
37
  "core-js": "^3.6.5",
40
38
  "rxjs": "~6.6.3",
41
39
  "tslib": "^2.0.1",
@@ -61,7 +59,6 @@
61
59
  "cordova-plugin-ionic-webview": "^5.0.0",
62
60
  "cordova-plugin-splashscreen": "^6.0.0",
63
61
  "cordova-plugin-statusbar": "^2.4.3",
64
- "cordova-plugin-whitelist": "^1.3.5",
65
62
  "jasmine-core": "~4.0.1",
66
63
  "jasmine-spec-reporter": "~6.0.0",
67
64
  "karma": "~6.3.17",
@@ -79,18 +76,12 @@
79
76
  "plugins": {
80
77
  "@regulaforensics/cordova-plugin-document-reader-api": {},
81
78
  "@regulaforensics/cordova-plugin-document-reader-core-fullrfid": {},
82
- "cordova-plugin-android-permissions": {},
83
- "cordova-plugin-telerik-imagepicker": {
84
- "PHOTO_LIBRARY_USAGE_DESCRIPTION": " "
85
- },
79
+ "cordova-plugin-camera": {},
86
80
  "cordova-plugin-file": {},
87
- "cordova-plugin-whitelist": {},
88
81
  "cordova-plugin-statusbar": {},
89
82
  "cordova-plugin-device": {},
90
83
  "cordova-plugin-splashscreen": {},
91
- "cordova-plugin-ionic-webview": {
92
- "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
93
- },
84
+ "cordova-plugin-ionic-webview": {},
94
85
  "cordova-plugin-ionic-keyboard": {}
95
86
  },
96
87
  "platforms": [
@@ -3,8 +3,7 @@ import { CommonModule } from '@angular/common';
3
3
  import { IonicModule } from '@ionic/angular';
4
4
  import { FormsModule } from '@angular/forms';
5
5
  import { RouterModule } from '@angular/router';
6
- import { ImagePicker } from "@awesome-cordova-plugins/image-picker/ngx";
7
- import { AndroidPermissions } from '@awesome-cordova-plugins/android-permissions/ngx';
6
+ import { Camera } from "@awesome-cordova-plugins/camera/ngx"
8
7
  import { DocumentReader } from '@regulaforensics/ionic-native-document-reader/ngx';
9
8
 
10
9
  import { HomePage } from './home.page';
@@ -22,8 +21,7 @@ import { HomePage } from './home.page';
22
21
  ])
23
22
  ],
24
23
  providers:[
25
- ImagePicker,
26
- AndroidPermissions,
24
+ Camera,
27
25
  DocumentReader
28
26
  ],
29
27
  declarations: [HomePage]
@@ -1,9 +1,8 @@
1
1
  import { Component, ViewChild, ElementRef } from '@angular/core'
2
2
  import { File } from '@awesome-cordova-plugins/file'
3
- import { ImagePicker } from '@awesome-cordova-plugins/image-picker/ngx'
4
- import { AndroidPermissions } from '@awesome-cordova-plugins/android-permissions/ngx'
3
+ import { Camera, DestinationType, MediaType, PictureSourceType } from '@awesome-cordova-plugins/camera/ngx'
5
4
  import { Platform } from '@ionic/angular'
6
- import { DocumentReader, DocumentReaderScenario, Enum, DocumentReaderCompletion, DocumentReaderResults, DocumentReaderNotification, ScannerConfig, RecognizeConfig } from '@regulaforensics/ionic-native-document-reader/ngx'
5
+ import { DocumentReader, DocumentReaderScenario, Enum, DocumentReaderCompletion, DocumentReaderResults, DocumentReaderNotification, ScannerConfig, RecognizeConfig, DocReaderConfig, Functionality } from '@regulaforensics/ionic-native-document-reader/ngx'
7
6
 
8
7
  var selectedScenario = "Mrz"
9
8
  var doRfid: boolean = false
@@ -36,71 +35,54 @@ export class HomePage {
36
35
  @ViewChild('rfidProgress', { static: false }) rfidProgress: ElementRef
37
36
  @ViewChild('cancelButton', { static: false }) cancelButton: ElementRef
38
37
 
39
- constructor(public DocumentReader: DocumentReader, public platform: Platform, private imagePicker: ImagePicker, private androidPermissions: AndroidPermissions) {
38
+ constructor(public DocumentReader: DocumentReader, public platform: Platform, private camera: Camera) {
40
39
  }
41
40
 
42
41
  ionViewDidEnter() {
43
- var app = this
44
- var DocumentReader = this.DocumentReader
45
- var error1 = e => {
46
- console.log(e)
47
- this.status.nativeElement.innerHTML = e
48
- this.status.nativeElement.style.backgroundColor = "red"
49
- }
50
- var error2 = e => {
51
- e = JSON.stringify(e, undefined, 2)
52
- console.log(e)
53
- alert(e)
42
+ function onInitialized() {
43
+ app.status.nativeElement.innerHTML = "Ready"
44
+ app.status.nativeElement.style.backgroundColor = "green"
45
+
46
+ var functionality = new Functionality()
47
+ functionality.showCaptureButton = true
48
+ DocumentReader.setFunctionality(functionality)
54
49
  }
55
50
 
56
- app.cancelButton.nativeElement.addEventListener("click", stopRfid)
51
+ var app = this
52
+ var DocumentReader = this.DocumentReader
53
+ app.cancelButton.nativeElement.addEventListener("click", hideRfidUI)
57
54
  updateUI()
58
55
  app.status.nativeElement.innerHTML = "loading......"
59
56
  app.status.nativeElement.style.backgroundColor = "grey"
60
57
  app.platform.ready().then(() => {
61
- readFile("www/assets", "regula.license", (license) => {
62
- DocumentReader.prepareDatabase("Full").subscribe(r => {
63
- if (r != "database prepared")
64
- app.status.nativeElement.innerHTML = "Downloading database: " + r + "%"
65
- else {
66
- app.status.nativeElement.innerHTML = "Loading......"
67
- DocumentReader.initializeReader({
68
- license: license,
69
- delayedNNLoad: true
70
- }).then(m => onInitialized()).catch(error1)
58
+ readFile("www/assets", "regula.license", (license: string) => {
59
+ var config = new DocReaderConfig()
60
+ config.license = license
61
+ config.delayedNNLoad = true
62
+ DocumentReader.initializeReader(config).then((message: string) => {
63
+ var callback = JSON.parse(message)
64
+ if (!callback.success) {
65
+ var error = "Init error: " + callback.error.message
66
+ console.log(error)
67
+ this.status.nativeElement.innerHTML = error
68
+ this.status.nativeElement.style.backgroundColor = "red"
69
+ return
71
70
  }
71
+ console.log("Init complete")
72
+ app.showScannerButton.nativeElement.addEventListener("click", scan)
73
+ app.showImagePicker.nativeElement.addEventListener("click", recognize)
74
+ DocumentReader.getAvailableScenarios().then(sc =>
75
+ DocumentReader.getIsRFIDAvailableForUse().then((canRfid: boolean) =>
76
+ postInitialize(JSON.parse(sc), canRfid)))
77
+ onInitialized()
72
78
  })
73
79
  })
74
80
  })
75
81
 
76
- function addCertificates() {
77
- File.resolveDirectoryUrl(File.applicationDirectory + "certificates").then(dir => {
78
- dir.createReader().readEntries(entries => {
79
- for (let i = 0; i < entries.length; i++) {
80
- if (entries[i].isFile) {
81
- var findExt = entries[i].name.split('.')
82
- var pkdResourceType = 0
83
- if (findExt.length > 0)
84
- pkdResourceType = Enum.PKDResourceType.getType(findExt[findExt.length - 1].toLowerCase())
85
- readFile("certificates", entries[i].name, (file, resType) => {
86
- resType = resType[0]
87
- var certificates = []
88
- certificates.push({
89
- 'binaryData': file,
90
- 'resourceType': resType
91
- })
92
- DocumentReader.addPKDCertificates(certificates).then(s => console.log("certificate added")).catch(e => console.log(e))
93
- }, pkdResourceType)
94
- }
95
- }
96
- })
97
- })
98
- }
99
-
100
- function readFile(dirPath: string, fileName: string, callback, ...items) {
82
+ function readFile(dirPath: string, fileName: string, callback: any, ...items: any) {
101
83
  File.resolveDirectoryUrl(File.applicationDirectory + dirPath).then(dir => File.getFile(dir, fileName, null).then(fileEntry => fileEntry.file(file => {
102
84
  var reader = new FileReader()
103
- reader.onloadend = (evt) => {
85
+ reader.onloadend = (_) => {
104
86
  var data = reader.result as String
105
87
  data = data.substring(data.indexOf(',') + 1)
106
88
  callback(data, items)
@@ -118,32 +100,27 @@ export class HomePage {
118
100
  app.rfidProgress.nativeElement.value = rfidProgress
119
101
  }
120
102
 
121
- function stopRfid() {
122
- hideRfidUI()
123
- DocumentReader.stopRFIDReader()
124
- }
125
-
126
103
  function handleCompletion(completion: DocumentReaderCompletion) {
127
- console.log("DocReaderAction: " + completion.action)
128
- if (isReadingRfidCustomUi && (completion.action === Enum.DocReaderAction.CANCEL || completion.action === Enum.DocReaderAction.ERROR))
129
- hideRfidUI()
130
- if (isReadingRfidCustomUi && completion.action === Enum.DocReaderAction.NOTIFICATION)
131
- updateRfidUI(completion.results.documentReaderNotification)
132
- if (completion.action === Enum.DocReaderAction.COMPLETE)
133
- if (isReadingRfidCustomUi) {
134
- if (completion.results.rfidResult !== 1)
135
- restartRfidUI()
136
- else {
137
- hideRfidUI()
138
- displayResults(completion.results)
139
- }
104
+ if (isReadingRfidCustomUi) {
105
+ if (completion.action == Enum.DocReaderAction.ERROR) restartRfidUI()
106
+ if (actionSuccess(completion.action) || actionError(completion.action)) {
107
+ hideRfidUI()
108
+ displayResults(completion.results)
140
109
  }
141
- else
142
- handleResults(completion.results)
143
- if (completion.action === Enum.DocReaderAction.TIMEOUT)
110
+ } else if (actionSuccess(completion.action) || actionError(completion.action))
144
111
  handleResults(completion.results)
145
112
  }
146
113
 
114
+ function actionSuccess(action: number) {
115
+ if (action == Enum.DocReaderAction.COMPLETE || action == Enum.DocReaderAction.TIMEOUT) return true
116
+ return false
117
+ }
118
+
119
+ function actionError(action: number) {
120
+ if (action == Enum.DocReaderAction.CANCEL || action == Enum.DocReaderAction.ERROR) return true
121
+ return false
122
+ }
123
+
147
124
  function showRfidUI() {
148
125
  // show animation
149
126
  isReadingRfidCustomUi = true
@@ -152,6 +129,7 @@ export class HomePage {
152
129
 
153
130
  function hideRfidUI() {
154
131
  // show animation
132
+ DocumentReader.stopRFIDReader()
155
133
  restartRfidUI()
156
134
  isReadingRfidCustomUi = false
157
135
  rfidUIHeader = "Reading RFID"
@@ -168,77 +146,39 @@ export class HomePage {
168
146
  }
169
147
 
170
148
  function updateRfidUI(notification: DocumentReaderNotification) {
171
- if (notification.progress === undefined) return
172
149
  if (notification.notificationCode === Enum.eRFID_NotificationCodes.RFID_NOTIFICATION_PCSC_READING_DATAGROUP)
173
- rfidDescription = notification.dataFileType.toString()
150
+ rfidDescription = "ERFIDDataFileType: " + notification.dataFileType
174
151
  rfidUIHeader = "Reading RFID"
175
152
  rfidUIHeaderColor = "black"
176
- rfidProgress = notification.progress
153
+ if (notification.progress != undefined)
154
+ rfidProgress = notification.progress
177
155
  updateUI()
178
- if (app.platform.is("ios"))
179
- DocumentReader.setRfidSessionStatus(rfidDescription + "\n" + notification.progress + "%")
180
156
  }
181
157
 
182
158
  function customRFID() {
183
159
  showRfidUI()
184
- DocumentReader.readRFID().subscribe(m => handleRfidCompletion(m))
160
+ DocumentReader.readRFID(false, false, false).subscribe((m: string) => handleRfidCompletion(m))
185
161
  }
186
162
 
187
163
  function usualRFID() {
188
164
  isReadingRfid = true
189
- DocumentReader.startRFIDReader().subscribe(m => handleRfidCompletion(m))
165
+ DocumentReader.startRFIDReader(false, false, false).subscribe((m: string) => handleRfidCompletion(m))
190
166
  }
191
167
 
192
168
  function handleRfidCompletion(raw: string) {
193
- var notification = "rfidNotificationCompletionEvent"
194
- var paCert = "paCertificateCompletionEvent"
195
- var taCert = "taCertificateCompletionEvent"
196
- var taSig = "taSignatureCompletionEvent"
197
- if (raw.substring(0, notification.length) === notification) {
198
- raw = raw.substring(notification.length, raw.length)
199
- console.log(notification + ": " + raw)
200
- } else if (raw.substring(0, paCert.length) === paCert) {
201
- raw = raw.substring(paCert.length, raw.length)
202
- console.log(paCert + ": " + raw)
203
- } else if (raw.substring(0, taCert.length) === taCert) {
204
- raw = raw.substring(taCert.length, raw.length)
205
- console.log(taCert + ": " + raw)
206
- } else if (raw.substring(0, taSig.length) === taSig) {
207
- raw = raw.substring(taSig.length, raw.length)
208
- console.log(taSig + ": " + raw)
209
- } else
169
+ var idDetected = "rfidOnChipDetectedEvent"
170
+ var idProgress = "rfidOnProgressCompletion"
171
+ var idRetry = "rfidOnRetryReadChipEvent"
172
+ if (raw.substring(0, idDetected.length) === idDetected)
173
+ console.log("chip detected")
174
+ else if (raw.substring(0, idRetry.length) === idRetry)
175
+ console.log("error reading chip, retrying...")
176
+ else if (raw.substring(0, idProgress.length) === idProgress)
177
+ updateRfidUI(DocumentReaderNotification.fromJson(JSON.parse(raw.substring(idProgress.length, raw.length))))
178
+ else
210
179
  handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(raw)))
211
180
  }
212
181
 
213
- function onInitialized() {
214
- app.status.nativeElement.innerHTML = "Ready"
215
- app.status.nativeElement.style.backgroundColor = "green"
216
- app.showScannerButton.nativeElement.addEventListener("click", scan)
217
- if (app.platform.is("android"))
218
- app.showImagePicker.nativeElement.addEventListener("click", recognizeAndroid)
219
- if (app.platform.is("ios"))
220
- app.showImagePicker.nativeElement.addEventListener("click", recognize)
221
- DocumentReader.setConfig({
222
- functionality: {
223
- videoCaptureMotionControl: true,
224
- showCaptureButton: true
225
- },
226
- customization: {
227
- showResultStatusMessages: true,
228
- showStatusMessages: true
229
- },
230
- processParams: {
231
- scenario: "Mrz",
232
- doRfid: false
233
- },
234
- })
235
- DocumentReader.getAvailableScenarios().then(sc =>
236
- DocumentReader.isRFIDAvailableForUse().then(canRfid =>
237
- postInitialize(JSON.parse(sc), canRfid)))
238
- DocumentReader.setRfidDelegate(Enum.RFIDDelegate.NO_PA)
239
- // addCertificates()
240
- }
241
-
242
182
  function postInitialize(scenarios: Array<any>, canRfid: boolean) {
243
183
  var inputs = []
244
184
  for (let index of scenarios) {
@@ -310,42 +250,25 @@ export class HomePage {
310
250
  function scan() {
311
251
  var config = new ScannerConfig()
312
252
  config.scenario = selectedScenario
313
- DocumentReader.scan(config).subscribe(m =>
253
+ DocumentReader.scan(config).subscribe((m: string) =>
314
254
  handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(m))))
315
255
  }
316
256
 
317
257
  function recognize() {
318
- app.imagePicker.getPictures({ maximumImagesCount: 1 }).then((results) => {
319
- if (results.length > 0) {
320
- clearResults()
321
- app.status.nativeElement.innerHTML = "copying image......"
322
- app.status.nativeElement.style.backgroundColor = "grey"
323
- }
324
- File.readAsDataURL((app.platform.is("ios") ? "file://" : "") + results[0].substring(0, (results[0] as string).lastIndexOf("/")), results[0].substring((results[0] as string).lastIndexOf("/") + 1)).then((file => {
325
- app.status.nativeElement.innerHTML = "processing image......"
326
- app.status.nativeElement.style.backgroundColor = "grey"
327
- let fileString = (file as string)
328
- var config = new RecognizeConfig()
329
- config.scenario = selectedScenario
330
- config.image = fileString.substring(fileString.indexOf(",") + 1)
331
- DocumentReader.recognize(config).subscribe(m =>
332
- handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(m))))
333
- })).catch(error2)
334
- }, error2)
335
- }
336
-
337
- function recognizeAndroid() {
338
- app.androidPermissions.checkPermission(app.androidPermissions.PERMISSION.READ_EXTERNAL_STORAGE).then(result => {
339
- if (result.hasPermission)
340
- recognize()
341
- else
342
- app.androidPermissions.requestPermission(app.androidPermissions.PERMISSION.READ_EXTERNAL_STORAGE).then(result => {
343
- if (result.hasPermission)
344
- recognize()
345
- else
346
- console.log("storage permission denied")
347
- }, err => console.log(JSON.stringify(err)))
348
- }, err => console.log(JSON.stringify(err)))
258
+ app.camera.getPicture({
259
+ destinationType: DestinationType.DATA_URL,
260
+ mediaType: MediaType.PICTURE,
261
+ sourceType: PictureSourceType.PHOTOLIBRARY
262
+ }).then((result: string) => {
263
+ clearResults()
264
+ app.status.nativeElement.innerHTML = "processing image......"
265
+ app.status.nativeElement.style.backgroundColor = "grey"
266
+ var config = new RecognizeConfig()
267
+ config.scenario = selectedScenario
268
+ config.image = result
269
+ DocumentReader.recognize(config).subscribe((m: string) =>
270
+ handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(m))))
271
+ })
349
272
  }
350
273
  }
351
274
  }