-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (58 loc) · 2.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// import STRICH SDK as an ES6 module directly from a CDN
import {StrichSDK, BarcodeReader} from 'https://cdn.jsdelivr.net/npm/@pixelverse/strichjs-sdk@1.6.0';
// AAMVA helper routines
import {parseAAMVALicenseData} from "./aamva.js";
function processPDF417Barcode(codeDetection) {
// attempt to parse barcode data as AAMVA driver's license
const parsed = parseAAMVALicenseData(codeDetection.data);
if (!parsed) {
console.error('PDF417 data could not be parsed according to AAMVA spec');
return;
}
// calculate age from system time
const age = new Date().getFullYear() - parsed.dateOfBirth.getFullYear();
// depending on age, show success or reject popup
const dialog = document.getElementById(age < 21 ? 'failure' : 'success');
dialog.getElementsByClassName('popup-name')[0].innerText = parsed.firstName + ' ' + parsed.lastName;
dialog.getElementsByClassName('popup-age')[0].innerText = age + ' yrs old';
dialog.showModal();
}
// Initialize BarcodeReader with appropriate settings for PDF417
function initializeBarcodeReader() {
let configuration = {
selector: '.container',
engine: {
symbologies: ['pdf417']
},
locator: {
regionOfInterest: {
// PDF417 is typically a wide rectangle, size the ROI appropriately
left: 0.05, right: 0.05, top: 0.3, bottom: 0.3
}
},
frameSource: {
// high resolution recommended for PDF417
resolution: 'full-hd'
},
};
return new BarcodeReader(configuration).initialize()
.then(barcodeReader => {
// store the BarcodeReader in a global, to be able to access it later (e.g. to destroy it)
window['barcodeReader'] = barcodeReader;
barcodeReader.detected = (detections) => {
processPDF417Barcode(detections[0]);
};
return barcodeReader.start();
});
}
// initialize STRICH SDK with a valid license key
const licenseKey = '<your-license-key-here>';
StrichSDK.initialize(licenseKey)
.then(() => {
console.log('SDK initialized successfully');
return initializeBarcodeReader();
})
.catch(err => {
// See: https://docs.strich.io/reference/classes/SdkError.html
window.alert(err.localizedMessage);
});