Skip to content

Commit 99aa89c

Browse files
Merge pull request #401 from dynamsoft-docs/preview
update to internal commit 339357d3
2 parents 46c578f + e802acc commit 99aa89c

File tree

2 files changed

+66
-62
lines changed

2 files changed

+66
-62
lines changed

_config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ plugins:
6161
edition: js
6262

6363
defaults:
64+
- scope:
65+
path: "programming-old"
66+
values:
67+
ignore: true
6468
- scope:
6569
path: ""
6670
values:

programming/javascript/user-guide/index.md

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ In this guide, you will learn step by step on how to integrate the DBR-JS SDK in
6161
- [Add feedback](#add-feedback)
6262
- [Customize the UI](#customize-the-ui)
6363
- [API Documentation](#api-documentation)
64-
- [System Requirements](#system-requirements)
6564
- [How to Upgrade](#how-to-upgrade)
6665
- [Release Notes](#release-notes)
6766
- [Next Steps](#next-steps)
@@ -72,11 +71,11 @@ In this guide, you will learn step by step on how to integrate the DBR-JS SDK in
7271
- Angular App - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.20/hello-world/angular)
7372
- React App - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.20/hello-world/react)
7473
- Vue App - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.20/hello-world/vue)
75-
- PWA App - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.20/hello-world/pwa)
74+
- PWA App - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.20/hello-world/pwa) \| [Run](https://demo.dynamsoft.com/Samples/DBR/JS/hello-world/pwa/helloworld-pwa.html?ver=10.4.20&utm_source=guide)
7675
- WebView in Android and iOS - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/v10.4.20/hello-world/webview)
77-
- Read Driver Licenses - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.20/use-case/read-a-drivers-license/index.html)
78-
- Fill A Form - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.20/use-case/fill-a-form-with-barcode-reading.html)
79-
- Show result information on the video - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.20/use-case/show-result-texts-on-the-video.html)
76+
- Read Driver Licenses - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.20/use-case/read-a-drivers-license/index.html) \| [Run](https://demo.dynamsoft.com/Samples/DBR/JS/use-case/read-a-drivers-license/index.html?ver=10.4.20&utm_source=guide)
77+
- Fill A Form - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.20/use-case/fill-a-form-with-barcode-reading.html) \| [Run](https://demo.dynamsoft.com/Samples/DBR/JS/use-case/fill-a-form-with-barcode-reading.html?ver=10.4.20&utm_source=guide)
78+
- Show result information on the video - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.20/use-case/show-result-texts-on-the-video.html) \| [Run](https://demo.dynamsoft.com/Samples/DBR/JS/use-case/show-result-texts-on-the-video.html?ver=10.4.20&utm_source=guide)
8079
- Debug Camera and Collect Video Frame - [Github](https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v10.4.20/others/debug)
8180

8281
You can also:
@@ -116,8 +115,8 @@ The complete code of the "Hello World" example is shown below
116115
cvRouter.setInput(cameraEnhancer);
117116
118117
const resultsContainer = document.querySelector("#results");
119-
cvRouter.addResultReceiver({ onDecodedBarcodesReceived: (result) => {
120-
if (result.barcodeResultItems.length > 0) {
118+
cvRouter.addResultReceiver({ onCapturedResultReceived: (result) => {
119+
if (result.barcodeResultItems?.length) {
121120
resultsContainer.textContent = '';
122121
for (let item of result.barcodeResultItems) {
123122
resultsContainer.textContent += `${item.formatString}: ${item.text}\n\n`;
@@ -204,34 +203,18 @@ When a barcode is decoded, you will see the result text show up under the video
204203
205204
Alternatively, you can test locally by copying and pasting the code shown above into a local file (e.g. "hello-world.html") and opening it in your browser.
206205
207-
*Note*:
208-
209-
If you open the web page as `file:///` or `http://` , the camera may not work correctly because the [MediaDevices: getUserMedia()](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) method only works in secure contexts (HTTPS), in some or all supporting browsers.
210-
211-
To make sure your web application can access the camera, please configure your web server to support HTTPS. The following links may help.
212-
213-
1. NGINX: [Configuring HTTPS servers](https://nginx.org/en/docs/http/configuring_https_servers.html)
214-
2. IIS: [How to create a Self Signed Certificate in IIS](https://aboutssl.org/how-to-create-a-self-signed-certificate-in-iis/)
215-
3. Tomcat: [Setting Up SSL on Tomcat in 5 minutes](https://dzone.com/articles/setting-ssl-tomcat-5-minutes)
216-
4. Node.js: [npm tls](https://nodejs.org/docs/v0.4.1/api/tls.html)
217-
218-
If the test doesn't go as expected, you can [contact us](https://www.dynamsoft.com/company/contact/?ver=10.4.20&utm_source=guide&product=dbr&package=js).
206+
> *Secure Contexts*:
207+
>
208+
> If you open the web page as `http://` , our SDK may not work correctly because the [MediaDevices: getUserMedia()](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia) and other methods only work in [secure contexts](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts) (HTTPS, `localhost`, `127.0.0.1`, `file://`), in some or all supporting browsers.
209+
>
210+
> Regarding configuring https on your server, these guides for [nginx](https://nginx.org/en/docs/http/configuring_https_servers.html) / [IIS](https://aboutssl.org/how-to-create-a-self-signed-certificate-in-iis/) / [tomcat](https://dzone.com/articles/setting-ssl-tomcat-5-minutes) / [nodejs](https://nodejs.org/docs/v0.4.1/api/tls.html) might help.
211+
>
212+
> If the test doesn't go as expected, you can [contact us](https://www.dynamsoft.com/company/contact/?ver=10.4.20&utm_source=guide&product=dbr&package=js).
219213
220214
## Building your own page
221215
222216
### Include the SDK
223217
224-
To utilize the SDK, the initial step involves including the corresponding resource files:
225-
226-
* `core.js` encompasses common classes, interfaces, and enumerations shared across all Dynamsoft SDKs.
227-
* `license.js` introduces the `LicenseManager` class, which manages the licensing for all Dynamsoft SDKs.
228-
* `utility.js` encompasses auxiliary classes shared among all Dynamsoft SDKs.
229-
* `dbr.js` defines interfaces and enumerations tailored to the barcode reader module.
230-
* `cvr.js` introduces the `CaptureVisionRouter` class, which governs the entire image processing workflow.
231-
* `dce.js` comprises classes that offer camera support and basic user interface functionalities.
232-
233-
To simplify things, starting from version 10.0.21, we introduced `dbr.bundle.js`, which combines all six of the above files. In the following chapters, we will use `dbr.bundle.js`.
234-
235218
#### Use a public CDN
236219
237220
The simplest way to include the SDK is to use either the [jsDelivr](https://jsdelivr.com/) or [UNPKG](https://unpkg.com/) CDN. The "hello world" example above uses **jsDelivr**.
@@ -256,7 +239,7 @@ The simplest way to include the SDK is to use either the [jsDelivr](https://jsde
256239
257240
However, please **DO NOT** use `download2.dynamsoft.com` resources in a production application as they are for temporary testing purposes only. Instead, you can try hosting the SDK yourself.
258241
259-
- In frameworks like React and Vue, you may want to add the package as a dependency.
242+
- In frameworks like React, Vue and Angular, you may want to add the package as a dependency.
260243
261244
```sh
262245
npm i dynamsoft-barcode-reader-bundle@10.4.2002 -E
@@ -270,19 +253,13 @@ The simplest way to include the SDK is to use either the [jsDelivr](https://jsde
270253
271254
Besides using the public CDN, you can also download the SDK and host its files on your own server or a commercial CDN before including it in your application.
272255
273-
There are two options for downloading the SDK, and the usage for each is slightly different
274-
275256
- From the website
276257
277258
[Download Dynamsoft Barcode Reader JavaScript Package](https://www.dynamsoft.com/barcode-reader/downloads/?ver=10.4.20&utm_source=guide&product=dbr&package=js)
278259
279-
The resources are located at path `dynamsoft/distributables/<pkg>@<version>`, you can typically include it like this:
280-
281-
```html
282-
<script src="dynamsoft/distributables/dynamsoft-barcode-reader-bundle@10.4.2002/dist/dbr.bundle.js"></script>
283-
```
260+
The resources are located at path `dynamsoft/distributables/<pkg>@<version>`.
284261
285-
- npm
262+
- From npm
286263
287264
```sh
288265
npm i dynamsoft-barcode-reader-bundle@10.4.2002 -E
@@ -291,28 +268,23 @@ There are two options for downloading the SDK, and the usage for each is slightl
291268
npm i dynamsoft-image-processing@2.4.20 -E
292269
```
293270
294-
The resources are located at the path `node_modules/<pkg>`, without `@<version>`, so the script would be like:
295-
296-
```html
297-
<script src="node_modules/dynamsoft-barcode-reader-bundle/dist/dbr.bundle.js"></script>
298-
```
271+
The resources are located at the path `node_modules/<pkg>`, without `@<version>`. You need to copy "dynamsoft-xxx" packages elsewhere and add `@<version>`. `<version>` can be get from `package.json` of each package.
299272
300-
Since the version tags (`@<version>`) are missing, you need to [specify the engineResourcePaths](#specify-the-location-of-the-engine-files-optional) so that the SDK can find the resources correctly.
273+
You can typically include SDK like this:
301274
302-
> To avoid confusion, we suggest renaming "node_modules" or moving "dynamsoft-" packages elsewhere for self-hosting, as "node_modules" is reserved for Node.js dependencies.
275+
```html
276+
<script src="path/to/dynamsoft-barcode-reader-bundle@10.4.2002/dist/dbr.bundle.js"></script>
277+
```
303278
304279
*Note*:
305280
306281
* Certain legacy web application servers may lack support for the `application/wasm` mimetype for .wasm files. To address this, you have two options:
307282
1. Upgrade your web application server to one that supports the `application/wasm` mimetype.
308-
2. Manually define the mimetype on your server. You can refer to the following resources for guidance:
309-
1. [Apache](https://developer.mozilla.org/en-US/docs/Learn/Server-side/Apache_Configuration_htaccess#media_types_and_character_encodings)
310-
2. [IIS](https://docs.microsoft.com/en-us/iis/configuration/system.webserver/staticcontent/mimemap)
311-
3. [Nginx](https://www.nginx.com/resources/wiki/start/topics/examples/full/#mime-types)
283+
2. Manually define the mimetype on your server. You can refer to the guides for [apache](https://developer.mozilla.org/en-US/docs/Learn/Server-side/Apache_Configuration_htaccess#media_types_and_character_encodings) / [IIS](https://docs.microsoft.com/en-us/iis/configuration/system.webserver/staticcontent/mimemap) / [nginx](https://www.nginx.com/resources/wiki/start/topics/examples/full/#mime-types).
312284
313285
* To work properly, the SDK requires a few engine files, which are relatively large and may take quite a few seconds to download. We recommend that you set a longer cache time for these engine files, to maximize the performance of your web application.
314286
315-
```cmd
287+
```
316288
Cache-Control: max-age=31536000
317289
```
318290
@@ -336,14 +308,20 @@ As previously stated, the key "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" serves
336308
337309
#### Specify the location of the "engine" files (optional)
338310
339-
This is usually only required with frameworks like Angular or React, etc. where the referenced JavaScript files such as `cvr.js`, `dbr.js` are compiled into another file.
311+
This is usually only required with frameworks like Angular, React or Vue.
340312
341-
The purpose is to tell the SDK where to find the engine files (\*.worker.js, \*.wasm.js and \*.wasm, etc.). The API is called `Dynamsoft.Core.CoreModule.engineResourcePaths`:
313+
The purpose is to tell the SDK where to find the engine files (\*.worker.js, \*.wasm.js and \*.wasm, etc.).
342314
343-
```javascript
344-
//The following code uses the jsDelivr CDN as an example, feel free to change it to your own location of these files
315+
```ts
316+
// in framework
317+
import { CoreModule } from "dynamsoft-barcode-reader-bundle";
345318
CoreModule.engineResourcePaths.rootDirectory = "https://cdn.jsdelivr.net/npm/";
346319
```
320+
```js
321+
// in pure js
322+
Dynamsoft.Core.CoreModule.engineResourcePaths.rootDirectory = "https://cdn.jsdelivr.net/npm/";
323+
```
324+
These code uses the jsDelivr CDN as an example, feel free to change it to your own location.
347325
348326
### Set up and start image processing
349327
@@ -409,13 +387,14 @@ cvRouter.setInput(cameraEnhancer);
409387
410388
#### Register a result receiver
411389
412-
Once the image processing is complete, the results are sent to all the registered `CapturedResultReceiver` objects. Each `CapturedResultReceiver` object may encompass one or multiple callback functions associated with various result types. In our particular case, our focus is on identifying barcodes within the images, so it's sufficient to define the callback function `onDecodedBarcodesReceived`:
390+
Once the image processing is complete, the results are sent to all the registered `CapturedResultReceiver` objects. Each `CapturedResultReceiver` object may encompass one or multiple callback functions associated with various result types. This time we use `onCapturedResultReceived`:
391+
<!--In our particular case, our focus is on identifying barcodes within the images, so it's sufficient to define the callback function `onDecodedBarcodesReceived`:-->
413392
414393
```javascript
415394
const resultsContainer = document.querySelector("#results");
416395
const resultReceiver = new Dynamsoft.CVR.CapturedResultReceiver();
417-
resultReceiver.onDecodedBarcodesReceived = (result) => {
418-
if (result.barcodeResultItems.length > 0) {
396+
resultReceiver.onCapturedResultReceived = (result) => {
397+
if (result.barcodeResultItems?.length) {
419398
resultsContainer.textContent = '';
420399
for (let item of result.barcodeResultItems) {
421400
// In this example, the barcode results are displayed on the page below the video.
@@ -430,8 +409,8 @@ You can also write code like this. It is the same.
430409
431410
```javascript
432411
const resultsContainer = document.querySelector("#results");
433-
cvRouter.addResultReceiver({ onDecodedBarcodesReceived: (result) => {
434-
if (result.barcodeResultItems.length > 0) {
412+
cvRouter.addResultReceiver({ onCapturedResultReceived: (result) => {
413+
if (result.barcodeResultItems?.length) {
435414
resultsContainer.textContent = '';
436415
for (let item of result.barcodeResultItems) {
437416
// In this example, the barcode results are displayed on the page below the video.
@@ -520,8 +499,7 @@ Please be aware that it is necessary to update the `CapturedResultReceiver` obje
520499
```javascript
521500
const EnumCRIT = Dynamsoft.Core.EnumCapturedResultItemType;
522501
resultReceiver.onCapturedResultReceived = (result) => {
523-
let barcodes = result.items.filter(item => item.type === EnumCRIT.CRIT_BARCODE);
524-
if (barcodes.length > 0) {
502+
if (result.barcodeResultItems?.length) {
525503
// Use a filter to get the image on which barcodes are found.
526504
let image = result.items.filter(
527505
item => item.type === EnumCRIT.CRIT_ORIGINAL_IMAGE
@@ -683,13 +661,33 @@ cvRouter.addResultReceiver(resultReceiver);
683661
684662
### Customize the UI
685663
664+
```javascript
665+
// Create a CameraView instance with default settings
666+
let cameraView = await Dynamsoft.DCE.CameraView.createInstance();
667+
// Create a CameraView instance with a specified HTML file path, typically a local or remote URL
668+
let cameraView1 = await Dynamsoft.DCE.CameraView.createInstance('@engineResourcePath/dce.mobile-native.ui.html');
669+
// Create a CameraView instance within a specified DOM element
670+
let cameraView2 = await Dynamsoft.DCE.CameraView.createInstance(document.getElementById('my-ui'));
671+
// Create a CameraView instance using a custom UI file path
672+
let cameraView3 = await Dynamsoft.DCE.CameraView.createInstance('url/to/my/ui.html');
673+
674+
// Get the UI element associated with the cameraView instance
675+
let uiElement = cameraView.getUIElement();
676+
// Remove the camera selection dropdown from the CameraView's UI element
677+
uiElement.shadowRoot.querySelector('.dce-sel-camera').remove();
678+
// Remove the resolution selection dropdown from the CameraView's UI element
679+
uiElement.shadowRoot.querySelector('.dce-sel-resolution').remove();
680+
```
681+
686682
The UI is part of the auxiliary SDK "Dynamsoft Camera Enhancer", read more on how to [customize the UI](https://www.dynamsoft.com/barcode-reader/docs/core/programming/features/ui-customization-js.html?lang=js).
687683
688684
## API Documentation
689685
690686
You can check out the detailed documentation about the APIs of the SDK at
691687
[https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/?ver=10.4.2002](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/?ver=10.4.2002).
692688
689+
<!-- Compatibility is basically not an issue. Pls remove to another place
690+
693691
## System Requirements
694692
695693
DBR requires the following features to work:
@@ -728,6 +726,8 @@ The following table is a list of supported browsers based on the above requireme
728726
729727
Apart from the browsers, the operating systems may impose some limitations of their own that could restrict the use of the SDK. Browser compatibility ultimately depends on whether the browser on that particular operating system supports the features listed above.
730728
729+
-->
730+
731731
## How to Upgrade
732732
733733
If you want to upgrade the SDK from an old version to a newer one, please see [how to upgrade](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/upgrade-guide/index.html?ver=10.4.2002&utm_source=guide).

0 commit comments

Comments
 (0)