Skip to content

Commit c3d17e6

Browse files
committed
update readme
1 parent 6029fbb commit c3d17e6

File tree

10 files changed

+93
-179
lines changed

10 files changed

+93
-179
lines changed

hello-world/angular/README.md

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,7 @@ CoreModule.engineResourcePaths = {
6666
};
6767

6868
// Preload "BarcodeReader" module for reading barcodes. It will save time on the initial decoding by skipping the module loading.
69-
CoreModule.loadWasm(['DBR']).catch((ex) => {
70-
let errMsg;
71-
if (ex.message?.includes('network connection error')) {
72-
errMsg =
73-
'Failed to connect to Dynamsoft License Server: network connection error. Check your Internet connection or contact Dynamsoft Support (support@dynamsoft.com) to acquire an offline license.';
74-
} else {
75-
errMsg = ex.message || ex;
76-
}
77-
console.error(errMsg);
78-
alert(errMsg);
79-
});
69+
CoreModule.loadWasm(['DBR']);
8070
```
8171

8272
> Note:
@@ -139,6 +129,7 @@ import {
139129
CaptureVisionRouter,
140130
} from 'dynamsoft-capture-vision-router';
141131
import { MultiFrameResultCrossFilter } from 'dynamsoft-utility';
132+
import '../../cvr'; // import side effects. The license, engineResourcePath, so on.
142133

143134
@Component({
144135
selector: 'app-video-capture',
@@ -177,10 +168,14 @@ export class VideoCaptureComponent {
177168
resultReceiver.onDecodedBarcodesReceived = (result: DecodedBarcodesResult) => {
178169
if (!result.barcodesResultItems.length) return;
179170

180-
this.resultsContainer!.nativeElement.innerHTML = "";
171+
this.resultsContainer!.nativeElement.textContent = '';
181172
console.log(result);
182173
for (let item of result.barcodesResultItems) {
183-
this.resultsContainer!.nativeElement.innerHTML += `${item.formatString}: ${item.text}<br><hr>`;
174+
this.resultsContainer!.nativeElement.append(
175+
`${item.formatString}: ${item.text}`,
176+
document.createElement('br'),
177+
document.createElement('hr'),
178+
);
184179
}
185180
};
186181
router.addResultReceiver(resultReceiver);
@@ -211,13 +206,7 @@ export class VideoCaptureComponent {
211206
router,
212207
};
213208
} catch (ex: any) {
214-
let errMsg;
215-
if (ex.message?.includes('network connection error')) {
216-
errMsg =
217-
'Failed to connect to Dynamsoft License Server: network connection error. Check your Internet connection or contact Dynamsoft Support (support@dynamsoft.com) to acquire an offline license.';
218-
} else {
219-
errMsg = ex.message || ex;
220-
}
209+
let errMsg = ex.message || ex;
221210
console.error(errMsg);
222211
alert(errMsg);
223212
throw ex;
@@ -267,6 +256,7 @@ export class VideoCaptureComponent {
267256
import { Component } from '@angular/core';
268257
import { BarcodeResultItem } from '@dynamsoft/dynamsoft-barcode-reader';
269258
import { CaptureVisionRouter } from 'dynamsoft-capture-vision-router';
259+
import '../../cvr'; // import side effects. The license, engineResourcePath, so on.
270260

271261
@Component({
272262
selector: 'app-image-capture',
@@ -292,13 +282,7 @@ export class ImageCaptureComponent {
292282
if (texts != '') alert(texts);
293283
if (!result.items.length) alert('No barcode found');
294284
} catch (ex: any) {
295-
let errMsg;
296-
if (ex.message?.includes('network connection error')) {
297-
errMsg =
298-
'Failed to connect to Dynamsoft License Server: network connection error. Check your Internet connection or contact Dynamsoft Support (support@dynamsoft.com) to acquire an offline license.';
299-
} else {
300-
errMsg = ex.message || ex;
301-
}
285+
let errMsg = ex.message || ex;
302286
console.error(errMsg);
303287
alert(errMsg);
304288
}

hello-world/electron/README.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ Create the page to be loaded in the created window.
101101
<body>
102102
<h1>Hello World for Electron</h1>
103103
<div id="div-ui-container"></div>
104+
Results:
105+
<br>
106+
<div id="div-results-container"></div>
104107
<script src="action.js"></script>
105108
</body>
106109
</html>
@@ -153,9 +156,17 @@ Dynamsoft.Core.CoreModule.engineResourcePaths = {
153156
// Define a callback for results.
154157
const resultReceiver = new Dynamsoft.CVR.CapturedResultReceiver();
155158
resultReceiver.onDecodedBarcodesReceived = (result) => {
159+
if (!result.barcodesResultItems.length) return;
160+
161+
const resultsContainer = document.querySelector("#div-results-container");
162+
resultsContainer.textContent = '';
163+
console.log(result);
156164
for (let item of result.barcodesResultItems) {
157-
console.log(item.text);
158-
alert(item.text);
165+
resultsContainer.append(
166+
`${item.formatString}: ${item.text}`,
167+
document.createElement('br'),
168+
document.createElement('hr'),
169+
);
159170
}
160171
};
161172
router.addResultReceiver(resultReceiver);
@@ -181,13 +192,7 @@ Dynamsoft.Core.CoreModule.engineResourcePaths = {
181192
await cameraEnhancer.open();
182193
await router.startCapturing("ReadSingleBarcode");
183194
} catch (ex) {
184-
let errMsg;
185-
if (ex.message?.includes("network connection error")) {
186-
errMsg =
187-
"Failed to connect to Dynamsoft License Server: network connection error. Check your Internet connection or contact Dynamsoft Support (support@dynamsoft.com) to acquire an offline license.";
188-
} else {
189-
errMsg = ex.message || ex;
190-
}
195+
let errMsg = ex.message || ex;
191196
console.error(errMsg);
192197
alert(errMsg);
193198
}
@@ -203,6 +208,12 @@ Dynamsoft.Core.CoreModule.engineResourcePaths = {
203208
width: 100%;
204209
height: 80vh;
205210
}
211+
212+
#div-results-container {
213+
width: 100%;
214+
height: 10vh;
215+
overflow: auto;
216+
}
206217
```
207218

208219
## Run the application

hello-world/next/README.md

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,7 @@ CoreModule.engineResourcePaths = {
6464
};
6565

6666
// Preload "BarcodeReader" module for reading barcodes. It will save time on the initial decoding by skipping the module loading.
67-
CoreModule.loadWasm(['DBR']).catch((ex) => {
68-
let errMsg;
69-
if (ex.message?.includes('network connection error')) {
70-
errMsg =
71-
'Failed to connect to Dynamsoft License Server: network connection error. Check your Internet connection or contact Dynamsoft Support (support@dynamsoft.com) to acquire an offline license.';
72-
} else {
73-
errMsg = ex.message || ex;
74-
}
75-
console.error(errMsg);
76-
alert(errMsg);
77-
});
67+
CoreModule.loadWasm(['DBR']);
7868
```
7969

8070
> Note:
@@ -145,10 +135,14 @@ function VideoCapture() {
145135
) => {
146136
if (!result.barcodesResultItems.length) return;
147137

148-
resultsContainer.current!.innerHTML = "";
138+
resultsContainer.current!.textContent = '';
149139
console.log(result);
150140
for (let item of result.barcodesResultItems) {
151-
resultsContainer.current!.innerHTML += `${item.formatString}: ${item.text}<br><hr>`;
141+
resultsContainer.current!.append(
142+
`${item.formatString}: ${item.text}`,
143+
document.createElement('br'),
144+
document.createElement('hr'),
145+
);
152146
}
153147
};
154148
router.addResultReceiver(resultReceiver);
@@ -179,13 +173,7 @@ function VideoCapture() {
179173
router,
180174
};
181175
} catch (ex: any) {
182-
let errMsg;
183-
if (ex.message?.includes("network connection error")) {
184-
errMsg =
185-
"Failed to connect to Dynamsoft License Server: network connection error. Check your Internet connection or contact Dynamsoft Support (support@dynamsoft.com) to acquire an offline license.";
186-
} else {
187-
errMsg = ex.message || ex;
188-
}
176+
let errMsg = ex.message || ex;
189177
console.error(errMsg);
190178
alert(errMsg);
191179
throw ex;
@@ -264,6 +252,7 @@ export default VideoCapture;
264252
import React, { useRef, useEffect } from "react";
265253
import { BarcodeResultItem } from "@dynamsoft/dynamsoft-barcode-reader";
266254
import { CaptureVisionRouter } from "dynamsoft-capture-vision-router";
255+
import "../../cvr"; // import side effects. The license, engineResourcePath, so on.
267256
import "./ImageCapture.css";
268257

269258
function ImageCapture() {
@@ -298,13 +287,9 @@ function ImageCapture() {
298287
if (texts !== "") alert(texts);
299288
if (!result.items.length) alert("No barcode found");
300289
} catch (ex: any) {
301-
if (ex.message.indexOf("network connection error")) {
302-
let customMsg =
303-
"Failed to connect to Dynamsoft License Server: network connection error. Check your Internet connection or contact Dynamsoft Support (support@dynamsoft.com) to acquire an offline license.";
304-
console.log(customMsg);
305-
alert(customMsg);
306-
}
307-
throw ex;
290+
let errMsg = ex.message || ex;
291+
console.error(errMsg);
292+
alert(errMsg);
308293
}
309294
e.target.value = "";
310295
};

hello-world/next/components/ImageCapture/ImageCapture.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ function ImageCapture() {
4141
let errMsg = ex.message || ex;
4242
console.error(errMsg);
4343
alert(errMsg);
44-
throw ex;
4544
}
4645
e.target.value = "";
4746
};

hello-world/nuxt/README.md

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,7 @@ CoreModule.engineResourcePaths = {
6868
};
6969

7070
// Preload "BarcodeReader" module for reading barcodes. It will save time on the initial decoding by skipping the module loading.
71-
CoreModule.loadWasm(['DBR']).catch((ex) => {
72-
let errMsg;
73-
if (ex.message?.includes('network connection error')) {
74-
errMsg =
75-
'Failed to connect to Dynamsoft License Server: network connection error. Check your Internet connection or contact Dynamsoft Support (support@dynamsoft.com) to acquire an offline license.';
76-
} else {
77-
errMsg = ex.message || ex;
78-
}
79-
console.error(errMsg);
80-
alert(errMsg);
81-
});
71+
CoreModule.loadWasm(['DBR']);
8272
```
8373

8474
> Note:
@@ -146,10 +136,14 @@ const init = async (): Promise<{
146136
) => {
147137
if (!result.barcodesResultItems.length) return;
148138
149-
resultsContainer.value!.innerHTML = "";
139+
resultsContainer.value!.textContent = '';
150140
console.log(result);
151141
for (let item of result.barcodesResultItems) {
152-
resultsContainer.value!.innerHTML += `${item.formatString}: ${item.text}<br><hr>`;
142+
resultsContainer.value!.append(
143+
`${item.formatString}: ${item.text}`,
144+
document.createElement('br'),
145+
document.createElement('hr'),
146+
);
153147
}
154148
};
155149
router.addResultReceiver(resultReceiver);
@@ -180,13 +174,7 @@ const init = async (): Promise<{
180174
router,
181175
};
182176
} catch (ex: any) {
183-
let errMsg;
184-
if (ex.message?.includes("network connection error")) {
185-
errMsg =
186-
"Failed to connect to Dynamsoft License Server: network connection error. Check your Internet connection or contact Dynamsoft Support (support@dynamsoft.com) to acquire an offline license.";
187-
} else {
188-
errMsg = ex.message || ex;
189-
}
177+
let errMsg = ex.message || ex;
190178
console.error(errMsg);
191179
alert(errMsg);
192180
throw ex;
@@ -241,6 +229,7 @@ onBeforeUnmount(async () => {
241229
import { onMounted, onBeforeUnmount, ref, type Ref } from "vue";
242230
import { type BarcodeResultItem } from "@dynamsoft/dynamsoft-barcode-reader";
243231
import { CaptureVisionRouter } from "dynamsoft-capture-vision-router";
232+
import "../cvr"; // import side effects. The license, engineResourcePath, so on.
244233
245234
const pInit: Ref<Promise<CaptureVisionRouter> | null> = ref(null);
246235
@@ -261,10 +250,6 @@ const decodeImg = async (e: Event) => {
261250
if (!result.items.length) alert("No barcode found");
262251
} catch (ex: any) {
263252
let errMsg = ex.message || ex;
264-
if (errMsg.includes("network connection error")) {
265-
errMsg =
266-
"Failed to connect to Dynamsoft License Server: network connection error. Check your Internet connection or contact Dynamsoft Support (support@dynamsoft.com) to acquire an offline license.";
267-
}
268253
console.error(errMsg);
269254
alert(errMsg);
270255
}

hello-world/pwa/README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ Results:
3131
<div id="div-results-container" style="width: 100%; height: 10vh; overflow: auto;"></div>
3232
<script>
3333
if (location.protocol === "file:") {
34-
const message = `The page is opened via file:// and our SDKs may not work properly. Please open the page via https:// or host it on "http://localhost/".`;
35-
console.warn(message);
36-
alert(message);
34+
const message = `The page is opened via file:// and our SDKs may not work properly. Please open the page via https:// or host it on "http://localhost/".`;
35+
console.warn(message);
36+
alert(message);
3737
}
3838
</script>
3939
<script>
@@ -74,10 +74,14 @@ Results:
7474
if (!result.barcodesResultItems.length) return;
7575
7676
const resultsContainer = document.querySelector("#div-results-container");
77-
resultsContainer.innerHTML = "";
77+
resultsContainer.textContent = '';
7878
console.log(result);
7979
for (let item of result.barcodesResultItems) {
80-
resultsContainer.innerHTML += `${item.formatString}: ${item.text}<br><hr>`;
80+
resultsContainer.append(
81+
`${item.formatString}: ${item.text}`,
82+
document.createElement('br'),
83+
document.createElement('hr'),
84+
);
8185
}
8286
}
8387
};
@@ -104,13 +108,7 @@ Results:
104108
await cameraEnhancer.open();
105109
await router.startCapturing("ReadSingleBarcode");
106110
} catch (ex) {
107-
let errMsg;
108-
if (ex.message?.includes("network connection error")) {
109-
errMsg =
110-
"Failed to connect to Dynamsoft License Server: network connection error. Check your Internet connection or contact Dynamsoft Support (support@dynamsoft.com) to acquire an offline license.";
111-
} else {
112-
errMsg = ex.message || ex;
113-
}
111+
let errMsg = ex.message || ex;
114112
console.error(errMsg);
115113
alert(errMsg);
116114
}

0 commit comments

Comments
 (0)