Skip to content

Commit 5bb79b9

Browse files
committed
pwa
1 parent 4be27c0 commit 5bb79b9

File tree

6 files changed

+98
-0
lines changed

6 files changed

+98
-0
lines changed

example/web/pwa/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
quick run: https://dynamsoft.github.io/example/web/pwa/
6.48 KB
Loading
9.71 KB
Loading

example/web/pwa/index.html

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
6+
<link rel="manifest" href="./manifest.json">
7+
</head>
8+
<body>
9+
10+
Choose image(s) to decode:
11+
<input id="ipt-file" type="file" multiple accept="image/png,image/jpeg,image/bmp,image/gif">
12+
<br><br>
13+
<button id="btn-show-scanner">show scanner</button>
14+
15+
<!-- Please visit https://www.dynamsoft.com/CustomerPortal/Portal/TrialLicense.aspx to get a trial license. -->
16+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@7.3.0-v4/dist/dbr.js" data-productKeys="PRODUCT-KEYS"></script>
17+
18+
<script>
19+
// Dynamsoft.BarcodeReader._bUseFullFeature = true; // Control of loading min wasm or full wasm.
20+
21+
// reader for decoding picture
22+
let reader = null;
23+
// scanner for decoding video
24+
let scanner = null;
25+
26+
// decode input picture
27+
document.getElementById('ipt-file').addEventListener('change', async function(){
28+
try{
29+
reader = reader || await Dynamsoft.BarcodeReader.createInstance();
30+
let resultsToAlert = [];
31+
for(let i = 0; i < this.files.length; ++i){
32+
let file = this.files[i];
33+
resultsToAlert.push(i + '. ' + file.name + ":");
34+
let results = await reader.decode(file);
35+
console.log(results);
36+
for(let result of results){
37+
resultsToAlert.push(result.barcodeText);
38+
}
39+
}
40+
alert(resultsToAlert.join('\n'));
41+
}catch(ex){
42+
alert(ex.message);
43+
throw ex;
44+
}
45+
this.value = '';
46+
});
47+
48+
// decode video from camera
49+
document.getElementById('btn-show-scanner').addEventListener('click', async () => {
50+
try{
51+
scanner = scanner || await Dynamsoft.BarcodeScanner.createInstance();
52+
scanner.onFrameRead = results => {
53+
if(results.length){
54+
console.log(results);
55+
}
56+
};
57+
scanner.onUnduplicatedRead = (txt, result) => {
58+
alert(result.barcodeFormatString + ': ' + txt);
59+
};
60+
await scanner.show();
61+
}catch(ex){
62+
alert(ex.message);
63+
throw ex;
64+
}
65+
});
66+
if ('serviceWorker' in navigator) {
67+
navigator.serviceWorker.register('./service-worker.js');
68+
}
69+
</script>
70+
</body>
71+
</html>

example/web/pwa/manifest.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "dynamsoft bacode js pwa basic",
3+
"short_name": "bacode js",
4+
"start_url": "./",
5+
"scope": ".",
6+
"display": "standalone",
7+
"theme_color": "#ffffff",
8+
"background_color":"#ffffff",
9+
"icons": [{
10+
"src": "img/dynamsoft-512x512.png",
11+
"sizes": "512x512",
12+
"type": "image/png"
13+
},{
14+
"src": "img/dynamsoft-192x192.png",
15+
"sizes": "192x192",
16+
"type": "image/png"
17+
}]
18+
}

example/web/pwa/service-worker.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
self.addEventListener('fetch', event => {
2+
3+
// abandon non-GET requests
4+
if (event.request.method !== 'GET') return;
5+
6+
// do nothing now
7+
return;
8+
});

0 commit comments

Comments
 (0)