Skip to content

Commit 19ee545

Browse files
committed
Create es-module
1 parent f2b6650 commit 19ee545

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

1.hello-world/es-module.html

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
* The library requires a license to work, you use the API organizationID to tell the program where to fetch your license.
23+
* If the Organizaion ID is not specified, a 7-day (public) trial license will be used by default which is the case in this sample.
24+
* Note that network connection is required for this license to work.
25+
*/
26+
27+
/* When using your own license, uncomment the following line and specify your Organization ID. */
28+
29+
// Dynamsoft.DBR.organizationID = "YOUR-ORGANIZATION-ID";
30+
31+
/* If you don't have a license yet, you can request a trial on this page: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&package=js&utm_source=samples */
32+
/* For more information, please refer to https://www.dynamsoft.com/license-server/docs/about/licensefaq.html?ver=latest#how-to-use-a-trackable-license. */
33+
34+
/* The API "productKeys" is an alternative way to license the library, the major difference is that it does not require a network. Contact [email protected] for more information. */
35+
36+
// Dynamsoft.DBR.productKeys = "YOUR-PRODUCT-KEY";
37+
38+
/** LICENSE ALERT - THE END */
39+
import { DBR, BarcodeScanner } from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/dbr.mjs';
40+
41+
DBR.productKeys = "PRODUCT-KEYS";
42+
43+
DBR.engineResourcePath = "https://cdn.jsdelivr.net/npm/[email protected]/dist/";
44+
45+
46+
let pScanner = null;
47+
document.getElementById('btn-show-scanner').addEventListener('click', async () => {
48+
try {
49+
let scanner = await (pScanner = pScanner || BarcodeScanner.createInstance());
50+
/*
51+
* onFrameRead is triggered after the library finishes reading a frame.
52+
* There can be one or multiple barcodes on each frame.
53+
*/
54+
scanner.onFrameRead = results => {
55+
console.log("Barcodes on one frame:");
56+
for (let result of results) {
57+
console.log(result.barcodeFormatString + ": " + result.barcodeText);
58+
}
59+
};
60+
/*
61+
* onUnduplicatdRead is triggered only when a 'new' barcode is found.
62+
* The amount of time that the library 'remembers' a barcode is defined by
63+
* "duplicateForgetTime" in "ScanSettings". By default it is set to 3000 ms.
64+
*/
65+
scanner.onUnduplicatedRead = (txt, result) => {
66+
alert(txt);
67+
console.log("Unique Code Found: " + result);
68+
}
69+
await scanner.show();
70+
} catch (ex) {
71+
alert(ex.message);
72+
throw ex;
73+
}
74+
});
75+
</script>
76+
</body>
77+
78+
</html>

0 commit comments

Comments
 (0)