-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (49 loc) · 1.84 KB
/
Copy pathindex.js
File metadata and controls
53 lines (49 loc) · 1.84 KB
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
/* eslint-disable no-console */
import { DBR, BarcodeReader, BarcodeScanner } from "dynamsoft-javascript-barcode";
DBR.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.4.0/dist/";
// Please visit https://www.dynamsoft.com/customer/license/trialLicense/?product=dbr&utm_source=github&package=js to get a trial license
DBR.productKeys = "PRODUCT-KEYS";
// Dynamsoft.DBR.BarcodeReader._bUseFullFeature = true; // Control of loading min wasm or full wasm.
// reader for decoding picture
let pReader = null;
// scanner for decoding video
let pScanner = null;
// decode input picture
document.getElementById('ipt-file').addEventListener('change', async function(){
try{
let reader = await (pReader = pReader || BarcodeReader.createInstance());
let resultsToAlert = [];
for(let i = 0; i < this.files.length; ++i){
let file = this.files[i];
resultsToAlert.push(i + '. ' + file.name + ":");
let results = await reader.decode(file);
console.log(results);
for(let result of results){
resultsToAlert.push(result.barcodeText);
}
}
alert(resultsToAlert.join('\n'));
}catch(ex){
alert(ex.message);
throw ex;
}
this.value = '';
});
// decode video from camera
document.getElementById('btn-show-scanner').addEventListener('click', async () => {
try{
let scanner = await (pScanner = pScanner || BarcodeScanner.createInstance());
scanner.onFrameRead = results => {
if(results.length){
console.log(results);
}
};
scanner.onUnduplicatedRead = (txt, result) => {
alert(result.barcodeFormatString + ': ' + txt);
};
await scanner.show();
}catch(ex){
alert(ex.message);
throw ex;
}
});