Skip to content

Commit 99d579f

Browse files
committed
code improve
1 parent 91010a2 commit 99d579f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+127747
-508
lines changed

1.hello-world/10.read-video-pwa/helloworld-pwa.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<meta name="keywords" content="read barcode from camera in PWA">
99
<title>Dynamsoft Barcode Reader PWA Sample - Hello World (Decoding via Camera)</title>
1010
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.8.7/dist/dbr.js"></script>
11-
<link rel="manifest" href="./helloworld-pwa.webmanifest">
11+
<link rel="manifest" href="./helloworld-pwa.json">
1212
</head>
1313

1414
<body>
@@ -38,18 +38,18 @@ <h1 style="font-size: 1.5em;">Hello World for PWA</h1>
3838
}
3939
});
4040
try {
41-
let scanner = await (pScanner = pScanner || Dynamsoft.DBR.BarcodeScanner.createInstance());
42-
scanner.onFrameRead = results => {
41+
pScanner = pScanner || await Dynamsoft.DBR.BarcodeScanner.createInstance();
42+
pScanner.onFrameRead = results => {
4343
console.log("Barcodes on one frame:");
4444
for (let result of results) {
4545
console.log(result.barcodeFormatString + ": " + result.barcodeText);
4646
}
4747
};
48-
scanner.onUnduplicatedRead = (txt, result) => {
48+
pScanner.onUnduplicatedRead = (txt, result) => {
4949
latestResult = txt;
50-
console.log("Unique Code Found: " + result);
50+
alert(txt, result);
5151
}
52-
await scanner.show();
52+
await pScanner.show();
5353
} catch (ex) {
5454
alert(ex.message);
5555
throw ex;

1.hello-world/10.read-video-pwa/helloworld-pwa.webmanifest renamed to 1.hello-world/10.read-video-pwa/helloworld-pwa.json

File renamed without changes.

1.hello-world/10.read-video-pwa/service-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const cacheName = 'helloworld-pwa';
33
const appShellFiles = [
44
'./helloworld-pwa.html',
55
'./dbr-big.png',
6-
'./helloworld-pwa.webmanifest',
6+
'./helloworld-pwa.json',
77
];
88

99
// Installing Service Worker

1.hello-world/11.read-video-requirejs.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ <h1 style="font-size: 1.5em;">Hello World for RequireJS</h1>
1414
<script src="https://cdn.jsdelivr.net/npm/requirejs@2.3.6/require.js"></script>
1515
<script>
1616
requirejs(['https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.8.7/dist/dbr.js'], function({
17-
DBR,
1817
BarcodeReader,
1918
BarcodeScanner
2019
}) {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<meta name="description" content="Quickly read barcodes with Dynamsoft Barcode Reader from a live camera stream.">
8+
<meta name="keywords" content="camera based barcode reading">
9+
<title>Dynamsoft Barcode Reader Sample - Hello World (Decoding via Camera)</title>
10+
<!--
11+
This sample makes use of the library hosted by the CDN jsDelivr. If you would rather use the
12+
library offline. Please see the guide on how to host the library:
13+
https://www.dynamsoft.com/barcode-reader/programming/javascript/user-guide/?ver=latest#host-the-library-yourself-recommended
14+
-->
15+
</head>
16+
17+
<body>
18+
<h1 style="font-size: 1.5em;">Read Barcodes from a Camera</h1>
19+
<button id="btn-show-scanner">Show Barcode Scanner</button>
20+
<script type="module">
21+
/** LICENSE ALERT - README
22+
*
23+
* The library requires a license to work.
24+
* If the license is not specified, a free public trial license will be used by default which is the case in this sample.
25+
* Note that network connection is required for the public license to work.
26+
* For more info, please check https://www.dynamsoft.com/barcode-reader/programming/javascript/user-guide/?ver=8.8.7&utm_source=github#specify-the-license or contact support@dynamsoft.com.
27+
*/
28+
29+
/* When using your own license, uncomment the following line and specify your license. */
30+
31+
// Dynamsoft.DBR.BarcodeReader.license = "YOUR-ORGANIZATION-ID or YOUR-HANDSHAKECODE or AN-OFFLINE-LICENSE or ANY-OTHER-TYPE-OF-SUPPORTED-LICENSE-STRING";
32+
33+
/** LICENSE ALERT - THE END */
34+
import { DBR, BarcodeScanner } from 'https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.8.7/dist/dbr.mjs';
35+
36+
// DBR.productKeys = "PRODUCT-KEYS";
37+
38+
DBR.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.8.7/dist/";
39+
40+
41+
let pScanner = null;
42+
document.getElementById('btn-show-scanner').addEventListener('click', async () => {
43+
try {
44+
pScanner = pScanner || await BarcodeScanner.createInstance();
45+
/*
46+
* onFrameRead is triggered after the library finishes reading a frame.
47+
* There can be one or multiple barcodes on each frame.
48+
*/
49+
pScanner.onFrameRead = results => {
50+
console.log("Barcodes on one frame:");
51+
for (let result of results) {
52+
console.log(result.barcodeFormatString + ": " + result.barcodeText);
53+
}
54+
};
55+
/*
56+
* onUnduplicatdRead is triggered only when a 'new' barcode is found.
57+
* The amount of time that the library 'remembers' a barcode is defined by
58+
* "duplicateForgetTime" in "ScanSettings". By default it is set to 3000 ms.
59+
*/
60+
pScanner.onUnduplicatedRead = (txt, result) => {
61+
alert(txt);
62+
console.log("Unique Code Found: " + result);
63+
}
64+
await pScanner.show();
65+
} catch (ex) {
66+
alert(ex.message);
67+
throw ex;
68+
}
69+
});
70+
</script>
71+
</body>
72+
73+
</html>

0 commit comments

Comments
 (0)