Skip to content

Commit e51e3ef

Browse files
authored
Merge pull request #251 from Dynamsoft/_dev
Dev
2 parents c6ddce9 + 4d2fdec commit e51e3ef

File tree

74 files changed

+711
-358
lines changed

Some content is hidden

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

74 files changed

+711
-358
lines changed

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,34 @@ This repository contains multiple samples that demonstrates how to use the [Dyna
44

55
## Get the Code
66

7-
Since the repository has a lot of history, it is slow to clone directly. Please download the [zip](https://github.com/Dynamsoft/barcode-reader-javascript-samples/archive/refs/heads/main.zip)/[tar.gz](https://github.com/Dynamsoft/barcode-reader-javascript-samples/archive/refs/heads/main.tar.gz), or use the `--depth 1` to clone the code.
7+
Cloning the full repository may be slow due to its extensive history. To get started quickly, you have a few options:
8+
9+
- Download as [zip](https://github.com/Dynamsoft/barcode-reader-javascript-samples/archive/refs/heads/main.zip)
10+
- Download as [tar.gz](https://github.com/Dynamsoft/barcode-reader-javascript-samples/archive/refs/heads/main.tar.gz)
11+
- Shallow clone with Git:
12+
813
```git
914
git clone https://github.com/Dynamsoft/barcode-reader-javascript-samples.git --depth 1
1015
```
1116

17+
> [!NOTE]
18+
> If you expect unstable network conditions or prefer to work entirely offline, you can download the [offline package from Dynamsoft website](https://www.dynamsoft.com/barcode-reader/downloads/1000003-confirmation/). This includes the full repository and all required dependencies for offline use.
19+
>
20+
> **Running the Samples Locally**
21+
>
22+
> Opening HTML files directly may not work as expected. Instead, run a local development server. Here’s a quick method using [Visual Studio Code](https://code.visualstudio.com/):
23+
>
24+
> 1. Install the [Five Server extension](https://marketplace.visualstudio.com/items?itemName=yandeu.five-server) from the VS Code Marketplace.
25+
>
26+
> 2. Right-click on `hello-world.html` and select "Open with Five Server". This will serve the application at `http://127.0.0.1:5500/hello-world.html`.
27+
1228
## Request a trial license
1329

1430
A default license is included which allows you to test the sample apps for up to 24 hours. You can [request a 30-day trial license](https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&package=js&utm_source=sampleReadme) via Dynamsoft website to evaluate further.
1531

1632
## Documentation
1733

18-
For the developer guide and full API reference of Dynamsoft Barcode Reader JavaScript library, please check out the [documentation](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/?ver=10.5.1000&utm_source=sampleReadme).
34+
For the developer guide and full API reference of Dynamsoft Barcode Reader JavaScript library, please check out the [documentation](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/?ver=11.0.3000&utm_source=sampleReadme).
1935

2036
## Support
2137

@@ -30,6 +46,7 @@ If you have any questions, feel free to [contact Dynamsoft support](https://www.
3046
Get the basic features working with plain/native JavaScript or within a framework like [Angular](https://angular.io/), [React](https://reactjs.org/) or [Vue](https://vuejs.org/), with RTU-BarcodeScanner APIs.
3147

3248
* [**Scan Single Barcode**](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/main/barcode-scanner-api-samples/scan-single-barcode/hello-world.html) - [run↗](https://demo.dynamsoft.com/samples/dbr/js/barcode-scanner-api-samples/scan-single-barcode/hello-world.html?utm_source=sampleReadme): Scan single barcode from video stream with minimum code in JavaScript.
49+
* [**Scan And Search**](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/main/barcode-scanner-api-samples/scan-single-barcode/scan-and-search.html) - [run↗](https://demo.dynamsoft.com/samples/dbr/js/barcode-scanner-api-samples/scan-single-barcode/scan-and-search.html?utm_source=sampleReadme): Scan a barcode to retrieve the relevant product information from the database in JavaScript.
3350
* [**Hello World in Angular**](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/main/barcode-scanner-api-samples/scan-single-barcode/angular): Read single barcode from camera in an Angular application.
3451
* [**Hello World in React**](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/main/barcode-scanner-api-samples/scan-single-barcode/react): Read single barcode from camera in a React application.
3552
* [**Hello World in Vue**](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/main/barcode-scanner-api-samples/scan-single-barcode/vue): Read single barcode from camera in a Vue application.

barcode-scanner-api-samples/scan-multiple-barcodes/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const config = {
2525
license: "YOUR-LICENSE-KEY",
2626
engineResourcePaths: {
2727
// feel free to change it to your own path
28-
rootDirectory: "https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@10.5.1000/dist/",
28+
rootDirectory: "https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@11.0.3000/dist/",
2929
},
3030
container: ".barcode-scanner-view",
3131
scanMode: Dynamsoft.EnumScanMode.SM_MULTI_UNIQUE,
@@ -73,6 +73,7 @@ A list of 20 dummy products is used, with each scan randomly adding a product to
7373
Multiple samples are provided for single barcode scanning. These samples can be easily adapted to scan multiple unique barcodes by simply updating the `config` object.
7474

7575
* [**Hello World**](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/main/barcode-scanner-api-samples/scan-single-barcode): Scan single barcode from video stream with minimum code in JavaScript.
76+
* [**Scan and Search**](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/main/barcode-scanner-api-samples/scan-single-barcode): Scan a barcode to retrieve the relevant product information from the database in JavaScript.
7677
* [**Hello World in Angular**](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/main/barcode-scanner-api-samples/scan-single-barcode/angular): Read single barcode from camera in an Angular application.
7778
* [**Hello World in React**](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/main/barcode-scanner-api-samples/scan-single-barcode/react): Read single barcode from camera in a React application.
7879
* [**Hello World in Vue**](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/main/barcode-scanner-api-samples/scan-single-barcode/vue): Read single barcode from camera in a Vue application.

barcode-scanner-api-samples/scan-multiple-barcodes/cart-builder.html

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>List-Builder - Scan to Cart Simulation</title>
88

9-
<!-- Dynamsoft Barcode Reader Bundle -->
10-
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@10.5.3000/dist/dbr.bundle.js"></script>
9+
<!-- Include Dynamsoft Barcode Reader Bundle via CDN -->
10+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@11.0.3000/dist/dbr.bundle.js"></script>
1111
<!-- If the network is unstable or you prefer to self-host the SDK, uncomment the line below to load it locally -->
12-
<!-- <script src="../../../distributables/dbr.bundle.js"></script> -->
12+
<!-- <script src="../../../dist/dbr.bundle.js"></script> -->
1313

1414

1515
<style>
@@ -70,16 +70,20 @@
7070

7171
#floatingDiv {
7272
position: fixed;
73-
top: 400px;
74-
left: 100px;
75-
width: 400px;
76-
height: 200px;
73+
top: 40%;
74+
left: 10%;
75+
width: 50%;
76+
height: 25%;
77+
max-width: 400px;
78+
max-height: 200px;
79+
min-width: 150px;
80+
min-height: 150px;
7781
background: #f9f9f9;
7882
border: 2px solid #ccc;
7983
border-radius: 8px;
8084
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
8185
cursor: move;
82-
z-index: 9999;
86+
z-index: 999;
8387
padding: 3px;
8488
box-sizing: border-box;
8589
}
@@ -116,25 +120,22 @@ <h2>Simulated Shopping Cart</h2>
116120
</div>
117121

118122
<script>
123+
const dragDiv = document.getElementById("floatingDiv");
119124
// Function to initialize and launch the barcode scanner
120125
async function startScanner() {
121126
// Create a new instance of Dynamsoft BarcodeScanner with configuration options
122127
const scanner = new Dynamsoft.BarcodeScanner({
123128
// License key for Dynamsoft Barcode Reader (replace with a valid key)
124129
license: "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9",
125130

126-
// Specify the path to the engine resources (loaded from CDN in this case)
127-
engineResourcePaths: {
128-
rootDirectory:
129-
"https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@10.5.3000/dist/",
130-
},
131-
132131
// Set scanning mode to detect multiple unique barcodes in one session
133132
scanMode: Dynamsoft.EnumScanMode.SM_MULTI_UNIQUE,
134133

135134
// Time in milliseconds to forget duplicate barcodes (prevents rapid duplicate scans)
136135
duplicateForgetTime: 5000,
137136

137+
showResultView: false,
138+
138139
// Configure the scanner view (UI settings)
139140
scannerViewConfig: {
140141
container: document.querySelector("#floatingDiv"), // Attach scanner UI to floating div
@@ -225,7 +226,6 @@ <h2>Simulated Shopping Cart</h2>
225226
.addEventListener("click", startScanner);
226227

227228
// Make the Floating Div Draggable
228-
const dragDiv = document.getElementById("floatingDiv");
229229
let offsetX = 0,
230230
offsetY = 0,
231231
isDragging = false;
@@ -244,7 +244,28 @@ <h2>Simulated Shopping Cart</h2>
244244
});
245245

246246
document.addEventListener("mouseup", () => (isDragging = false));
247+
248+
dragDiv.addEventListener("touchstart", (e) => {
249+
isDragging = true;
250+
offsetX = e.touches[0].clientX - dragDiv.offsetLeft;
251+
offsetY = e.touches[0].clientY - dragDiv.offsetTop;
252+
});
253+
254+
document.addEventListener("touchmove", (e) => {
255+
if (isDragging) {
256+
e.preventDefault();
257+
dragDiv.style.left = `${e.touches[0].clientX - offsetX}px`;
258+
dragDiv.style.top = `${e.touches[0].clientY - offsetY}px`;
259+
}
260+
}, { passive: false });
261+
262+
document.addEventListener("touchend", () => (isDragging = false));
247263
};
264+
265+
window.addEventListener("orientationchange", () => {
266+
dragDiv.style.left = "10%"
267+
dragDiv.style.top = "40%"
268+
})
248269
</script>
249270
</body>
250271

barcode-scanner-api-samples/scan-multiple-barcodes/hello-world.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
<title>
88
Dynamsoft Barcode Scanner Sample - Hello World (Decode via Camera)
99
</title>
10-
<!-- Include Dynamsoft Barcode Reader Bundle from CDN -->
11-
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@10.5.3000/dist/dbr.bundle.js"></script>
10+
<!-- Include Dynamsoft Barcode Reader Bundle via CDN -->
11+
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@11.0.3000/dist/dbr.bundle.js"></script>
1212
<!-- If the network is unstable or you prefer to self-host the SDK, uncomment the line below to load it locally -->
13-
<!-- <script src="../../../distributables/dbr.bundle.js"></script> -->
13+
<!-- <script src="../../../dist/dbr.bundle.js"></script> -->
1414

1515

1616
<style>
@@ -59,20 +59,23 @@ <h1 class="barcode-scanner-title">
5959
license: "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9",
6060

6161
// Specify where to render the scanner UI
62-
container: ".barcode-scanner-view",
62+
container: document.querySelector(".barcode-scanner-view"),
6363

6464
// Set scan mode to detect multiple unique barcodes per scan session
6565
scanMode: Dynamsoft.EnumScanMode.SM_MULTI_UNIQUE,
6666

67-
// Display a result view for barcodes detected
68-
showResultView: true,
67+
// showResultView: true,
6968

7069
// Enable an "Upload Image" button for scanning barcodes from existing images
7170
showUploadImageButton: true,
7271

72+
// showPoweredByDynamsoft: false,
73+
7374
// Additional configuration for the scanner UI
7475
scannerViewConfig: {
75-
showCloseButton: true, // Display a close button on the scanner interface
76+
// showCloseButton: false, // Uncomment to show a close button in the scanner UI
77+
showFlashButton: true,
78+
cameraSwitchControl: "toggleFrontBack"
7679
},
7780
};
7881

barcode-scanner-api-samples/scan-single-barcode/README.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
# 📦 Scan Single Barcode - Hello World
1+
# 📦 Scan Single Barcode
2+
3+
## 🚀 1.Hello World
24

35
This sample demonstrates how to use the `BarcodeScanner` API from the [Dynamsoft Barcode Reader JavaScript SDK](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/) to scan a **single barcode** from a video stream using plain JavaScript.
46

5-
## ✨ Features
7+
### ✨ Features
68

79
- Uses `BarcodeScanner` APIs from `dynamsoft-barcode-reader-bundle`
810
- Scans a single barcode at a time
911
- UI rendered to a container element
1012

11-
## 🔧 How It Works
13+
### 🔧 How It Works
1214

1315
The sample uses the `BarcodeScanner` class to launch a scanner and decode a single barcode from a camera stream. The key configuration includes:
1416

@@ -21,7 +23,7 @@ const config = {
2123
license: "YOUR-LICENSE-KEY",
2224
engineResourcePaths: {
2325
// feel free to change it to your own path
24-
rootDirectory: "https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@10.5.1000/dist/",
26+
rootDirectory: "https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@11.0.3000/dist/",
2527
},
2628
container: ".barcode-scanner-view",
2729
};
@@ -34,11 +36,34 @@ const barcodeScanner = new Dynamsoft.BarcodeScanner(config);
3436
barcodeScanner.launch();
3537
```
3638

37-
## 📌 Notes
39+
### 📌 Notes
3840

3941
- This sample scans one **single barcode**, you can configure `scanMode` to change the behavior to scan multiple barcodes.
4042
- To avoid network-related loading issues, consider hosting all required resources locally.
4143

44+
## 🛒 2. Scan and Search
45+
46+
This simple demonstrates how to use the `BarcodeScanner` API from the [Dynamsoft Barcode Reader JavaScript SDK](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/) to scan a product barcode and simulate a search from a product database.
47+
48+
### ✨ Features
49+
50+
- Scan Barcodes using your device camera
51+
- Search by Text or Barcode input
52+
- Displays mock product data as search results
53+
- Responsive UI with modern styling
54+
55+
### 🔧 How It Works
56+
57+
1. Click the Scan button to launch the barcode scanner.
58+
2. Once a barcode is detected, its value is displayed along with placeholder product information.
59+
3. Alternatively, type a product name or barcode manually in the input field and click Search.
60+
4. Results are displayed in the Search Result text area.
61+
62+
### 📌 Notes
63+
64+
- No real backend is connected in this demo; results are mocked.
65+
- You can integrate with a real product API by replacing the placeholder content in the searchResult.value.
66+
4267
## 📄 See other BarcodeScanner samples
4368

4469
* [**Hello World in Angular**](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/main/barcode-scanner-api-samples/scan-single-barcode/angular): Read single barcode from camera in an Angular application.
@@ -48,4 +73,4 @@ barcodeScanner.launch();
4873
Scan multiple barcodes:
4974

5075
* [**Hello World**](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/main/barcode-scanner-api-samples/scan-multiple-barcodes): Scan multiple barcodes from video stream with minimum code in JavaScript.
51-
* [**Cart Builder**](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/main/barcode-scanner-api-samples/scan-multiple-barcodes): Simulates a shopping experience where users scan barcodes to add items to a dynamic cart.
76+
* [**Cart Builder**](https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/main/barcode-scanner-api-samples/scan-multiple-barcodes): Simulates a shopping experience where users scan barcodes to add items to a dynamic cart.

barcode-scanner-api-samples/scan-single-barcode/angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@angular/platform-browser": "^19.2.0",
1818
"@angular/platform-browser-dynamic": "^19.2.0",
1919
"@angular/router": "^19.2.0",
20-
"dynamsoft-barcode-reader-bundle": "10.5.3000",
20+
"dynamsoft-barcode-reader-bundle": "11.0.3000",
2121
"rxjs": "~7.8.0",
2222
"tslib": "^2.3.0",
2323
"zone.js": "~0.15.0"

barcode-scanner-api-samples/scan-single-barcode/angular/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ <h2 class="barcode-scanner-title-text">Hello World for Angular</h2>
44
<svg t="1744959268852" class="barcode-scanner-title-logo" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3482"><path d="M435.8 536.2H512V353z" fill="#DD0031" p-id="3483"></path><path d="M400.9 616.8l-52.4 130.8h-97.2L512 163V64L94.9 212.7l63.6 551.5L512 960V616.8z" fill="#DD0031" p-id="3484"></path><path d="M512 353v183.2h76.2z" fill="#C3002F" p-id="3485"></path><path d="M512 64v99l259.8 584.6h-97.2l-52.4-130.8H512V960l353.5-195.8 63.6-551.5z" fill="#C3002F" p-id="3486"></path></svg>
55
</div>
66
<!-- This div will host the barcode scanner's camera view -->
7-
<div class="barcode-scanner-view"></div>
7+
<div class="barcode-scanner-view" #scannerView></div>
88
</div>
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Component } from '@angular/core';
2-
import { BarcodeScanner } from 'dynamsoft-barcode-reader-bundle';
1+
import { Component, ElementRef, ViewChild } from '@angular/core';
2+
import { BarcodeScanner, BarcodeScannerConfig } from 'dynamsoft-barcode-reader-bundle';
33

44
@Component({
55
selector: 'app-root',
@@ -10,18 +10,27 @@ import { BarcodeScanner } from 'dynamsoft-barcode-reader-bundle';
1010
export class AppComponent {
1111
title = 'angular';
1212

13+
@ViewChild('scannerView') scannerView!: ElementRef<HTMLDivElement>;
14+
1315
async ngAfterViewInit(): Promise<void> {
1416
// Configuration object for initializing the BarcodeScanner instance
15-
const config = {
17+
const config: BarcodeScannerConfig = {
1618
license: "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9", // Replace with your Dynamsoft license key
17-
container: ".barcode-scanner-view", // Specify where to render the scanner UI
19+
container: this.scannerView.nativeElement, // Specify where to render the scanner UI
1820

1921
// Specify the path for the definition file "barcode-scanner.ui.xml" for the scanner view.
20-
uiPath: "https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@10.5.3000/dist/",
22+
uiPath: "https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@11.0.3000/dist/",
23+
24+
// showUploadImageButton: true,
25+
// showPoweredByDynamsoft: false,
26+
// scannerViewConfig: {
27+
// showFlashButton: true,
28+
// cameraSwitchControl: "toggleFrontBack",
29+
// },
2130

2231
// Specify custom paths for the engine resources
2332
engineResourcePaths: {
24-
rootDirectory: "https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@10.5.3000/dist/",
33+
rootDirectory: "https://cdn.jsdelivr.net/npm/",
2534
},
2635
}
2736

@@ -30,7 +39,9 @@ export class AppComponent {
3039

3140
// Launch the scanner; once a barcode is detected, display its text in an alert
3241
barcodeScanner.launch().then((result) => {
33-
alert(result.barcodeResults[0].text);
42+
if (result.barcodeResults.length) {
43+
alert(result.barcodeResults[0].text);
44+
}
3445
});
3546
}
3647
}

0 commit comments

Comments
 (0)