@regulaforensics/ionic-native-document-reader 6.4.0 → 6.5.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.
@@ -1,11 +1,12 @@
1
1
  import { IonPage, isPlatform } from '@ionic/react';
2
2
  import { DocumentReader, DocumentReaderScenario, Enum, DocumentReaderCompletion, DocumentReaderResults, DocumentReaderNotification } from '@regulaforensics/ionic-native-document-reader';
3
3
  import React from "react";
4
- import { File } from '@ionic-native/file'
5
- import { AndroidPermissions } from "@ionic-native/android-permissions"
6
- import { ImagePicker } from "@ionic-native/image-picker"
4
+ import { File } from '@awesome-cordova-plugins/file'
5
+ import { AndroidPermissions } from "@awesome-cordova-plugins/android-permissions"
6
+ import { ImagePicker } from "@awesome-cordova-plugins/image-picker"
7
7
 
8
8
  var doRfid: boolean = false
9
+ var isReadingRfidCustomUi: boolean = false
9
10
  var isReadingRfid: boolean = false
10
11
  var rfidUIHeader: string = "Reading RFID"
11
12
  var rfidUIHeaderColor: string = "black"
@@ -44,14 +45,17 @@ status.innerHTML = "loading......"
44
45
  status.style.backgroundColor = "grey"
45
46
  document.addEventListener("deviceready", onDeviceReady, false);
46
47
 
47
- function onDeviceReady(){
48
+ function onDeviceReady() {
48
49
  readFile("public/assets", "regula.license", (license: any) => {
49
50
  DocumentReader.prepareDatabase("Full").subscribe(r => {
50
51
  if (r != "database prepared")
51
52
  status.innerHTML = "Downloading database: " + r + "%"
52
53
  else {
53
54
  status.innerHTML = "Loading......"
54
- DocumentReader.initializeReader(license).then(m => onInitialized()).catch(error1)
55
+ DocumentReader.initializeReader({
56
+ license: license,
57
+ delayedNNLoad: true
58
+ }).then(m => onInitialized()).catch(error1)
55
59
  }
56
60
  })
57
61
  })
@@ -94,8 +98,8 @@ function readFile(dirPath: string, fileName: string, callback: any, ...items: an
94
98
  }
95
99
 
96
100
  function updateUI() {
97
- mainUI.style.display = isReadingRfid ? "none" : ""
98
- rfidUI.style.display = isReadingRfid ? "" : "none"
101
+ mainUI.style.display = isReadingRfidCustomUi ? "none" : ""
102
+ rfidUI.style.display = isReadingRfidCustomUi ? "" : "none"
99
103
  rfidUIHeaderRef.innerHTML = rfidUIHeader
100
104
  rfidUIHeaderRef.style.color = rfidUIHeaderColor
101
105
  rfidDescriptionRef.innerHTML = rfidDescription
@@ -107,34 +111,39 @@ function stopRfid() {
107
111
  DocumentReader.stopRFIDReader()
108
112
  }
109
113
 
110
- function handleCompletion(completion: DocumentReaderCompletion) {
111
- if (isReadingRfid && (completion.action === Enum.DocReaderAction.CANCEL || completion.action === Enum.DocReaderAction.ERROR))
114
+ function handleCompletion(completion?: DocumentReaderCompletion) {
115
+ if (completion == undefined) return;
116
+ if (isReadingRfidCustomUi && (completion.action === Enum.DocReaderAction.CANCEL || completion.action === Enum.DocReaderAction.ERROR))
112
117
  hideRfidUI()
113
- if (isReadingRfid && completion.action === Enum.DocReaderAction.NOTIFICATION)
114
- updateRfidUI(completion.results!!.documentReaderNotification!!)
118
+ if (isReadingRfidCustomUi && completion.action === Enum.DocReaderAction.NOTIFICATION)
119
+ updateRfidUI(completion.results!.documentReaderNotification!)
115
120
  if (completion.action === Enum.DocReaderAction.COMPLETE)
116
- if (isReadingRfid) {
117
- if (completion.results!!.rfidResult !== 1)
121
+ if (isReadingRfidCustomUi) {
122
+ if (completion.results!.rfidResult !== 1)
118
123
  restartRfidUI()
119
124
  else {
120
125
  hideRfidUI()
121
- displayResults(completion.results!!)
126
+ displayResults(completion.results!)
122
127
  }
123
128
  }
124
129
  else
125
- handleResults(completion.results!!)
130
+ handleResults(completion.results!)
131
+ if (completion.action === Enum.DocReaderAction.TIMEOUT)
132
+ handleResults(completion.results!)
133
+ if (completion.action === Enum.DocReaderAction.CANCEL || completion.action === Enum.DocReaderAction.ERROR)
134
+ isReadingRfid = false
126
135
  }
127
136
 
128
137
  function showRfidUI() {
129
138
  // show animation
130
- isReadingRfid = true
139
+ isReadingRfidCustomUi = true
131
140
  updateUI()
132
141
  }
133
142
 
134
143
  function hideRfidUI() {
135
144
  // show animation
136
145
  restartRfidUI()
137
- isReadingRfid = false
146
+ isReadingRfidCustomUi = false
138
147
  rfidUIHeader = "Reading RFID"
139
148
  rfidUIHeaderColor = "black"
140
149
  updateUI()
@@ -150,10 +159,10 @@ function restartRfidUI() {
150
159
 
151
160
  function updateRfidUI(notification: DocumentReaderNotification) {
152
161
  if (notification.code === Enum.eRFID_NotificationCodes.RFID_NOTIFICATION_PCSC_READING_DATAGROUP)
153
- rfidDescription = Enum.eRFID_DataFile_Type.getTranslation(notification.attachment!!)
162
+ rfidDescription = Enum.eRFID_DataFile_Type.getTranslation(notification.attachment!)
154
163
  rfidUIHeader = "Reading RFID"
155
164
  rfidUIHeaderColor = "black"
156
- rfidProgress = notification.value!!
165
+ rfidProgress = notification.value!
157
166
  updateUI()
158
167
  if (isPlatform("ios"))
159
168
  DocumentReader.setRfidSessionStatus(rfidDescription + "\n" + notification.value + "%")
@@ -166,8 +175,7 @@ function customRFID() {
166
175
  }
167
176
 
168
177
  function usualRFID() {
169
- doRfid = false
170
- rfidCheckbox.checked = false
178
+ isReadingRfid = true
171
179
  var notification = "rfidNotificationCompletionEvent"
172
180
  var paCert = "paCertificateCompletionEvent"
173
181
  var taCert = "taCertificateCompletionEvent"
@@ -226,10 +234,10 @@ function postInitialize(scenarios: Array<any>, canRfid: boolean) {
226
234
  inputs.push(input)
227
235
  input.type = "radio"
228
236
  input.name = "scenario"
229
- input.value = (DocumentReaderScenario.fromJson(typeof index === "string" ? JSON.parse(index) : index).name)!!
237
+ input.value = (DocumentReaderScenario.fromJson(typeof index === "string" ? JSON.parse(index) : index)!.name)!
230
238
  if (index == 0)
231
239
  input.checked = true
232
- input.onclick = () => DocumentReader.setConfig({ processParams: { scenario: DocumentReaderScenario.fromJson(typeof index === "string" ? JSON.parse(index) : index).name } })
240
+ input.onclick = () => DocumentReader.setConfig({ processParams: { scenario: DocumentReaderScenario.fromJson(typeof index === "string" ? JSON.parse(index) : index)!.name } })
233
241
  input.style.display = "inline-block"
234
242
  }
235
243
  for (let input of inputs) {
@@ -252,29 +260,22 @@ function postInitialize(scenarios: Array<any>, canRfid: boolean) {
252
260
 
253
261
  function handleResults(results: DocumentReaderResults) {
254
262
  clearResults()
255
- if (doRfid && results != null && results.chipPage != 0) {
256
- var accessKey = results.getTextFieldValueByType!!({ fieldType: 51 })
257
- if (accessKey != null && accessKey != "") {
258
- accessKey = accessKey.replace(/^/g, '').replace(/\n/g, '')
259
- DocumentReader.setRfidScenario({ mMrz: accessKey, mPacePasswordType: 1, })
260
- } else {
261
- accessKey = results.getTextFieldValueByType!!({ fieldType: 159 })
262
- if (accessKey != null && accessKey != "")
263
- DocumentReader.setRfidScenario({ mMrz: accessKey, mPacePasswordType: 2, })
264
- }
263
+ if (doRfid && !isReadingRfid && results != null && results.chipPage != 0) {
265
264
  // customRFID()
266
265
  usualRFID()
267
- } else
266
+ } else {
267
+ isReadingRfid = false
268
268
  displayResults(results)
269
+ }
269
270
  }
270
271
 
271
272
  function displayResults(results: DocumentReaderResults) {
272
- status.innerHTML = results.getTextFieldValueByType!!({ fieldType: Enum.eVisualFieldType.FT_SURNAME_AND_GIVEN_NAMES })
273
+ status.innerHTML = results.getTextFieldValueByType({ fieldType: Enum.eVisualFieldType.FT_SURNAME_AND_GIVEN_NAMES })!
273
274
  status.style.backgroundColor = "green"
274
- if (results.getGraphicFieldImageByType!!({ fieldType: Enum.eGraphicFieldType.GF_DOCUMENT_IMAGE }) != null)
275
- documentImage.src = "data:image/png;base64," + results.getGraphicFieldImageByType!!({ fieldType: Enum.eGraphicFieldType.GF_DOCUMENT_IMAGE })
276
- if (results.getGraphicFieldImageByType!!({ fieldType: Enum.eGraphicFieldType.GF_PORTRAIT }) != null)
277
- portraitImage.src = "data:image/png;base64," + results.getGraphicFieldImageByType!!({ fieldType: Enum.eGraphicFieldType.GF_PORTRAIT })
275
+ if (results.getGraphicFieldImageByType({ fieldType: Enum.eGraphicFieldType.GF_DOCUMENT_IMAGE }) != null)
276
+ documentImage.src = "data:image/png;base64," + results.getGraphicFieldImageByType({ fieldType: Enum.eGraphicFieldType.GF_DOCUMENT_IMAGE })
277
+ if (results.getGraphicFieldImageByType({ fieldType: Enum.eGraphicFieldType.GF_PORTRAIT }) != null)
278
+ portraitImage.src = "data:image/png;base64," + results.getGraphicFieldImageByType({ fieldType: Enum.eGraphicFieldType.GF_PORTRAIT })
278
279
  }
279
280
 
280
281
  function clearResults() {