Skip to content

Commit 92ac481

Browse files
committed
side effect; script position
1 parent 495c82e commit 92ac481

File tree

7 files changed

+43
-46
lines changed

7 files changed

+43
-46
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
<meta name="description" content="Read barcodes from camera with Dynamsoft Barcode Reader in a PWA application.">
88
<meta name="keywords" content="read barcode from camera in PWA">
99
<title>Dynamsoft Barcode Reader PWA Sample - Hello World (Decoding via Camera)</title>
10-
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.8.7/dist/dbr.js"></script>
1110
<link rel="manifest" href="./helloworld-pwa.json">
1211
</head>
1312

1413
<body>
1514
<h1 style="font-size: 1.5em;">Hello World for PWA</h1>
1615
<button id='readBarcode'>Read Barcode via Camera</button>
16+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.8.7/dist/dbr.js"></script>
1717
<script>
1818
/** LICENSE ALERT - README
1919
*

1.hello-world/4.read-video-react/src/components/HelloWorld/HelloWorld.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import './HelloWorld.css';
22
import reactLogo from '../../logo.svg';
3-
import DBR from "../../dbr";
3+
import "../../dbr"; // import side effects. The license, engineResourcePath, so on.
4+
import { BarcodeReader } from "dynamsoft-javascript-barcode";
45
import React from 'react';
56
import VideoDecode from '../VideoDecode/VideoDecode';
67
import ImgDecode from '../ImgDecode/ImgDecode';
@@ -15,7 +16,7 @@ class HelloWorld extends React.Component {
1516
}
1617
async componentDidMount() {
1718
try {
18-
await DBR.BarcodeScanner.loadWasm();
19+
await BarcodeReader.loadWasm();
1920
} catch (ex) {
2021
alert(ex.message);
2122
throw ex;

1.hello-world/4.read-video-react/src/components/ImgDecode/ImgDecode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react'
2-
import DBR from "../../dbr";
2+
import { BarcodeReader } from "dynamsoft-javascript-barcode";
33
import './ImgDecode.css'
44

55
export default class ImgDecode extends Component {
@@ -10,7 +10,7 @@ export default class ImgDecode extends Component {
1010

1111
decodeImg = async (e) => {
1212
try {
13-
const reader = await (this.pReader = DBR.BarcodeReader.createInstance());
13+
const reader = await (this.pReader = BarcodeReader.createInstance());
1414
let results = await reader.decode(e.target.files[0]);
1515
for(let result of results){
1616
alert(result.barcodeText);

1.hello-world/4.read-video-react/src/components/VideoDecode/VideoDecode.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import DBR from "dynamsoft-javascript-barcode";
1+
import { BarcodeReader } from "dynamsoft-javascript-barcode";
22

33
/** LICENSE ALERT - README
44
*
@@ -10,10 +10,8 @@ import DBR from "dynamsoft-javascript-barcode";
1010

1111
/* When using your own license, uncomment the following line and specify your license. */
1212

13-
// DBR.BarcodeReader.license = "YOUR-ORGANIZATION-ID or YOUR-HANDSHAKECODE or AN-OFFLINE-LICENSE or ANY-OTHER-TYPE-OF-SUPPORTED-LICENSE-STRING";
13+
// BarcodeReader.license = "YOUR-ORGANIZATION-ID or YOUR-HANDSHAKECODE or AN-OFFLINE-LICENSE or ANY-OTHER-TYPE-OF-SUPPORTED-LICENSE-STRING";
1414

1515
/** LICENSE ALERT - THE END */
1616

17-
DBR.BarcodeReader.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.8.7/dist/";
18-
19-
export default DBR;
17+
BarcodeReader.engineResourcePath = "https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@8.8.7/dist/";
Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
1-
window.onload = function () {
2-
/** LICENSE ALERT - README
3-
*
4-
* The library requires a license to work.
5-
* If the license is not specified, a free public trial license will be used by default which is the case in this sample.
6-
* Note that network connection is required for the public license to work.
7-
* 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.
8-
*/
1+
/** LICENSE ALERT - README
2+
*
3+
* The library requires a license to work.
4+
* If the license is not specified, a free public trial license will be used by default which is the case in this sample.
5+
* Note that network connection is required for the public license to work.
6+
* 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.
7+
*/
98

10-
/* When using your own license, uncomment the following line and specify your license. */
9+
/* When using your own license, uncomment the following line and specify your license. */
1110

12-
// Dynamsoft.DBR.BarcodeReader.license = "YOUR-ORGANIZATION-ID or YOUR-HANDSHAKECODE or AN-OFFLINE-LICENSE or ANY-OTHER-TYPE-OF-SUPPORTED-LICENSE-STRING";
11+
// Dynamsoft.DBR.BarcodeReader.license = "YOUR-ORGANIZATION-ID or YOUR-HANDSHAKECODE or AN-OFFLINE-LICENSE or ANY-OTHER-TYPE-OF-SUPPORTED-LICENSE-STRING";
1312

14-
/** LICENSE ALERT - THE END */
13+
/** LICENSE ALERT - THE END */
1514

16-
Dynamsoft.DBR.BarcodeReader.loadWasm();
17-
let pScanner = null;
18-
document.getElementById('readBarcode').onclick = async () => {
19-
try {
20-
const scanner = await (pScanner = pScanner || Dynamsoft.DBR.BarcodeScanner.createInstance());
21-
scanner.onFrameRead = results => {
22-
if (results.length) {
23-
console.log(results);
24-
}
25-
};
26-
scanner.onUnduplicatedRead = (txt, result) => {
27-
alert(txt, result);
28-
};
29-
document.getElementById("barcodeScannerUI").appendChild(scanner.getUIElement());
30-
await scanner.show();
31-
} catch (ex) {
32-
alert(ex.message);
33-
throw ex;
34-
}
35-
};
36-
}
15+
Dynamsoft.DBR.BarcodeReader.loadWasm();
16+
let pScanner = null;
17+
document.getElementById('readBarcode').onclick = async () => {
18+
try {
19+
const scanner = await (pScanner = pScanner || Dynamsoft.DBR.BarcodeScanner.createInstance());
20+
scanner.onFrameRead = results => {
21+
if (results.length) {
22+
console.log(results);
23+
}
24+
};
25+
scanner.onUnduplicatedRead = (txt, result) => {
26+
alert(txt, result);
27+
};
28+
document.getElementById("barcodeScannerUI").appendChild(scanner.getUIElement());
29+
await scanner.show();
30+
} catch (ex) {
31+
alert(ex.message);
32+
throw ex;
33+
}
34+
};

1.hello-world/9.read-video-electron/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
<meta name="keywords" content="read barcode from camera in Electron">
88
<title>Read barcodes from a video input in Electron!</title>
99
<link href="style.css" rel="stylesheet">
10-
<script src="./node_modules/dynamsoft-javascript-barcode/dist/dbr.js"></script>
11-
<script src="action.js"></script>
1210
</head>
1311

1412
<body>
@@ -17,6 +15,8 @@ <h1 style="font-size: 1.5em;">Hello World for Electron</h1>
1715
<div class="container">
1816
<div id="barcodeScannerUI"></div>
1917
</div>
18+
<script src="./node_modules/dynamsoft-javascript-barcode/dist/dbr.js"></script>
19+
<script src="action.js"></script>
2020
</body>
2121

2222
</html>

0 commit comments

Comments
 (0)