@regulaforensics/document-reader 8.2.186-beta → 8.2.204-beta

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 (53) hide show
  1. package/RNDocumentReader.podspec +2 -2
  2. package/android/build.gradle +2 -2
  3. package/android/cordova.gradle +2 -2
  4. package/android/src/main/java/com/regula/plugin/documentreader/Config.kt +2 -0
  5. package/android/src/main/java/com/regula/plugin/documentreader/Main.kt +6 -0
  6. package/examples/capacitor/package.json +1 -1
  7. package/examples/capacitor/src/extra/bt_device.tsx +2 -2
  8. package/examples/capacitor/src/extra/custom_rfid.tsx +29 -42
  9. package/examples/capacitor/src/main.tsx +85 -53
  10. package/examples/cordova/config.xml +3 -2
  11. package/examples/cordova/package.json +1 -1
  12. package/examples/cordova/www/images/portrait.png +0 -0
  13. package/examples/cordova/www/index.html +2 -17
  14. package/examples/cordova/www/index.js +40 -0
  15. package/examples/cordova/www/src/extra/bt_device.js +31 -0
  16. package/examples/cordova/www/src/extra/custom_rfid.js +60 -0
  17. package/examples/cordova/www/src/main.css +7 -6
  18. package/examples/cordova/www/src/main.html +10 -32
  19. package/examples/cordova/www/src/main.js +174 -22
  20. package/examples/ionic/config.xml +9 -4
  21. package/examples/ionic/index.ts +1 -2
  22. package/examples/ionic/package-lock.json +1862 -1638
  23. package/examples/ionic/package.json +1 -4
  24. package/examples/ionic/src/extra/bt_device.ts +32 -0
  25. package/examples/ionic/src/extra/custom_rfid.ts +61 -0
  26. package/examples/ionic/src/images/portrait.png +0 -0
  27. package/examples/ionic/src/main.css +7 -6
  28. package/examples/ionic/src/main.html +39 -61
  29. package/examples/ionic/src/main.ts +183 -36
  30. package/examples/react_native/app.config.ts +3 -1
  31. package/examples/react_native/images/portrait.png +0 -0
  32. package/examples/react_native/index.tsx +8 -2
  33. package/examples/react_native/package.json +1 -1
  34. package/examples/react_native/src/extra/bt_device.tsx +33 -0
  35. package/examples/react_native/src/extra/custom_rfid.tsx +62 -0
  36. package/examples/react_native/src/main.css +7 -6
  37. package/examples/react_native/src/main.html +10 -32
  38. package/examples/react_native/src/main.tsx +167 -21
  39. package/ios/RGLWConfig.m +2 -0
  40. package/ios/RGLWMain.m +10 -0
  41. package/package.json +1 -1
  42. package/plugin.xml +2 -2
  43. package/www/capacitor/index.js +16 -0
  44. package/www/capacitor/params/customization/Customization.js +7 -0
  45. package/www/capacitor/results/visual_results/FieldType.js +3 -1
  46. package/www/cordova.js +26 -1
  47. package/www/react-native/index.js +16 -0
  48. package/www/react-native/internal/bridge.js +1 -1
  49. package/www/react-native/params/customization/Customization.js +7 -0
  50. package/www/react-native/results/visual_results/FieldType.js +3 -1
  51. package/www/types/index.d.ts +6 -0
  52. package/www/types/params/customization/Customization.d.ts +5 -0
  53. package/www/types/results/visual_results/FieldType.d.ts +5 -1
@@ -6,17 +6,15 @@
6
6
  "android": "scripts/android.sh"
7
7
  },
8
8
  "dependencies": {
9
- "@regulaforensics/document-reader": "8.2.186-beta",
9
+ "@regulaforensics/document-reader": "8.2.204-beta",
10
10
  "@regulaforensics/document-reader-core-fullauthrfid": "8.2.8-beta",
11
11
  "@regulaforensics/document-reader-btdevice": "8.2.8-beta",
12
12
  "@awesome-cordova-plugins/file": "6.14.0",
13
13
  "@awesome-cordova-plugins/camera": "6.14.0",
14
- "@awesome-cordova-plugins/dialogs": "6.14.0",
15
14
  "cordova-ios": "7.1.1",
16
15
  "cordova-android": "13.0.0",
17
16
  "cordova-plugin-file": "8.1.3",
18
17
  "cordova-plugin-camera": "8.0.0",
19
- "cordova-plugin-dialogs": "2.0.2",
20
18
  "cordova-plugin-ionic-webview": "^5.0.0",
21
19
  "@angular/cli": "19.2.0",
22
20
  "@angular/core": "19.2.0",
@@ -36,7 +34,6 @@
36
34
  "@regulaforensics/document-reader-btdevice": {},
37
35
  "cordova-plugin-file": {},
38
36
  "cordova-plugin-camera": {},
39
- "cordova-plugin-dialogs": {},
40
37
  "cordova-plugin-ionic-webview": {}
41
38
  },
42
39
  "platforms": [
@@ -0,0 +1,32 @@
1
+ import { DocumentReader, InitConfig } from "@regulaforensics/document-reader"
2
+ import { handleException, setStatus } from "../main"
3
+
4
+ export const useBtDevice = false
5
+ const btDeviceName = "Regula 0000"
6
+
7
+ export function setupBTDevice() {
8
+ document.getElementById("bt-device").style.display = "flex"
9
+ document.getElementById("connect").onclick = () => connect()
10
+ setStatus("Connect to a bluetooth device")
11
+ }
12
+
13
+ async function connect() {
14
+ setStatus("Searching for devices...")
15
+ if (await DocumentReader.instance.connectBluetoothDevice(btDeviceName)) {
16
+ await initialize()
17
+ DocumentReader.instance.functionality.useAuthenticator = true
18
+ document.getElementById("bt-device").style.display = "none"
19
+ } else
20
+ setStatus("Failed to connect")
21
+ }
22
+
23
+ async function initialize() {
24
+ setStatus("Initializing...")
25
+
26
+ var initConfig = InitConfig.withBleDevice()
27
+ initConfig.delayedNNLoad = true
28
+ var [success, error] = await DocumentReader.instance.initialize(initConfig)
29
+
30
+ handleException(error)
31
+ return success
32
+ }
@@ -0,0 +1,61 @@
1
+ import { DocReaderAction, DocumentReader, RFIDConfig, RFIDDataFileType, RFIDNotificationCodes } from "@regulaforensics/document-reader"
2
+ import { displayResults, setStatus } from "../main"
3
+
4
+ export const useRfidSelfHostedUI = false
5
+
6
+ export function rfidSelfHostedUI() {
7
+ var config = RFIDConfig.withoutUI((action, results, _) => {
8
+ if (DocReaderAction.stopped(action)) stop()
9
+ if (DocReaderAction.finished(action)) displayResults(results)
10
+ if (DocReaderAction.interrupted(action)) setStatus("Error reading RFID")
11
+ })
12
+
13
+ config.onProgress = async (notification) => {
14
+ if (notification.progress == 1) return
15
+ if (notification.notificationCode == RFIDNotificationCodes.PCSC_READING_DATAGROUP)
16
+ setDescription(await RFIDDataFileType.getTranslation(notification.dataFileType))
17
+ setStatus("Reading RFID")
18
+ setProgress(notification.progress)
19
+ }
20
+
21
+ setup()
22
+ DocumentReader.instance.rfid(config)
23
+ }
24
+
25
+ function setup() {
26
+ setStatus("Reading RFID")
27
+ setDescription("Place your phone on top of the NFC tag")
28
+ setProgress(-1)
29
+ currentProgress = -1
30
+ setShowing(true)
31
+ document.getElementById("cancel-rfid").onclick = () => stop()
32
+ }
33
+
34
+ function stop() {
35
+ DocumentReader.instance.stopRFIDReader()
36
+ displayResults(null)
37
+ setShowing(false)
38
+ }
39
+
40
+ function setDescription(data) {
41
+ document.getElementById("rfid-description").innerHTML = data
42
+ }
43
+
44
+ var currentProgress = -1
45
+ function setProgress(next) {
46
+ var progress = document.getElementById("progress")
47
+ // make progress bar look better
48
+ if (next == 0) return // ignore idle 0s, leave progress at 100 while its not moving
49
+ if (next < currentProgress) next = 0 // move to 0 if progress finaly started moving
50
+ if (next >= 95) next = 100 // rfid never returns 100 and it looks ugly, fix it
51
+ if (next < currentProgress) progress.style.transition = 'none' // instantly reset progress
52
+ else progress.style.transition = 'width 0.5s' // smoothly increase progress
53
+
54
+ progress.style.width = next + "%"
55
+ currentProgress = next
56
+ }
57
+
58
+ function setShowing(data) {
59
+ document.getElementById("main").style.display = data ? "none" : "flex"
60
+ document.getElementById("custom-rfid").style.display = data ? "flex" : "none"
61
+ }
@@ -88,10 +88,12 @@ body {
88
88
  top: 1px;
89
89
  }
90
90
 
91
+ .radio {
92
+ align-items: baseline;
93
+ padding: 15px;
94
+ }
95
+
91
96
  input[type="checkbox"] {
92
- appearance: none;
93
- -webkit-appearance: none;
94
- -moz-appearance: none;
95
97
  width: 20px;
96
98
  height: 20px;
97
99
  border: 2px solid black;
@@ -121,10 +123,9 @@ input[type="text"] {
121
123
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
122
124
  }
123
125
 
124
- .progress {
126
+ #progress {
125
127
  width: 0%;
126
128
  height: 20px;
127
129
  background-color: #4285F4;
128
130
  border-radius: 5px;
129
- transition: width 0.5s ease-in-out;
130
- }
131
+ }
@@ -1,63 +1,41 @@
1
1
  <div class="column" style="height: 100%">
2
- <div class="column header">
3
- <span id="status" class="title">Loading...</span>
4
- <div class="column divider"></div>
5
- </div>
6
- <div id="main" class="column no-scroll">
7
- <div class="row">
8
- <div class="column" style="padding: 5px;">
9
- <p>Portrait</p>
10
- <img id="portrait-image" src="images/portrait.png" height="150px" width="150px">
11
- </div>
12
- <div class="column" style="padding: 5px;">
13
- <p>Document image</p>
14
- <img id="document-image" src="images/document.png" height="150px" width="200px">
15
- </div>
16
- </div>
17
- <div id="scenario-container" class="column no-scroll"
18
- style="margin-top: 15px; background-color: rgba(0, 0, 0, 0.03);">
19
- <div id="scenarios" class="scroll">
20
- <div class="row" style="align-items: baseline; padding: 15px;">
21
- <input type="radio" name="scenario" value="Aaa">
22
- <span style="width: 200px; padding-left: 5px;">Aaa</span>
23
- </div>
24
- <div class="row" style="align-items: baseline; padding: 15px;">
25
- <input type="radio" name="scenario" value="Aaa">
26
- <span style="width: 200px; padding-left: 5px;">Aaa</span>
27
- </div>
28
- <div class="row" style="align-items: baseline; padding: 15px;">
29
- <input type="radio" name="scenario" value="Aaa">
30
- <span style="width: 200px; padding-left: 5px;">Aaa</span>
31
- </div>
32
- <div class="row" style="align-items: baseline; padding: 15px;">
33
- <input type="radio" name="scenario" value="Aaa">
34
- <span style="width: 200px; padding-left: 5px;">Aaa</span>
35
- </div>
36
- <div class="row" style="align-items: baseline; padding: 15px;">
37
- <input type="radio" name="scenario" value="Aaa">
38
- <span style="width: 200px; padding-left: 5px;">Aaa</span>
39
- </div>
40
- </div>
41
- </div>
42
- <div class="row" style="width: 360px; padding-top: 15px;">
43
- <span id="rfid-checkbox-description" style="font-size: 18px;">Process rfid reading</span>
44
- <input id="rfid-checkbox" type="checkbox" style="margin-left: auto;" />
45
- </div>
46
- <div id="bt-device" class="row" style="display: none;">
47
- <input type="text" placeholder="Regula 0000" />
48
- <button class="button">Connect</button>
49
- </div>
50
- <div class="row">
51
- <button id="scan" class="button">Scan document</button>
52
- <button id="recognize" class="button">Scan image</button>
53
- </div>
54
- <div style="padding-top: 20px;"></div>
55
- </div>
56
- <div id="custom-rfid" class="column no-scroll" style="display: none;">
57
- <span id="rfid-description" style="font-size: 22px">Place your phone on top of the NFC tag</span>
58
- <div class="progress-bar">
59
- <div id="progress"></div>
60
- </div>
61
- <button id="cancel-rfid" class="text-button" style="margin-top: 50px;">X</button>
62
- </div>
2
+ <div class="column header">
3
+ <span id="status" class="title">Loading...</span>
4
+ <div class="column divider"></div>
5
+ </div>
6
+ <div id="main" class="column no-scroll">
7
+ <div class="row">
8
+ <div class="column" style="padding: 5px;">
9
+ <p>Portrait</p>
10
+ <img id="portrait-image" src="images/portrait.png" height="160px" width="120px">
11
+ </div>
12
+ <div class="column" style="padding: 5px;">
13
+ <p>Document image</p>
14
+ <img id="document-image" src="images/document.png" height="160px" width="200px">
15
+ </div>
16
+ </div>
17
+ <div id="bt-device" class="row" style="display: none;">
18
+ <input type="text" placeholder="Regula 0000" />
19
+ <button id="connect" class="button">Connect</button>
20
+ </div>
21
+ <div id="scenario-container" class="column no-scroll" style="margin-top: 15px; background-color: rgba(0, 0, 0, 0.03);">
22
+ <div id="scenarios" class="scroll"></div>
23
+ </div>
24
+ <div class="row" style="width: 360px; padding-top: 15px;">
25
+ <span id="rfid-checkbox-description" style="font-size: 18px;width: 100%;">Process rfid reading(unavailable)</span>
26
+ <input id="rfid-checkbox" type="checkbox" style="margin-left: auto;" disabled />
27
+ </div>
28
+ <div class="row">
29
+ <button id="scan" class="button">Scan document</button>
30
+ <button id="recognize" class="button">Scan image</button>
31
+ </div>
32
+ <div style="padding-top: 20px;"></div>
33
+ </div>
34
+ <div id="custom-rfid" class="column no-scroll" style="display: none;">
35
+ <span id="rfid-description" style="font-size: 22px">Place your phone on top of the NFC tag</span>
36
+ <div class="progress-bar">
37
+ <div id="progress"></div>
38
+ </div>
39
+ <button id="cancel-rfid" class="text-button" style="margin-top: 50px;">X</button>
40
+ </div>
63
41
  </div>
@@ -1,66 +1,213 @@
1
1
  import { Component } from '@angular/core'
2
- import { Dialogs } from '@awesome-cordova-plugins/dialogs/ngx'
3
- import { File } from '@awesome-cordova-plugins/file'
4
- import { Camera } from '@awesome-cordova-plugins/camera/ngx'
5
2
  import { Platform } from '@ionic/angular'
6
- import { DocumentReader, InitConfig } from '@regulaforensics/document-reader'
3
+ import { File } from '@awesome-cordova-plugins/file'
4
+ import { Camera as CameraClass,DestinationType, MediaType, PictureSourceType } from '@awesome-cordova-plugins/camera/ngx'
7
5
 
8
- var useBtDevice = false
9
- var ready = false
10
- var isReadingCustomRfid = false
6
+ import { DocumentReader, DocReaderAction, FieldType, GraphicFieldType, InitConfig, RecognizeConfig, ResultType, RFIDConfig, ScannerConfig, Scenario } from '@regulaforensics/document-reader'
7
+ import { setupBTDevice, useBtDevice } from './extra/bt_device'
8
+ import { useRfidSelfHostedUI, rfidSelfHostedUI } from './extra/custom_rfid'
9
+
10
+ var documentReader = DocumentReader.instance
11
+ var selectedScenario
12
+ var doRfid = false
13
+ var isReadingRfid = false
11
14
 
12
15
  async function init() {
13
16
  if (!await initialize()) return
17
+ setScenarios(documentReader.availableScenarios)
18
+ setCanRfid(await documentReader.isRFIDAvailableForUse())
14
19
  setStatus("Ready")
15
20
  }
16
21
 
22
+ async function scan() {
23
+ if (!await documentReader.isReady()) return
24
+ clearResults()
25
+ documentReader.startScanner(
26
+ ScannerConfig.withScenario(selectedScenario),
27
+ handleCompletion,
28
+ )
29
+ }
30
+
31
+ async function recognize() {
32
+ if (!await documentReader.isReady()) return
33
+ var image = await pickImage()
34
+ if (image == null) return
35
+
36
+ clearResults()
37
+ documentReader.recognize(
38
+ RecognizeConfig.withScenario(selectedScenario, { image: image }),
39
+ handleCompletion,
40
+ )
41
+ }
42
+
43
+ export function handleCompletion(action, results, error) {
44
+ handleException(error)
45
+ if (DocReaderAction.stopped(action) && !shouldRfid(results)) {
46
+ displayResults(results)
47
+ } else if (DocReaderAction.finished(action) && shouldRfid(results)) {
48
+ isReadingRfid = true
49
+ readRfid()
50
+ }
51
+ }
52
+
53
+ export async function displayResults(results) {
54
+ isReadingRfid = false
55
+ clearResults()
56
+ if (results == null) return
57
+
58
+ var name = await results.textFieldValueByType(FieldType.SURNAME_AND_GIVEN_NAMES)
59
+ var docImage = await results.graphicFieldImageByType(GraphicFieldType.DOCUMENT_IMAGE)
60
+ var portrait = await results.graphicFieldImageByType(GraphicFieldType.PORTRAIT)
61
+ portrait = await results.graphicFieldImageByTypeSource(GraphicFieldType.PORTRAIT, ResultType.RFID_IMAGE_DATA) ?? portrait
62
+
63
+ setStatus(name)
64
+ setPortrait(portrait)
65
+ setDocImage(docImage)
66
+ }
67
+
68
+ var readRfid = () => {
69
+ documentReader.rfid(new RFIDConfig(handleCompletion))
70
+ }
71
+
72
+ function shouldRfid(results) {
73
+ return doRfid &&
74
+ !isReadingRfid &&
75
+ results != null && results.chipPage != 0
76
+ }
77
+
17
78
  async function initialize() {
18
79
  setStatus("Initializing...")
19
80
 
20
- var license = await loadAssetIfExists("regula.license")
21
- var config = new InitConfig(license)
22
- var [success, error] = await documentReader.initialize(config)
23
-
24
- if (!success && error != null) {
81
+ var license = await loadAsset("regula.license")
82
+ var initConfig = new InitConfig(license)
83
+ var [success, error] = await documentReader.initialize(initConfig)
84
+
85
+ handleException(error)
86
+ return success
87
+ }
88
+
89
+ export function handleException(error) {
90
+ if (error != null) {
25
91
  setStatus(error.message)
26
92
  console.log(error.code + ": " + error.message)
27
93
  }
28
- return success
29
94
  }
30
95
 
31
- async function loadAssetIfExists(path: string): Promise<string | null> {
32
- try {
33
- var dir = await File.resolveDirectoryUrl(File.applicationDirectory + "www/assets")
34
- var fileEntry = await File.getFile(dir, path, null)
35
- var result = await new Promise<string | null>((resolve, _) => {
36
- fileEntry.file(file => {
37
- var reader = new FileReader()
38
- reader.onloadend = (_) => resolve(reader.result as string)
39
- reader.readAsDataURL(file)
40
- }, _ => resolve(null))
41
- })
42
- return result
43
- } catch (_) {
44
- return null
96
+ // ui --------------------------------------------------------------------------------------------------------------------
97
+
98
+ export function setStatus(data) {
99
+ if (data != null)
100
+ document.getElementById("status").innerHTML = data
101
+ }
102
+
103
+ function setPortrait(data) {
104
+ if (data != null)
105
+ portraitUIImage.src = "data:image/png;base64," + data
106
+ }
107
+
108
+ function setDocImage(data) {
109
+ if (data != null)
110
+ documentUIImage.src = "data:image/png;base64," + data
111
+ }
112
+
113
+ function clearResults() {
114
+ setStatus("Ready")
115
+ portraitUIImage.src = "images/portrait.png"
116
+ documentUIImage.src = "images/document.png"
117
+ }
118
+
119
+ function setCanRfid(data) {
120
+ var checkbox // implicitly any, since cordova sample is pure js
121
+ checkbox = document.getElementById('rfid-checkbox')
122
+ var checkboxDescription = document.getElementById("rfid-checkbox-description")
123
+ if (data) {
124
+ checkbox.disabled = false
125
+ checkboxDescription.innerHTML = "Process rfid reading"
126
+ checkboxDescription.onclick = () => {
127
+ doRfid = !doRfid
128
+ checkbox.checked = doRfid
129
+ }
45
130
  }
46
131
  }
47
132
 
48
- var documentReader = DocumentReader.instance
49
- var setStatus = (data: string) => document.getElementById("status").innerHTML = data
133
+ // not equal --------------------------------------------------------------------------------------------------------------------
50
134
 
135
+ async function loadAsset(path: string): Promise<string> {
136
+ var dir = await File.resolveDirectoryUrl(File.applicationDirectory + "www/assets")
137
+ var fileEntry = await File.getFile(dir, path, null)
138
+ var result = await new Promise<string>((resolve, _) => {
139
+ fileEntry.file(file => {
140
+ var reader = new FileReader()
141
+ reader.onloadend = (_) => resolve(reader.result as string)
142
+ reader.readAsDataURL(file)
143
+ })
144
+ })
145
+ return result
146
+ }
147
+
148
+ async function pickImage(): Promise<string | null> {
149
+ return await Camera.getPicture({
150
+ destinationType: DestinationType.DATA_URL,
151
+ mediaType: MediaType.PICTURE,
152
+ sourceType: PictureSourceType.PHOTOLIBRARY
153
+ })
154
+ }
155
+
156
+ var Camera: CameraClass
157
+ var documentUIImage
158
+ var portraitUIImage
51
159
  @Component({
52
160
  selector: 'app-root',
53
161
  templateUrl: 'main.html',
54
162
  styleUrl: 'main.css'
55
163
  })
56
164
  export class Main {
57
- constructor(platform: Platform, dialogs: Dialogs, camera: Camera) {
165
+ constructor(platform: Platform, camera: CameraClass) {
166
+ Camera = camera
58
167
  platform.ready().then(() => {
59
- document.getElementById("main").style.display = isReadingCustomRfid ? "none" : "flex"
60
- document.getElementById("custom-rfid").style.display = isReadingCustomRfid ? "flex" : "none"
61
- document.getElementById("bt-device").style.display = (useBtDevice && !ready) ? "flex" : "none"
62
-
63
- init()
64
- });
168
+ documentUIImage = document.getElementById("document-image")
169
+ portraitUIImage = document.getElementById("portrait-image")
170
+ document.getElementById("scan").onclick = () => scan()
171
+ document.getElementById("recognize").onclick = () => recognize()
172
+
173
+ // custom rfid
174
+ if (useRfidSelfHostedUI) readRfid = () => rfidSelfHostedUI()
175
+
176
+ // bt device
177
+ if (!useBtDevice) init()
178
+ else setupBTDevice()
179
+ })
65
180
  }
66
181
  }
182
+
183
+ // not resolved --------------------------------------------------------------------------------------------------------------------
184
+
185
+ function setScenarios(data) {
186
+ selectedScenario = Scenario.MRZ
187
+ const scenariosContainer = document.getElementById("scenarios")
188
+ data.forEach(scenario => scenariosContainer.appendChild(createScenarioElement(scenario)))
189
+ }
190
+
191
+ function createScenarioElement(scenario) {
192
+ const div = document.createElement('div')
193
+ div.className = 'row radio'
194
+
195
+ const input = document.createElement('input')
196
+ input.type = 'radio'
197
+ input.name = 'scenario'
198
+ input.value = scenario.name
199
+ input.checked = scenario.name === selectedScenario
200
+
201
+ const span = document.createElement('span')
202
+ span.style.width = '200px'
203
+ span.style.paddingLeft = '5px'
204
+ span.textContent = scenario.caption
205
+
206
+ input.onclick = () => selectedScenario = scenario.name
207
+ span.onclick = () => input.click()
208
+
209
+ div.appendChild(input)
210
+ div.appendChild(span)
211
+
212
+ return div
213
+ }
@@ -28,7 +28,9 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
28
28
  },
29
29
  android: {
30
30
  package: 'com.regula.dr.fullauthrfid',
31
- permissions: ['android.permission.BLUETOOTH_CONNECT'],
31
+ permissions: [
32
+ 'android.permission.BLUETOOTH_CONNECT',
33
+ 'android.permission.NFC'],
32
34
  adaptiveIcon: {
33
35
  foregroundImage: './images/icon/adaptive-icon.png',
34
36
  backgroundColor: '#ffffff'
@@ -1,5 +1,6 @@
1
1
  import { registerRootComponent } from 'expo'
2
2
  import WebView from 'react-native-webview'
3
+ import React from 'react'
3
4
  import { onload } from './src/main'
4
5
 
5
6
  var webViewRef: any
@@ -24,13 +25,13 @@ export const document = {
24
25
  }; true
25
26
  `)
26
27
  } else
27
- webViewRef.injectJavaScript(`document.getElementById("${id}").${prop} = "${value}"; true`)
28
+ webViewRef.injectJavaScript(`document.getElementById("${id}").${prop} = ${parseValue(value)}; true`)
28
29
  return true
29
30
  },
30
31
  get(_, prop: string) {
31
32
  if (prop === "style") return new Proxy({}, {
32
33
  set(_, styleProp: string, value) {
33
- webViewRef.injectJavaScript(`document.getElementById("${id}").style.${styleProp} = "${value}"; true`)
34
+ webViewRef.injectJavaScript(`document.getElementById("${id}").style.${styleProp} = ${parseValue(value)}; true`)
34
35
  return true
35
36
  }
36
37
  })
@@ -41,6 +42,11 @@ export const document = {
41
42
  }
42
43
  }
43
44
 
45
+ function parseValue(value: any) {
46
+ if (value !== true && value !== false) return `"${value}"`
47
+ return value
48
+ }
49
+
44
50
  registerRootComponent(() =>
45
51
  <WebView
46
52
  ref={ref => { webViewRef = ref }}
@@ -8,7 +8,7 @@
8
8
  "start": "expo start"
9
9
  },
10
10
  "dependencies": {
11
- "@regulaforensics/document-reader": "8.2.186-beta",
11
+ "@regulaforensics/document-reader": "8.2.204-beta",
12
12
  "@regulaforensics/document-reader-core-fullauthrfid": "8.2.8-beta",
13
13
  "@regulaforensics/document-reader-btdevice": "8.2.8-beta",
14
14
  "react-native": "0.79.2",
@@ -0,0 +1,33 @@
1
+ import { document } from '../../index'
2
+ import { DocumentReader, InitConfig } from "@regulaforensics/document-reader"
3
+ import { handleException, setStatus } from "../main"
4
+
5
+ export const useBtDevice = false
6
+ const btDeviceName = "Regula 0000"
7
+
8
+ export function setupBTDevice() {
9
+ document.getElementById("bt-device").style.display = "flex"
10
+ document.getElementById("connect").onclick = () => connect()
11
+ setStatus("Connect to a bluetooth device")
12
+ }
13
+
14
+ async function connect() {
15
+ setStatus("Searching for devices...")
16
+ if (await DocumentReader.instance.connectBluetoothDevice(btDeviceName)) {
17
+ await initialize()
18
+ DocumentReader.instance.functionality.useAuthenticator = true
19
+ document.getElementById("bt-device").style.display = "none"
20
+ } else
21
+ setStatus("Failed to connect")
22
+ }
23
+
24
+ async function initialize() {
25
+ setStatus("Initializing...")
26
+
27
+ var initConfig = InitConfig.withBleDevice()
28
+ initConfig.delayedNNLoad = true
29
+ var [success, error] = await DocumentReader.instance.initialize(initConfig)
30
+
31
+ handleException(error)
32
+ return success
33
+ }
@@ -0,0 +1,62 @@
1
+ import { document } from '../../index'
2
+ import { DocReaderAction, DocumentReader, RFIDConfig, RFIDDataFileType, RFIDNotificationCodes } from "@regulaforensics/document-reader"
3
+ import { displayResults, setStatus } from "../main"
4
+
5
+ export const useRfidSelfHostedUI = false
6
+
7
+ export function rfidSelfHostedUI() {
8
+ var config = RFIDConfig.withoutUI((action, results, _) => {
9
+ if (DocReaderAction.stopped(action)) stop()
10
+ if (DocReaderAction.finished(action)) displayResults(results)
11
+ if (DocReaderAction.interrupted(action)) setStatus("Error reading RFID")
12
+ })
13
+
14
+ config.onProgress = async (notification) => {
15
+ if (notification.progress == 1) return
16
+ if (notification.notificationCode == RFIDNotificationCodes.PCSC_READING_DATAGROUP)
17
+ setDescription(await RFIDDataFileType.getTranslation(notification.dataFileType))
18
+ setStatus("Reading RFID")
19
+ setProgress(notification.progress)
20
+ }
21
+
22
+ setup()
23
+ DocumentReader.instance.rfid(config)
24
+ }
25
+
26
+ function setup() {
27
+ setStatus("Reading RFID")
28
+ setDescription("Place your phone on top of the NFC tag")
29
+ setProgress(-1)
30
+ currentProgress = -1
31
+ setShowing(true)
32
+ document.getElementById("cancel-rfid").onclick = () => stop()
33
+ }
34
+
35
+ function stop() {
36
+ DocumentReader.instance.stopRFIDReader()
37
+ displayResults(null)
38
+ setShowing(false)
39
+ }
40
+
41
+ function setDescription(data) {
42
+ document.getElementById("rfid-description").innerHTML = data
43
+ }
44
+
45
+ var currentProgress = -1
46
+ function setProgress(next) {
47
+ var progress = document.getElementById("progress")
48
+ // make progress bar look better
49
+ if (next == 0) return // ignore idle 0s, leave progress at 100 while its not moving
50
+ if (next < currentProgress) next = 0 // move to 0 if progress finaly started moving
51
+ if (next >= 95) next = 100 // rfid never returns 100 and it looks ugly, fix it
52
+ if (next < currentProgress) progress.style.transition = 'none' // instantly reset progress
53
+ else progress.style.transition = 'width 0.5s' // smoothly increase progress
54
+
55
+ progress.style.width = next + "%"
56
+ currentProgress = next
57
+ }
58
+
59
+ function setShowing(data) {
60
+ document.getElementById("main").style.display = data ? "none" : "flex"
61
+ document.getElementById("custom-rfid").style.display = data ? "flex" : "none"
62
+ }