dynamsoft-barcode-reader-bundle 11.2.4000 → 11.4.2000-beta-202604162228

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/LEGAL.txt +8 -1
  2. package/LICENSE +1 -1
  3. package/README.html +541 -115
  4. package/README.md +628 -125
  5. package/dist/dbr.bundle.d.ts +1577 -2689
  6. package/dist/dbr.bundle.esm.js +3 -3
  7. package/dist/dbr.bundle.js +3 -3
  8. package/dist/dbr.bundle.mjs +3 -3
  9. package/dist/dbr.bundle.worker.js +3 -3
  10. package/dist/dynamsoft-barcode-reader-bundle-ml-simd-pthread.js +1 -1
  11. package/dist/dynamsoft-barcode-reader-bundle-ml-simd-pthread.wasm +0 -0
  12. package/dist/dynamsoft-barcode-reader-bundle-ml-simd.js +1 -1
  13. package/dist/dynamsoft-barcode-reader-bundle-ml-simd.wasm +0 -0
  14. package/dist/dynamsoft-barcode-reader-bundle.js +1 -1
  15. package/dist/dynamsoft-barcode-reader-bundle.wasm +0 -0
  16. package/dist/models/Code128Decoder.data +0 -0
  17. package/dist/models/Code39ITFDecoder.data +0 -0
  18. package/dist/models/DataMatrixQRCodeDeblur.data +0 -0
  19. package/dist/models/DataMatrixQRCodeLocalization.data +0 -0
  20. package/dist/models/EAN13Decoder.data +0 -0
  21. package/dist/models/OneDDeblur.data +0 -0
  22. package/dist/models/OneDLocalization.data +0 -0
  23. package/dist/models/PDF417Deblur.data +0 -0
  24. package/dist/models/PDF417Localization.data +0 -0
  25. package/dist/parser-resources/AADHAAR.data +0 -0
  26. package/dist/parser-resources/AAMVA_DL_ID.data +1 -0
  27. package/dist/parser-resources/GS1_AI.data +66 -0
  28. package/dist/parser-resources/MRTD.data +1 -0
  29. package/dist/parser-resources/SOUTH_AFRICA_DL.data +1 -0
  30. package/dist/parser-resources/VIN.data +0 -0
  31. package/dist/templates/DBR-PresetTemplates.json +9 -22
  32. package/dist/ui/barcode-scanner.ui.xml +271 -108
  33. package/dist/ui/dce.rtu.ui.xml +431 -0
  34. package/dist/ui/dce.ui.v5.xml +470 -0
  35. package/dist/ui/dce.ui.xml +138 -114
  36. package/dist/ui/dls.license.dialog.html +1 -1
  37. package/package.json +16 -15
  38. package/samples.url +1 -1
  39. package/API_Reference_BarcodeScanner.url +0 -2
  40. package/API_Reference_Foundational.url +0 -2
  41. package/dist/parser-resources/AADHAAR.dcpres +0 -1
  42. package/dist/parser-resources/AADHAAR_Map.txt +0 -3
  43. package/dist/parser-resources/AAMVA_DL_ID.dcpres +0 -1
  44. package/dist/parser-resources/AAMVA_DL_ID_WITH_MAG_STRIPE.dcpres +0 -1
  45. package/dist/parser-resources/AAMVA_Map.txt +0 -70
  46. package/dist/parser-resources/GS1_AI.dcpres +0 -1
  47. package/dist/parser-resources/GS1_AI_Map.txt +0 -643
  48. package/dist/parser-resources/MRTD_Map.txt +0 -255
  49. package/dist/parser-resources/MRTD_TD1_ID.dcpres +0 -1
  50. package/dist/parser-resources/MRTD_TD2_FRENCH_ID.dcpres +0 -1
  51. package/dist/parser-resources/MRTD_TD2_ID.dcpres +0 -1
  52. package/dist/parser-resources/MRTD_TD2_VISA.dcpres +0 -1
  53. package/dist/parser-resources/MRTD_TD3_PASSPORT.dcpres +0 -1
  54. package/dist/parser-resources/MRTD_TD3_VISA.dcpres +0 -1
  55. package/dist/parser-resources/SOUTH_AFRICA_DL.dcpres +0 -1
  56. package/dist/parser-resources/SOUTH_AFRICA_DL_Map.txt +0 -3
  57. package/dist/parser-resources/VIN.dcpres +0 -1
  58. package/dist/parser-resources/VIN_Map.txt +0 -150
package/README.html CHANGED
@@ -219,181 +219,607 @@
219
219
  </head>
220
220
  <body>
221
221
  <div id='content'>
222
- <h1 id="build-a-web-based-barcode-scanner-using-just-a-few-lines-of-javascript">Build a Web-Based Barcode Scanner Using Just a Few Lines of JavaScript</h1>
223
- <!-- Don't forget to add the TOC & update license section, which is useful for npm README.-->
222
+ <h1 id="barcode-reader-for-your-website---foundational-api-guide">Barcode Reader for Your Website - Foundational API Guide</h1>
223
+ <p><a href="https://www.dynamsoft.com/barcode-reader/sdk-javascript/">Dynamsoft Barcode Reader JavaScript Edition</a> (DBR-JS) is equipped with industry-leading algorithms for exceptional speed, accuracy and read rates in barcode reading. Using its well-designed API, you can turn your web page into a barcode scanner with just a few lines of code. Once the DBR-JS SDK gets integrated into your web page, your users can access a camera via the browser and read barcodes directly from its video input.</p>
224
+ <!-- ![version](https://img.shields.io/npm/v/dynamsoft-barcode-reader.svg)
225
+ ![downloads](https://img.shields.io/npm/dm/dynamsoft-barcode-reader.svg)
226
+ ![jsdelivr](https://img.shields.io/jsdelivr/npm/hm/dynamsoft-barcode-reader.svg)
227
+
228
+ ![version](https://img.shields.io/npm/v/dynamsoft-javascript-barcode.svg)
229
+ ![downloads](https://img.shields.io/npm/dm/dynamsoft-javascript-barcode.svg)
230
+ ![jsdelivr](https://img.shields.io/jsdelivr/npm/hm/dynamsoft-javascript-barcode.svg) -->
231
+ <p>In this guide, you will learn step by step on how to integrate the DBR-JS SDK into your website.</p>
232
+ <p><span style="font-size:20px">Table of Contents</span></p>
224
233
  <ul>
225
- <li><a href="#build-a-web-based-barcode-scanner-using-just-a-few-lines-of-javascript">Build a Web-Based Barcode Scanner Using Just a Few Lines of JavaScript</a></li>
226
- <li><a href="#license">License</a></li>
227
- <li><a href="#quick-start-hello-world-example">Quick Start: Hello World Example</a><ul>
228
- <li><a href="#step-1-setting-up-the-html-and-including-the-barcode-scanner">Step 1: Setting up the HTML and Including the Barcode Scanner</a></li>
229
- <li><a href="#step-2-initializing-the-barcode-scanner">Step 2: Initializing the Barcode Scanner</a></li>
230
- <li><a href="#step-3-launching-the-barcode-scanner">Step 3: Launching the Barcode Scanner</a></li></ul></li>
234
+ <li><a href="#barcode-reader-for-your-website---foundational-api-guide">Barcode Reader for Your Website - Foundational API Guide</a></li>
235
+ <li><a href="#hello-world---simplest-implementation">Hello World - Simplest Implementation</a><ul>
236
+ <li><a href="#understand-the-code">Understand the code</a></li>
237
+ <li><a href="#about-the-code">About the code</a></li>
238
+ <li><a href="#run-the-example">Run the example</a></li></ul></li>
239
+ <li><a href="#preparing-the-sdk">Preparing the SDK</a><ul>
240
+ <li><a href="#step-1-include-the-sdk">Step 1: Include the SDK</a></li>
241
+ <li><a href="#step-2-prepare-the-sdk">Step 2: Prepare the SDK</a></li>
242
+ <li><a href="#1-specify-the-license">1. Specify the license</a></li>
243
+ <li><a href="#2-optional-specify-the-location-of-the-engine-files">2. [Optional] Specify the location of the "engine" files</a></li></ul></li>
244
+ <li><a href="#using-the-sdk">Using the SDK</a><ul>
245
+ <li><a href="#step-1-preload-the-module">Step 1: Preload the module</a></li>
246
+ <li><a href="#step-2-create-a-capturevisionrouter-object">Step 2: Create a CaptureVisionRouter object</a></li>
247
+ <li><a href="#step-3-connect-an-image-source">Step 3: Connect an image source</a></li>
248
+ <li><a href="#step-4-register-a-result-receiver">Step 4: Register a result receiver</a></li>
249
+ <li><a href="#step-5-start-process-video-frames">Step 5: Start process video frames</a></li></ul></li>
250
+ <li><a href="#customizing-the-process">Customizing the process</a><ul>
251
+ <li><a href="#1-adjust-the-preset-template-settings">1. Adjust the preset template settings</a></li>
252
+ <li><a href="#11-change-barcode-settings">1.1. Change barcode settings</a></li>
253
+ <li><a href="#12-retrieve-the-original-image">1.2. Retrieve the original image</a></li>
254
+ <li><a href="#13-change-reading-frequency-to-save-power">1.3. Change reading frequency to save power</a></li>
255
+ <li><a href="#14-specify-a-scan-region">1.4. Specify a scan region</a></li>
256
+ <li><a href="#2-edit-the-preset-templates-directly">2. Edit the preset templates directly</a></li>
257
+ <li><a href="#3-important-filter-the-results">3. [Important] Filter the results</a></li>
258
+ <li><a href="#method-1-verify-results-across-multiple-frames">Method 1: Verify results across multiple frames</a></li>
259
+ <li><a href="#method-2-eliminate-redundant-results-detected-within-a-short-time-frame">Method 2: Eliminate redundant results detected within a short time frame</a></li>
260
+ <li><a href="#4-add-feedback">4. Add feedback</a></li></ul></li>
261
+ <li><a href="#customizing-the-ui">Customizing the UI</a></li>
262
+ <li><a href="#documentation">Documentation</a><ul>
263
+ <li><a href="#api-reference">API Reference</a></li>
264
+ <li><a href="#how-to-upgrade">How to Upgrade</a></li>
265
+ <li><a href="#release-notes">Release Notes</a></li></ul></li>
231
266
  <li><a href="#next-steps">Next Steps</a></li>
232
267
  </ul>
233
- <p>This user guide provides a step-by-step walkthrough of a "Hello World" web application using the <code>BarcodeScanner</code> JavaScript Edition.</p>
234
- <p>The <code>BarcodeScanner</code> class offers the following features:</p>
235
- <ul>
236
- <li><p>High-level APIs that deliver core functionality with a single line of code.</p></li>
237
- <li><p>Pre-built UI components for fast and easy integration.</p></li>
238
- <li><p>Intuitive configuration objects that streamline both algorithm and UI setup.</p></li>
239
- </ul>
240
- <p>We recommend using this guide as a reference when creating your own application. If you are looking for a fully customizable barcode decoding library, you are welcome to use the <a href="https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/user-guide/index.html">Foundational APIs</a>. Before starting, ensure the <strong>basic requirements</strong> are met.</p>
241
- <!--
242
- Thanks to its simplified APIs and built-in UI for video streaming, you can implement basic scanning functionality with just one line of code:
243
- <pre><code class="hljs js language-js"><span class="hljs-keyword">new</span> Dynamsoft.BarcodeScanner().launch().then(<span class="hljs-function"><span class="hljs-params">result</span>=&gt;</span>alert(result.barcodeResults[<span class="hljs-number">0</span>].text));
244
- </code></pre>
245
-
246
- <p align="center" style="text-align:center; white-space: normal; ">
247
- <a target="_blank" href="https://jsfiddle.net/DynamsoftTeam/csm2f9wb/" title="Run via JSFiddle" style="text-decoration:none;">
248
- <img src="https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/jsfiddle.svg" alt="Run via JSFiddle" width="20" height="20" style="width:20px;height:20px;" >
249
- </a>
250
- </p>
251
- -->
268
+ <h2 id="hello-world---simplest-implementation">Hello World - Simplest Implementation</h2>
269
+ <p>Let's start with the "Hello World" example of the DBR-JS SDK which demonstrates how to use the minimum code to enable a web page to read barcodes from a live video stream. </p>
270
+ <p><strong>Basic Requirements</strong></p>
252
271
  <ul>
253
272
  <li>Internet connection</li>
254
273
  <li>A supported browser</li>
255
274
  <li>Camera access</li>
256
275
  </ul>
257
276
  <blockquote>
258
- <p>[!TIP]<br />
259
- Please refer to <a href="https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/faq/system-requirement.html">system requirements</a> for more details.</p>
277
+ <p>Please refer to <a href="https://www.dynamsoft.com/faq/barcode-reader/web/capabilities/system-requirement.html">system requirements</a> for more details.</p>
260
278
  </blockquote>
261
- <h2 id="license">License</h2>
262
- <p>When getting started with Barcode Scanner, we recommend <a href="https://www.dynamsoft.com/customer/license/trialLicense/?product=dbr&utm_source=npm&package=js">getting your own 30-day trial license</a></p>
263
- <!-- When getting started with Barcode Scanner, we recommend getting your own 30-day trial license.
264
-
265
- {% include trialLicense.html %} -->
266
- <h2 id="quick-start-hello-world-example">Quick Start: Hello World Example</h2>
279
+ <h3 id="understand-the-code">Understand the code</h3>
280
+ <p>The complete code of the "Hello World" example is shown below</p>
267
281
  <pre><code class="hljs html language-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
268
- <span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">&quot;en&quot;</span>&gt;</span>
269
- <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
270
- <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@11.2.4000/dist/dbr.bundle.js&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
271
- <span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
272
- <span class="hljs-comment">// Initialize the Dynamsoft Barcode Scanner</span>
273
- <span class="hljs-keyword">const</span> barcodeScanner = <span class="hljs-keyword">new</span> Dynamsoft.BarcodeScanner({
274
- <span class="hljs-comment">// Please don&#x27;t forget to replace YOUR_LICENSE_KEY_HERE</span>
275
- <span class="hljs-attr">license</span>: <span class="hljs-string">&quot;YOUR_LICENSE_KEY_HERE&quot;</span>,
276
- });
277
- (<span class="hljs-keyword">async</span> () =&gt; {
278
- <span class="hljs-comment">// Launch the scanner and wait for the result</span>
279
- <span class="hljs-keyword">const</span> result = <span class="hljs-keyword">await</span> barcodeScanner.launch();
280
- <span class="hljs-comment">// Display the first detected barcode&#x27;s text in an alert</span>
281
- <span class="hljs-keyword">if</span> (result.barcodeResults.length) {
282
- alert(result.barcodeResults[<span class="hljs-number">0</span>].text);
282
+ <span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
283
+ <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
284
+ <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;camera-view-container&quot;</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;width: 100%; height: 60vh&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
285
+ <span class="hljs-tag">&lt;<span class="hljs-name">textarea</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;results&quot;</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;width: 100%; min-height: 10vh; font-size: 3vmin; overflow: auto&quot;</span> <span class="hljs-attr">disabled</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">textarea</span>&gt;</span>
286
+ <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@11.4.2000/dist/dbr.bundle.js&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
287
+ <span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
288
+ Dynamsoft.License.LicenseManager.initLicense(<span class="hljs-string">&quot;DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9&quot;</span>);
289
+ Dynamsoft.Core.CoreModule.loadWasm();
290
+ (<span class="hljs-keyword">async</span> () =&gt; {
291
+ <span class="hljs-keyword">let</span> cvRouter = <span class="hljs-keyword">await</span> Dynamsoft.CVR.CaptureVisionRouter.createInstance();
292
+
293
+ <span class="hljs-keyword">let</span> cameraView = <span class="hljs-keyword">await</span> Dynamsoft.DCE.CameraView.createInstance();
294
+ <span class="hljs-keyword">let</span> cameraEnhancer = <span class="hljs-keyword">await</span> Dynamsoft.DCE.CameraEnhancer.createInstance(cameraView);
295
+ <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&quot;#camera-view-container&quot;</span>).append(cameraView.getUIElement());
296
+ cvRouter.setInput(cameraEnhancer);
297
+
298
+ <span class="hljs-keyword">const</span> resultsContainer = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&quot;#results&quot;</span>);
299
+ <span class="hljs-keyword">await</span> cvRouter.addResultReceiver({ <span class="hljs-attr">onDecodedBarcodesReceived</span>: <span class="hljs-function">(<span class="hljs-params">result</span>) =&gt;</span> {
300
+ <span class="hljs-keyword">if</span> (result.barcodeResultItems?.length) {
301
+ resultsContainer.textContent = <span class="hljs-string">&#x27;&#x27;</span>;
302
+ <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> item <span class="hljs-keyword">of</span> result.barcodeResultItems) {
303
+ resultsContainer.textContent += <span class="hljs-string">`<span class="hljs-subst">${item.formatString}</span>: <span class="hljs-subst">${item.text}</span>\n\n`</span>;
283
304
  }
284
- })();
285
- </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
286
- <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
305
+ }
306
+ }});
307
+
308
+ <span class="hljs-keyword">let</span> filter = <span class="hljs-keyword">new</span> Dynamsoft.Utility.MultiFrameResultCrossFilter();
309
+ filter.enableResultCrossVerification(<span class="hljs-string">&quot;barcode&quot;</span>, <span class="hljs-literal">true</span>);
310
+ filter.enableResultDeduplication(<span class="hljs-string">&quot;barcode&quot;</span>, <span class="hljs-literal">true</span>);
311
+ <span class="hljs-keyword">await</span> cvRouter.addResultFilter(filter);
312
+
313
+ <span class="hljs-keyword">await</span> cameraEnhancer.open();
314
+ <span class="hljs-keyword">await</span> cvRouter.startCapturing(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>);
315
+ })();
316
+ </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
317
+ <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
287
318
  <span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
288
319
  </code></pre>
289
320
  <p align="center" style="text-align:center; white-space: normal; ">
290
- <a target="_blank" href="https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v11.2.40/barcode-scanner-api-samples/scan-single-barcode/hello-world.html" title="Code in Github" style="text-decoration:none;">
321
+ <a target="_blank" href="https://github.com/Dynamsoft/barcode-reader-javascript-samples/blob/v11.4.20/hello-world.html" title="Code in Github" style="text-decoration:none;">
291
322
  <img src="https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/github.svg" alt="Code in Github" width="20" height="20" style="width:20px;height:20px;">
292
323
  </a>
293
324
  &nbsp;
294
- <a target="_blank" href="https://jsfiddle.net/DynamsoftTeam/gcqjf5r7/" title="Run via JSFiddle" style="text-decoration:none;">
325
+ <a target="_blank" href="https://jsfiddle.net/DynamsoftTeam/csm2f9wb/" title="Run via JSFiddle" style="text-decoration:none;">
295
326
  <img src="https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/jsfiddle.svg" alt="Run via JSFiddle" width="20" height="20" style="width:20px;height:20px;" >
296
327
  </a>
297
328
  &nbsp;
298
- <a target="_blank" href="https://demo.dynamsoft.com/Samples/DBR/JS/barcode-scanner-api-samples/scan-single-barcode/hello-world.html?ver=11.2.40&utm_source=npm" title="Run in Dynamsoft" style="text-decoration:none;">
329
+ <a target="_blank" href="https://demo.dynamsoft.com/Samples/DBR/JS/hello-world.html?ver=11.4.20&utm_source=npm" title="Run in Dynamsoft" style="text-decoration:none;">
299
330
  <img src="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.0.0/svgs/solid/circle-play.svg" alt="Run in Dynamsoft" width="20" height="20" style="width:20px;height:20px;">
300
331
  </a>
301
332
  </p>
302
- <h3 id="step-1-setting-up-the-html-and-including-the-barcode-scanner">Step 1: Setting up the HTML and Including the Barcode Scanner</h3>
303
- <p>As outlined earlier, this guide will help you create a simple Hello World barcode scanning application using vanilla JavaScript. The full sample code is also available in the <a href="https://github.com/Dynamsoft/barcode-reader-javascript-samples/tree/v11.2.40">GitHub repository</a>.</p>
304
- <p>The first step before writing the code is to include the SDK in your application. You can simply include the SDK by using the precompiled script.</p>
305
- <pre><code class="hljs html language-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
306
- <span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">&quot;en&quot;</span>&gt;</span>
307
- <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
308
- <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@11.2.4000/dist/dbr.bundle.js&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
309
- <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
310
- <span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
311
- </code></pre>
312
- <p>In this example, we include the precompiled Barcode Scanner SDK script via public CDN in the body.</p>
333
+ <!-- > Don't want to deal with too many details? You can get a quick start with the [BarcodeScanner >>](https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/user-guide/index.html)
334
+ > ```js
335
+ > // Scan instantly with a single line of code!
336
+ > new Dynamsoft.BarcodeScanner().launch().then(result=>alert(result.barcodeResults[0].text));
337
+ > ``` -->
338
+ <hr />
339
+ <h4 id="about-the-code">About the code</h4>
340
+ <ul>
341
+ <li><p><code>Dynamsoft.License.LicenseManager.initLicense()</code>: This method initializes the license for using the SDK in the application. Note that the string "<strong>DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9</strong>" used in this example points to an online license that requires a network connection to work. Read more on <a href="#1-specify-the-license">Specify the license</a>.</p></li>
342
+ <li><p><code>Dynamsoft.Core.CoreModule.loadWasm()</code>: This is an optional code. Used to load wasm resources in advance, reducing latency between video playing and barcode decoding.</p></li>
343
+ <li><p><code>Dynamsoft.CVR.CaptureVisionRouter.createInstance()</code>: This method creates a <code>CaptureVisionRouter</code> object <code>cvRouter</code> which controls the entire process in three steps:</p></li>
344
+ <li><p><strong>Retrieve Images from the Image Source</strong></p>
345
+ <ul>
346
+ <li><code>cvRouter</code> connects to the image source through the <a href="https://www.dynamsoft.com/capture-vision/docs/core/architecture/input.html#image-source-adapter?lang=js">ImageSourceAdapter</a> interface with the method <code>setInput()</code>.<br />
347
+ <code>js
348
+ cvRouter.setInput(cameraEnhancer);
349
+ </code><br />
350
+ &gt; The image source in our case is a <a href="https://www.dynamsoft.com/camera-enhancer/docs/web/programming/javascript/user-guide/index.html">CameraEnhancer</a> object created with <code>Dynamsoft.DCE.CameraEnhancer.createInstance(cameraView)</code></li></ul></li>
351
+ <li><p><strong>Coordinate Image-Processing Tasks</strong></p>
352
+ <ul>
353
+ <li>The coordination happens behind the scenes. <code>cvRouter</code> starts the process by specifying a preset template "ReadSingleBarcode" in the method <code>startCapturing()</code>.<br />
354
+ <code>js
355
+ cvRouter.startCapturing("ReadSingleBarcode");
356
+ </code></li></ul></li>
357
+ <li><p><strong>Dispatch Results to Listening Objects</strong></p>
358
+ <ul>
359
+ <li>The processing results are returned through the <a href="https://www.dynamsoft.com/capture-vision/docs/core/architecture/output.html#captured-result-receiver?lang=js">CapturedResultReceiver</a> interface. The <code>CapturedResultReceiver</code> object is registered to <code>cvRouter</code> via the method <code>addResultReceiver()</code>. For more information, please check out <a href="#step-4-register-a-result-receiver">Register a result receiver</a>.<br />
360
+ <code>js
361
+ cvRouter.addResultReceiver({/*The-CapturedResultReceiver-Object"*/});
362
+ </code></li>
363
+ <li>Also note that reading from video is extremely fast and there could be many duplicate results. We can use a <a href="#3-important-filter-the-results">filter</a> with result deduplication enabled to filter out the duplicate results. The object is registered to <code>cvRouter</code> via the method <code>addResultFilter()</code>.<br />
364
+ <code>js
365
+ cvRouter.addResultFilter(filter);
366
+ </code></li></ul></li>
367
+ </ul>
368
+ <blockquote>
369
+ <p>Read more on <a href="https://www.dynamsoft.com/capture-vision/docs/core/architecture/#capture-vision-router">Capture Vision Router</a>.</p>
370
+ </blockquote>
371
+ <h3 id="run-the-example">Run the example</h3>
372
+ <p>You can run the example deployed to <a href="https://demo.dynamsoft.com/Samples/DBR/JS/hello-world.html?ver=11.4.20&utm_source=npm">the Dynamsoft Demo Server</a> or test it with <a href="https://jsfiddle.net/DynamsoftTeam/csm2f9wb/">JSFiddle code editor</a>. </p>
373
+ <p>You will be asked to allow access to your camera, after which the video will be displayed on the page. After that, you can point the camera at a barcode to read it.</p>
374
+ <p>When a barcode is decoded, you will see the result text show up under the video and the barcode location will be highlighted in the video feed.</p>
375
+ <p>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.</p>
376
+ <blockquote>
377
+ <p><em>Secure Contexts</em>:</p>
378
+ <p>If you open the web page as <code>http://</code> , our SDK may not work correctly because the <a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia">MediaDevices: getUserMedia()</a> and other methods only work in <a href="https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts">secure contexts</a> (HTTPS, <code>localhost</code>, <code>127.0.0.1</code>, <code>file://</code>), in some or all supporting browsers.</p>
379
+ <p>Regarding configuring https on your server, these guides for <a href="https://nginx.org/en/docs/http/configuring_https_servers.html">nginx</a> / <a href="https://aboutssl.org/how-to-create-a-self-signed-certificate-in-iis/">IIS</a> / <a href="https://dzone.com/articles/setting-ssl-tomcat-5-minutes">tomcat</a> / <a href="https://nodejs.org/docs/v0.4.1/api/tls.html">nodejs</a> might help.</p>
380
+ <p>If the test doesn't go as expected, you can <a href="https://www.dynamsoft.com/company/contact/?ver=11.4.20&utm_source=npm&product=dbr&package=js">contact us</a>.</p>
381
+ </blockquote>
382
+ <h2 id="preparing-the-sdk">Preparing the SDK</h2>
383
+ <h3 id="step-1-include-the-sdk">Step 1: Include the SDK</h3>
313
384
  <div class="multi-panel-switching-prefix"></div>
385
+ <!--
386
+ - [Use a public CDN](#useapubliccdn)
387
+ - [Host the SDK yourself](#hostthesdkyourself) -->
314
388
  <div class="multi-panel-start"></div>
315
389
  <div class="multi-panel-title">Use a public CDN</div>
316
- <p>The simplest way to include the SDK is to use either the <a href="https://jsdelivr.com/"><strong>jsDelivr</strong></a> or <a href="https://unpkg.com/"><strong>UNPKG</strong></a> CDN.</p>
390
+ <p>The simplest way to include the SDK is to use either the <a href="https://jsdelivr.com/">jsDelivr</a> or <a href="https://unpkg.com/">UNPKG</a> CDN. The "hello world" example above uses <strong>jsDelivr</strong>.</p>
317
391
  <ul>
318
392
  <li>jsDelivr</li>
319
393
  </ul>
320
- <pre><code class="hljs html language-html"> <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@11.2.4000/dist/dbr.bundle.js&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
394
+ <pre><code class="hljs html language-html"> <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@11.4.2000/dist/dbr.bundle.js&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
321
395
  </code></pre>
322
396
  <ul>
323
397
  <li>UNPKG</li>
324
398
  </ul>
325
- <pre><code class="hljs html language-html"> <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;https://unpkg.com/dynamsoft-barcode-reader-bundle@11.2.4000/dist/dbr.bundle.js&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
399
+ <pre><code class="hljs html language-html"> <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;https://unpkg.com/dynamsoft-barcode-reader-bundle@11.4.2000/dist/dbr.bundle.js&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
400
+ </code></pre>
401
+ <!-- - In some rare cases (such as some restricted areas), you might not be able to access the CDN. If this happens, you can use the following files for the test.
402
+ <pre><code class="hljs html language-html"> <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;https://download2.dynamsoft.com/packages/dynamsoft-barcode-reader-bundle@11.4.2000/dist/dbr.bundle.js&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
326
403
  </code></pre>
327
- <p>When using a framework such as <strong>React</strong>, <strong>Vue</strong> or <strong>Angular</strong>, we recommend adding the package as a dependency using a package manager such as <strong>npm</strong> or <strong>yarn</strong>:</p>
328
- <pre><code class="hljs sh language-sh"> npm i dynamsoft-barcode-reader-bundle@11.2.4000
404
+
405
+ 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. -->
406
+ <ul>
407
+ <li>In frameworks like React, Vue and Angular, you may want to add the package as a dependency.</li>
408
+ </ul>
409
+ <pre><code class="hljs sh language-sh"> npm i dynamsoft-barcode-reader-bundle@11.4.2000 -E
329
410
  <span class="hljs-comment"># or</span>
330
- yarn add dynamsoft-barcode-reader-bundle@11.2.4000
411
+ yarn add dynamsoft-barcode-reader-bundle@11.4.2000 -E
331
412
  </code></pre>
332
- <p>When using package managers like <strong>npm</strong> or <strong>yarn</strong>, you likely need to specify the location of the engine files as a link to a CDN. Please see the <a href="https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/barcode-scanner.html#barcodescannerconfig">BarcodeScannerConfig API</a> for a code snippet on how to set the <code>engineResourcePaths</code>.</p>
413
+ <p>NOTE that in frameworks, you need to <a href="#2-optional-specify-the-location-of-the-engine-files">specify the location of the engine files</a>.</p>
333
414
  <div class="multi-panel-end"></div>
334
415
  <div class="multi-panel-start"></div>
335
416
  <div class="multi-panel-title">Host the SDK yourself</div>
336
- <p>Alternatively, you may choose to download the SDK and host the files on your own server or preferred CDN. This approach provides better control over versioning and availability.</p>
417
+ <p>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.</p>
337
418
  <ul>
338
419
  <li><p>From the website</p>
339
- <p><a href="https://www.dynamsoft.com/barcode-reader/downloads/?ver=11.2.40&utm_source=npm&product=dbr&package=js">Download Dynamsoft Barcode Reader JavaScript Package</a></p>
340
- <p>The resources are located in the <code>./dist/</code> directory.</p></li>
420
+ <p><a href="https://www.dynamsoft.com/barcode-reader/downloads/?ver=11.4.20&utm_source=npm&product=dbr&package=js">Download Dynamsoft Barcode Reader JavaScript Package</a></p>
421
+ <p>The resources are located at path <code>dynamsoft/distributables/&lt;pkg&gt;@&lt;version&gt;</code>.</p></li>
341
422
  <li><p>From npm</p></li>
342
423
  </ul>
343
- <pre><code class="hljs sh language-sh"> npm i dynamsoft-barcode-reader-bundle@11.2.4000
424
+ <pre><code class="hljs sh language-sh"> npm i dynamsoft-barcode-reader-bundle@11.4.2000 -E
344
425
  </code></pre>
345
- <p>The resources are located at the path <code>node_modules/&lt;pkg&gt;</code>, without <code>@&lt;version&gt;</code>. You can copy it elsewhere and add <code>@&lt;version&gt;</code> tag.</p>
426
+ <p>The resources are located at the path <code>node_modules/&lt;pkg&gt;</code>, without <code>@&lt;version&gt;</code>. You must copy "dynamsoft-xxx" packages elsewhere and add <code>@&lt;version&gt;</code>. The <code>&lt;version&gt;</code> can be obtained from <code>package.json</code> of each package. Another thing to do is to <a href="#2-optional-specify-the-location-of-the-engine-files">specify the engineResourcePaths</a> so that the SDK can correctly locate the resources.</p>
346
427
  <blockquote>
347
- <p>[!IMPORTANT]<br />
348
- Since "node<em>modules" is reserved for Node.js dependencies, and in our case the package is used only as static resources, we recommend either renaming the "node</em>modules" folder or moving the "dynamsoft-" packages to a dedicated folder for static resources in your project to facilitate self-hosting.</p>
428
+ <p>Since "node<em>modules" is reserved for Node.js dependencies, and in our case the package is used only as static resources, we recommend either renaming the "node</em>modules" folder or moving the "dynamsoft-" packages to a dedicated folder for static resources in your project to facilitate self-hosting.</p>
349
429
  </blockquote>
350
- <p>You can typically include the SDK like this:</p>
351
- <pre><code class="hljs html language-html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;path/to/dynamsoft-barcode-reader-bundle@11.2.4000/dist/dbr.bundle.js&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
430
+ <p>You can typically include SDK like this:</p>
431
+ <pre><code class="hljs html language-html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;path/to/dynamsoft-barcode-reader-bundle@11.4.2000/dist/dbr.bundle.js&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
352
432
  </code></pre>
353
433
  <div class="multi-panel-end"></div>
354
434
  <div class="multi-panel-switching-end"></div>
355
- <p>Barcode Scanner comes with a <strong>Ready-to-Use UI</strong>. When the Barcode Scanner launches, it creates a container which it populates with the <strong>Ready-to-Use UI</strong>.</p>
356
- <h3 id="step-2-initializing-the-barcode-scanner">Step 2: Initializing the Barcode Scanner</h3>
357
- <pre><code class="hljs js language-js"><span class="hljs-comment">// Initialize the Dynamsoft Barcode Scanner</span>
358
- <span class="hljs-keyword">const</span> barcodeScanner = <span class="hljs-keyword">new</span> Dynamsoft.BarcodeScanner({
359
- <span class="hljs-comment">// Please don&#x27;t forget to replace YOUR_LICENSE_KEY_HERE</span>
360
- <span class="hljs-attr">license</span>: <span class="hljs-string">&quot;YOUR_LICENSE_KEY_HERE&quot;</span>,
361
- });
435
+ <p><em>Note</em>:</p>
436
+ <ul>
437
+ <li>Certain legacy web application servers may lack support for the <code>application/wasm</code> mimetype for .wasm files. To address this, you have two options:</li>
438
+ </ul>
439
+ <ol>
440
+ <li>Upgrade your web application server to one that supports the <code>application/wasm</code> mimetype.</li>
441
+ <li>Manually define the mimetype on your server. You can refer to the guides for <a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Apache_Configuration_htaccess#media_types_and_character_encodings">apache</a> / <a href="https://docs.microsoft.com/en-us/iis/configuration/system.webserver/staticcontent/mimemap">IIS</a> / <a href="https://www.nginx.com/resources/wiki/start/topics/examples/full/#mime-types">nginx</a>.</li>
442
+ </ol>
443
+ <ul>
444
+ <li>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.</li>
445
+ </ul>
446
+ <pre><code>hljs <span class="hljs-keyword">Cache</span><span class="hljs-params">-Control</span>: <span class="hljs-keyword">max</span><span class="hljs-params">-age</span>=<span class="hljs-number">31536000</span>
362
447
  </code></pre>
363
- <p>This is the <strong>simplest</strong> way to initialize the Barcode Scanner. The configuration object must include a valid <strong>license</strong> key. Without it, the scanner will fail to launch and display an error. For help obtaining a license, see the <a href="#license">licensing</a> section.</p>
448
+ <p>Reference: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control">Cache-Control</a>.</p>
449
+ <h3 id="step-2-prepare-the-sdk">Step 2: Prepare the SDK</h3>
450
+ <p>Before using the SDK, you need to configure a few things.</p>
451
+ <h4 id="1-specify-the-license">1. Specify the license</h4>
452
+ <p>To enable the SDK's functionality, you must provide a valid license. Utilize the API function initLicense to set your license key.</p>
453
+ <pre><code class="hljs javascript language-javascript">Dynamsoft.License.LicenseManager.initLicense(<span class="hljs-string">&quot;DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9&quot;</span>);
454
+ </code></pre>
455
+ <p>As previously stated, the key "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" serves as a test license valid for 24 hours, applicable to any newly authorized browser. To test the SDK further, you can request a 30-day free trial license via the <a href="https://www.dynamsoft.com/customer/license/trialLicense?ver=11.4.20&utm_source=npm&product=dbr&package=js" target="_blank">Request a Trial License</a> link.</p>
364
456
  <blockquote>
365
- <p>[!TIP]<br />
366
- By default, the <code>BarcodeScanner</code> scans a single barcode at a time. However, it also supports a <code>MULTI_UNIQUE</code> scanning mode, which continuously scans and accumulates unique results in real time. You can enable this mode by modifying the <a href="https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/barcode-scanner.html#barcodescannerconfig"><code>BarcodeScannerConfig</code></a> as follows:</p>
457
+ <p>Upon registering a Dynamsoft account and obtaining the SDK package from the official website, Dynamsoft will automatically create a 30-day free trial license and embed the corresponding license key into all the provided SDK samples.</p>
367
458
  </blockquote>
368
- <pre><code class="hljs js language-js"><span class="hljs-comment">// Initialize the Dynamsoft Barcode Scanner in MULTI_UNIQUE mode</span>
369
- <span class="hljs-keyword">const</span> barcodeScanner = <span class="hljs-keyword">new</span> Dynamsoft.BarcodeScanner({
370
- <span class="hljs-attr">license</span>: <span class="hljs-string">&quot;YOUR_LICENSE_KEY_HERE&quot;</span>,
371
- <span class="hljs-attr">scanMode</span>: Dynamsoft.EnumScanMode.SM_MULTI_UNIQUE,
459
+ <h4 id="2-optional-specify-the-location-of-the-engine-files">2. [Optional] Specify the location of the "engine" files</h4>
460
+ <p>This step is generally necessary when utilizing frameworks such as Angular, React, Vue, or when managing the hosting of resource files yourself.</p>
461
+ <p>The purpose is to tell the SDK where to find the engine files (*.worker.js, *.wasm.js and *.wasm, etc.).</p>
462
+ <pre><code class="hljs ts language-ts"><span class="hljs-comment">// in framework</span>
463
+ <span class="hljs-keyword">import</span> { CoreModule } <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;dynamsoft-barcode-reader-bundle&quot;</span>;
464
+ CoreModule.engineResourcePaths.rootDirectory = <span class="hljs-string">&quot;https://cdn.jsdelivr.net/npm/&quot;</span>;
465
+ </code></pre>
466
+ <pre><code class="hljs js language-js"><span class="hljs-comment">// in pure js</span>
467
+ Dynamsoft.Core.CoreModule.engineResourcePaths.rootDirectory = <span class="hljs-string">&quot;https://cdn.jsdelivr.net/npm/&quot;</span>;
468
+ </code></pre>
469
+ <p>These code uses the jsDelivr CDN as an example, feel free to change it to your own location.</p>
470
+ <h2 id="using-the-sdk">Using the SDK</h2>
471
+ <h3 id="step-1-preload-the-module">Step 1: Preload the module</h3>
472
+ <p>The image processing logic is encapsulated within .wasm library files, and these files may require some time for downloading. To enhance the speed, we advise utilizing the following method to preload the libraries.</p>
473
+ <pre><code class="hljs js language-js"><span class="hljs-comment">// Preload the .wasm files</span>
474
+ Dynamsoft.Core.CoreModule.loadWasm();
475
+ </code></pre>
476
+ <h3 id="step-2-create-a-capturevisionrouter-object">Step 2: Create a CaptureVisionRouter object</h3>
477
+ <p>To use the SDK, we first create a <code>CaptureVisionRouter</code> object.</p>
478
+ <pre><code class="hljs javascript language-javascript">Dynamsoft.License.LicenseManager.initLicense(<span class="hljs-string">&quot;DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9&quot;</span>);
479
+
480
+ <span class="hljs-keyword">let</span> cvRouter = <span class="hljs-literal">null</span>;
481
+ <span class="hljs-keyword">try</span> {
482
+ cvRouter = <span class="hljs-keyword">await</span> Dynamsoft.CVR.CaptureVisionRouter.createInstance();
483
+ } <span class="hljs-keyword">catch</span> (ex) {
484
+ <span class="hljs-built_in">console</span>.error(ex);
485
+ }
486
+ </code></pre>
487
+ <p><em>Tip</em>:</p>
488
+ <p>When creating a <code>CaptureVisionRouter</code> object within a function which may be called more than once, it's best to use a "helper" variable to avoid double creation such as <code>pCvRouter</code> in the following code:</p>
489
+ <pre><code class="hljs javascript language-javascript">Dynamsoft.License.LicenseManager.initLicense(<span class="hljs-string">&quot;DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9&quot;</span>);
490
+
491
+ <span class="hljs-keyword">let</span> pCvRouter = <span class="hljs-literal">null</span>; <span class="hljs-comment">// The helper variable which is a promise of cvRouter</span>
492
+ <span class="hljs-keyword">let</span> cvRouter = <span class="hljs-literal">null</span>;
493
+
494
+ <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">&#x27;btn-scan&#x27;</span>).addEventListener(<span class="hljs-string">&#x27;click&#x27;</span>, <span class="hljs-keyword">async</span> () =&gt; {
495
+ <span class="hljs-keyword">try</span> {
496
+ cvRouter = <span class="hljs-keyword">await</span> (pCvRouter = pCvRouter || Dynamsoft.CVR.CaptureVisionRouter.createInstance());
497
+ } <span class="hljs-keyword">catch</span> (ex) {
498
+ <span class="hljs-built_in">console</span>.error(ex);
499
+ }
372
500
  });
373
501
  </code></pre>
374
- <h3 id="step-3-launching-the-barcode-scanner">Step 3: Launching the Barcode Scanner</h3>
375
- <pre><code class="hljs js language-js">(<span class="hljs-keyword">async</span> () =&gt; {
376
- <span class="hljs-comment">// Launch the scanner and wait for the result</span>
377
- <span class="hljs-keyword">const</span> result = <span class="hljs-keyword">await</span> barcodeScanner.launch();
378
- <span class="hljs-comment">// Display the first detected barcode&#x27;s text in an alert</span>
379
- <span class="hljs-keyword">if</span> (result.barcodeResults.length) {
380
- alert(result.barcodeResults[<span class="hljs-number">0</span>].text);
502
+ <h3 id="step-3-connect-an-image-source">Step 3: Connect an image source</h3>
503
+ <p>The <code>CaptureVisionRouter</code> object, denoted as <code>cvRouter</code>, is responsible for handling images provided by an image source. In our scenario, we aim to detect barcodes directly from a live video stream. To facilitate this, we initialize a <code>CameraEnhancer</code> object, identified as <code>cameraEnhancer</code>, which is specifically designed to capture image frames from the video feed and subsequently forward them to <code>cvRouter</code>.</p>
504
+ <p>To enable video streaming on the webpage, we create a <code>CameraView</code> object referred to as <code>cameraView</code>, which is then passed to <code>cameraEnhancer</code>, and its content is displayed on the webpage.</p>
505
+ <pre><code class="hljs html language-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;camera-view-container&quot;</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;width: 100%; height: 100vh&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
506
+ </code></pre>
507
+ <pre><code class="hljs javascript language-javascript"><span class="hljs-keyword">let</span> cameraView = <span class="hljs-keyword">await</span> Dynamsoft.DCE.CameraView.createInstance();
508
+ <span class="hljs-keyword">let</span> cameraEnhancer = <span class="hljs-keyword">await</span> Dynamsoft.DCE.CameraEnhancer.createInstance(cameraView);
509
+ <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&quot;#camera-view-container&quot;</span>).append(cameraView.getUIElement());
510
+ cvRouter.setInput(cameraEnhancer);
511
+ </code></pre>
512
+ <h3 id="step-4-register-a-result-receiver">Step 4: Register a result receiver</h3>
513
+ <p>Once the image processing is complete, the results are sent to all the registered <code>CapturedResultReceiver</code> objects. Each <code>CapturedResultReceiver</code> object may encompass one or multiple callback functions associated with various result types. This time we use <code>onDecodedBarcodesReceived</code>:</p>
514
+ <!--In our particular case, our focus is on identifying barcodes within the images, so it's sufficient to define the callback function `onDecodedBarcodesReceived`:-->
515
+ <pre><code class="hljs javascript language-javascript"><span class="hljs-keyword">const</span> resultsContainer = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&quot;#results&quot;</span>);
516
+ <span class="hljs-keyword">const</span> resultReceiver = <span class="hljs-keyword">new</span> Dynamsoft.CVR.CapturedResultReceiver();
517
+ resultReceiver.onDecodedBarcodesReceived = <span class="hljs-function">(<span class="hljs-params">result</span>) =&gt;</span> {
518
+ <span class="hljs-keyword">if</span> (result.barcodeResultItems?.length) {
519
+ resultsContainer.textContent = <span class="hljs-string">&#x27;&#x27;</span>;
520
+ <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> item <span class="hljs-keyword">of</span> result.barcodeResultItems) {
521
+ <span class="hljs-comment">// In this example, the barcode results are displayed on the page below the video.</span>
522
+ resultsContainer.textContent += <span class="hljs-string">`<span class="hljs-subst">${item.formatString}</span>: <span class="hljs-subst">${item.text}</span>\n\n`</span>;
523
+ }
381
524
  }
382
- })();
525
+ };
526
+ <span class="hljs-keyword">await</span> cvRouter.addResultReceiver(resultReceiver);
383
527
  </code></pre>
384
- <p>Now that the Barcode Scanner has been initialized and configured, it is ready to be launched! Upon launch, the Barcode Scanner presents the main <strong><code>BarcodeScannerView</code></strong> UI in its container on the page, and is ready to start scanning. By default, we use the <code>SINGLE</code> scanning mode, which means only one decoding result will be included in the final result. In the code above, we directly alerted the successfully decoded barcode text on the page.</p>
528
+ <p>You can also write code like this. It is the same.</p>
529
+ <pre><code class="hljs javascript language-javascript"><span class="hljs-keyword">const</span> resultsContainer = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&quot;#results&quot;</span>);
530
+ <span class="hljs-keyword">await</span> cvRouter.addResultReceiver({ <span class="hljs-attr">onDecodedBarcodesReceived</span>: <span class="hljs-function">(<span class="hljs-params">result</span>) =&gt;</span> {
531
+ <span class="hljs-keyword">if</span> (result.barcodeResultItems?.length) {
532
+ resultsContainer.textContent = <span class="hljs-string">&#x27;&#x27;</span>;
533
+ <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> item <span class="hljs-keyword">of</span> result.barcodeResultItems) {
534
+ <span class="hljs-comment">// In this example, the barcode results are displayed on the page below the video.</span>
535
+ resultsContainer.textContent += <span class="hljs-string">`<span class="hljs-subst">${item.formatString}</span>: <span class="hljs-subst">${item.text}</span>\n\n`</span>;
536
+ }
537
+ }
538
+ }});
539
+ </code></pre>
540
+ <p>Check out <a href="https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/capture-vision-router/captured-result-receiver.html">CapturedResultReceiver</a> for more information.</p>
541
+ <h3 id="step-5-start-process-video-frames">Step 5: Start process video frames</h3>
542
+ <p>With the setup now complete, we can proceed to process the images in two straightforward steps:</p>
543
+ <ol>
544
+ <li>Initiate the image source to commence image acquisition. In our scenario, we invoke the <code>open()</code> method on <code>cameraEnhancer</code> to initiate video streaming and simultaneously initiate the collection of images. These collected images will be dispatched to <code>cvRouter</code> as per its request.</li>
545
+ <li>Define a preset template to commence image processing. In our case, we utilize the "ReadSingleBarcode" template, specifically tailored for processing images containing a single barcode.</li>
546
+ </ol>
547
+ <pre><code class="hljs javascript language-javascript"><span class="hljs-keyword">await</span> cameraEnhancer.open();
548
+ <span class="hljs-keyword">await</span> cvRouter.startCapturing(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>);
549
+ </code></pre>
550
+ <p><em>Note</em>:</p>
551
+ <ul>
552
+ <li><code>cvRouter</code> is engineered to consistently request images from the image source.</li>
553
+ <li>Various preset templates are at your disposal for barcode reading:</li>
554
+ </ul>
555
+ <table>
556
+ <thead>
557
+ <tr>
558
+ <th>Template Name</th>
559
+ <th>Function Description</th>
560
+ </tr>
561
+ </thead>
562
+ <tbody>
563
+ <tr>
564
+ <td><strong>ReadBarcodes_Default</strong></td>
565
+ <td>Scans multiple barcodes by default setting.</td>
566
+ </tr>
567
+ <tr>
568
+ <td><strong>ReadSingleBarcode</strong></td>
569
+ <td>Quickly scans a single barcode.</td>
570
+ </tr>
571
+ <tr>
572
+ <td><strong>ReadBarcodes_SpeedFirst</strong></td>
573
+ <td>Prioritizes speed in scanning multiple barcodes.</td>
574
+ </tr>
575
+ <tr>
576
+ <td><strong>ReadBarcodes_ReadRateFirst</strong></td>
577
+ <td>Maximizes the number of barcodes read.</td>
578
+ </tr>
579
+ <tr>
580
+ <td><strong>ReadBarcodes_Balance</strong></td>
581
+ <td>Balances speed and quantity in reading multiple barcodes.</td>
582
+ </tr>
583
+ <tr>
584
+ <td><strong>ReadDenseBarcodes</strong></td>
585
+ <td>Specialized in reading barcodes with high information density.</td>
586
+ </tr>
587
+ <tr>
588
+ <td><strong>ReadDistantBarcodes</strong></td>
589
+ <td>Capable of reading barcodes from extended distances.</td>
590
+ </tr>
591
+ </tbody>
592
+ </table>
593
+ <p>Read more on the <a href="https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/capture-vision-router/preset-templates.html">preset CaptureVisionTemplates</a>.</p>
594
+ <h2 id="customizing-the-process">Customizing the process</h2>
595
+ <h3 id="1-adjust-the-preset-template-settings">1. Adjust the preset template settings</h3>
596
+ <p>When making adjustments to some basic tasks, we often only need to modify <a href="https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/capture-vision-router/interfaces/simplified-capture-vision-settings.html">SimplifiedCaptureVisionSettings</a>.</p>
597
+ <h4 id="11-change-barcode-settings">1.1. Change barcode settings</h4>
598
+ <p>The preset templates can be updated to meet different requirements. For example, the following code limits the barcode format to QR code.</p>
599
+ <pre><code class="hljs javascript language-javascript"><span class="hljs-keyword">let</span> settings = <span class="hljs-keyword">await</span> cvRouter.getSimplifiedSettings(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>);
600
+ settings.barcodeSettings.barcodeFormatIds = Dynamsoft.DBR.EnumBarcodeFormat.BF_QR_CODE;
601
+ <span class="hljs-keyword">await</span> cvRouter.updateSettings(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>, settings);
602
+ <span class="hljs-keyword">await</span> cvRouter.startCapturing(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>);
603
+ </code></pre>
604
+ <p>For a list of adjustable barcode settings, check out <a href="https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/interfaces/simplified-barcode-reader-settings.html">SimplifiedBarcodeReaderSettings</a> and <a href="https://www.dynamsoft.com/capture-vision/docs/core/enums/barcode-reader/barcode-format.html?lang=js&product=dbr">EnumBarcodeFormat</a>.</p>
605
+ <h4 id="12-retrieve-the-original-image">1.2. Retrieve the original image</h4>
606
+ <p>Additionally, we have the option to modify the template to retrieve the original image containing the barcode.</p>
607
+ <pre><code class="hljs javascript language-javascript"><span class="hljs-keyword">let</span> settings = <span class="hljs-keyword">await</span> cvRouter.getSimplifiedSettings(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>);
608
+ settings.outputOriginalImage = <span class="hljs-literal">true</span>;
609
+ <span class="hljs-keyword">await</span> cvRouter.updateSettings(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>, settings);
610
+ <span class="hljs-keyword">await</span> cvRouter.startCapturing(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>);
611
+ </code></pre>
612
+ <p>Limit the barcode format to QR code, and retrieve the original image containing the barcode, at the same time.</p>
613
+ <pre><code class="hljs javascript language-javascript"><span class="hljs-keyword">let</span> settings = <span class="hljs-keyword">await</span> cvRouter.getSimplifiedSettings(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>);
614
+ settings.outputOriginalImage = <span class="hljs-literal">true</span>;
615
+ settings.barcodeSettings.barcodeFormatIds = Dynamsoft.DBR.EnumBarcodeFormat.BF_QR_CODE;
616
+ <span class="hljs-keyword">await</span> cvRouter.updateSettings(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>, settings);
617
+ <span class="hljs-keyword">await</span> cvRouter.startCapturing(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>);
618
+ </code></pre>
619
+ <p>Please be aware that it is necessary to update the <code>CapturedResultReceiver</code> object to obtain the original image. For instance:</p>
620
+ <pre><code class="hljs javascript language-javascript"><span class="hljs-keyword">const</span> EnumCRIT = Dynamsoft.Core.EnumCapturedResultItemType; <span class="hljs-comment">// Enum for captured result item types.</span>
621
+ <span class="hljs-comment">// Create a result receiver to handle the results.</span>
622
+ <span class="hljs-keyword">await</span> cvRouter.addResultReceiver({
623
+ <span class="hljs-comment">// This function is called when any capture result is received.</span>
624
+ <span class="hljs-attr">onCapturedResultReceived</span>: <span class="hljs-function">(<span class="hljs-params">result</span>) =&gt;</span> {
625
+ <span class="hljs-comment">//Check for barcode results</span>
626
+ <span class="hljs-keyword">let</span> barcodeResultItems = result.items.filter(<span class="hljs-function">(<span class="hljs-params">item</span>) =&gt;</span> item.type === EnumCRIT.CRIT_BARCODE);
627
+ <span class="hljs-keyword">if</span> (barcodeResultItems.length &gt; <span class="hljs-number">0</span>) {
628
+ <span class="hljs-keyword">let</span> image = result.items.filter(<span class="hljs-function">(<span class="hljs-params">item</span>) =&gt;</span> item.type === EnumCRIT.CRIT_ORIGINAL_IMAGE)[<span class="hljs-number">0</span>]?.imageData; <span class="hljs-comment">// Retrieve the original image.</span>
629
+ <span class="hljs-keyword">if</span> (image) <span class="hljs-built_in">document</span>.body.appendChild(image.toCanvas()); <span class="hljs-comment">// Append the image to DOM.</span>
630
+ <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> item <span class="hljs-keyword">of</span> barcodeResultItems) {
631
+ <span class="hljs-comment">// Print each barcode result to the console.</span>
632
+ <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Barcode: <span class="hljs-subst">${item.text}</span>, Format: <span class="hljs-subst">${item.formatString}</span>`</span>);
633
+ }
634
+ }
635
+ },
636
+ });
637
+ </code></pre>
638
+ <h4 id="13-change-reading-frequency-to-save-power">1.3. Change reading frequency to save power</h4>
639
+ <p>The SDK is initially configured to process images sequentially without any breaks. Although this setup maximizes performance, it can lead to elevated power consumption, potentially causing the device to overheat. In many cases, it's possible to reduce the reading speed while still satisfying business requirements. The following code snippet illustrates how to adjust the SDK to process an image every 500 milliseconds:</p>
385
640
  <blockquote>
386
- <p>[!NOTE]<br />
387
- In the Hello World sample, after a successful decoding process, the scanner closes and the user is met with an empty page. In order to open the scanner again, the user must refresh the page. You may choose to implement a more user-friendly behavior in a production environment, such as presenting the user with an option to re-open the Barcode Scanner upon closing it.</p>
388
- <p>[!TIP]<br />
389
- When running performance benchmarks, make sure to disable the console, avoid using <code>console.log()</code>, and run in non-debug mode whenever possible. This ensures that your benchmark results reflect true performance without interference from logging or debugging overhead.</p>
390
- <h2 id="next-steps">Next Steps</h2>
641
+ <p>Please bear in mind that in the following code, if an image's processing time is shorter than 500 milliseconds, the SDK will wait for the full 500 milliseconds before proceeding to process the next image. Conversely, if an image's processing time exceeds 500 milliseconds, the subsequent image will be processed immediately upon completion.</p>
391
642
  </blockquote>
392
- <p>Now that you've implemented the basic functionality, here are some recommended next steps to further explore the capabilities of the Barcode Scanner:</p>
643
+ <pre><code class="hljs javascript language-javascript"><span class="hljs-keyword">let</span> settings = <span class="hljs-keyword">await</span> cvRouter.getSimplifiedSettings(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>);
644
+ settings.minImageCaptureInterval = <span class="hljs-number">500</span>;
645
+ <span class="hljs-keyword">await</span> cvRouter.updateSettings(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>, settings);
646
+ <span class="hljs-keyword">await</span> cvRouter.startCapturing(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>);
647
+ </code></pre>
648
+ <h4 id="14-specify-a-scan-region">1.4. Specify a scan region</h4>
649
+ <p>We can specify a scan region to allow the SDK to process only part of the image, improving processing speed. The code snippet below demonstrates how to do this using the <code>cameraEnhancer</code> image source.</p>
650
+ <pre><code class="hljs javascript language-javascript">cameraEnhancer = <span class="hljs-keyword">await</span> Dynamsoft.DCE.CameraEnhancer.createInstance(cameraView);
651
+ <span class="hljs-comment">// In this example, we set the scan region to cover the central 25% of the image.</span>
652
+ cameraEnhancer.setScanRegion({
653
+ <span class="hljs-attr">x</span>: <span class="hljs-number">25</span>,
654
+ <span class="hljs-attr">y</span>: <span class="hljs-number">25</span>,
655
+ <span class="hljs-attr">width</span>: <span class="hljs-number">50</span>,
656
+ <span class="hljs-attr">height</span>: <span class="hljs-number">50</span>,
657
+ <span class="hljs-attr">isMeasuredInPercentage</span>: <span class="hljs-literal">true</span>,
658
+ });
659
+ </code></pre>
660
+ <p><em>Note</em>:</p>
661
+ <ol>
662
+ <li>By configuring the region at the image source, images are cropped before processing, removing the need to adjust any further processing settings.</li>
663
+ <li><code>cameraEnhancer</code> enhances interactivity by overlaying a mask on the video, clearly marking the scanning region.</li>
664
+ </ol>
665
+ <p><em>See Also</em>:</p>
666
+ <p><a href="https://www.dynamsoft.com/camera-enhancer/docs/web/programming/javascript/api-reference/acquisition.html#setscanregion">CameraEnhancer::setScanRegion</a></p>
667
+ <!-- Since DCE is always used, no need to use this approach
668
+
669
+
670
+ You can use the parameter `roi` (region of interest) together with the parameter `roiMeasuredInPercentage` to configure the SDK to only read a specific region on the image frames. For example, the following code limits the reading in the center 25%( = 50% * 50%) of the image frames:
671
+ <pre><code class="hljs javascript language-javascript"><span class="hljs-keyword">let</span> settings = <span class="hljs-keyword">await</span> cvRouter.getSimplifiedSettings(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>);
672
+ settings.roiMeasuredInPercentage = <span class="hljs-literal">true</span>;
673
+ settings.roi.points = [
674
+ { <span class="hljs-attr">x</span>: <span class="hljs-number">25</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">25</span> },
675
+ { <span class="hljs-attr">x</span>: <span class="hljs-number">75</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">25</span> },
676
+ { <span class="hljs-attr">x</span>: <span class="hljs-number">75</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">75</span> },
677
+ { <span class="hljs-attr">x</span>: <span class="hljs-number">25</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">75</span> },
678
+ ];
679
+ <span class="hljs-keyword">await</span> cvRouter.updateSettings(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>, settings);
680
+ <span class="hljs-keyword">await</span> cvRouter.startCapturing(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>);
681
+ </code></pre> -->
682
+ <!--
683
+ * Specify the maximum time allowed for processing each image
684
+
685
+ You can set the maximum time allowed for processing a single image with the property `timeout`.
686
+
687
+ > Please be aware that the SDK will cease processing an image if its processing time exceeds the duration specified by the `timeout` parameter. It should not be confused with the previously discussed parameter, `minImageCaptureInterval`.
688
+ <pre><code class="hljs javascript language-javascript"><span class="hljs-keyword">let</span> settings = <span class="hljs-keyword">await</span> cvRouter.getSimplifiedSettings(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>);
689
+ settings.timeout = <span class="hljs-number">500</span>;
690
+ <span class="hljs-keyword">await</span> cvRouter.updateSettings(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>, settings);
691
+ <span class="hljs-keyword">await</span> cvRouter.startCapturing(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>);
692
+ </code></pre>
693
+ -->
694
+ <h3 id="2-edit-the-preset-templates-directly">2. Edit the preset templates directly</h3>
695
+ <p>The preset templates have many more settings that can be customized to suit your use case best. If you <a href="https://www.dynamsoft.com/barcode-reader/downloads/1000003-confirmation/">download the SDK from Dynamsoft website</a>, you can find the templates under</p>
696
+ <ul>
697
+ <li>"/dynamsoft-barcode-reader-js-11.4.2000/dist/templates/"</li>
698
+ </ul>
699
+ <p>Upon completing the template editing, you can invoke the <code>initSettings</code> method and provide it with the template path as an argument.</p>
700
+ <pre><code class="hljs javascript language-javascript"><span class="hljs-keyword">await</span> cvRouter.initSettings(<span class="hljs-string">&quot;PATH-TO-THE-FILE&quot;</span>); <span class="hljs-comment">// E.g. &quot;https://your-website/ReadSingleBarcode.json&quot;)</span>
701
+ <span class="hljs-keyword">await</span> cvRouter.startCapturing(<span class="hljs-string">&quot;ReadSingleBarcode&quot;</span>); <span class="hljs-comment">// Make sure the name matches one of the CaptureVisionTemplates in the template JSON file.</span>
702
+ </code></pre>
703
+ <h3 id="3-important-filter-the-results">3. [Important] Filter the results</h3>
704
+ <p>When processing video frames, the same barcode is often detected multiple times. To improve the user experience, we can use the <a href="https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/utility/multi-frame-result-cross-filter.html">MultiFrameResultCrossFilter</a> object. This object provides two methods for handling duplicate detections, which can be used independently or together, depending on what best suits your application needs:</p>
705
+ <h4 id="method-1-verify-results-across-multiple-frames">Method 1: Verify results across multiple frames</h4>
706
+ <pre><code class="hljs js language-js"><span class="hljs-keyword">let</span> filter = <span class="hljs-keyword">new</span> Dynamsoft.Utility.MultiFrameResultCrossFilter();
707
+ filter.enableResultCrossVerification(<span class="hljs-string">&quot;barcode&quot;</span>, <span class="hljs-literal">true</span>);
708
+ <span class="hljs-keyword">await</span> cvRouter.addResultFilter(filter);
709
+ </code></pre>
710
+ <p><em>Note</em>:</p>
711
+ <ul>
712
+ <li><code>enableResultCrossVerification</code> was designed to cross-validate the outcomes across various frames in a video streaming scenario, enhancing the reliability of the final results. This validation is particularly crucial for barcodes with limited error correction capabilities, such as 1D codes.</li>
713
+ </ul>
714
+ <h4 id="method-2-eliminate-redundant-results-detected-within-a-short-time-frame">Method 2: Eliminate redundant results detected within a short time frame</h4>
715
+ <pre><code class="hljs js language-js"><span class="hljs-keyword">let</span> filter = <span class="hljs-keyword">new</span> Dynamsoft.Utility.MultiFrameResultCrossFilter();
716
+ filter.enableResultDeduplication(<span class="hljs-string">&quot;barcode&quot;</span>, <span class="hljs-literal">true</span>);
717
+ <span class="hljs-keyword">await</span> cvRouter.addResultFilter(filter);
718
+ </code></pre>
719
+ <p><em>Note</em>:</p>
720
+ <ul>
721
+ <li><code>enableResultDeduplication</code> was designed to prevent high usage in video streaming scenarios, addressing the repetitive processing of the same code within a short period of time.</li>
722
+ </ul>
723
+ <p>Initially, the filter is set to forget a result 3 seconds after it is first received. During this time frame, if an identical result appears, it is ignored.</p>
724
+ <blockquote>
725
+ <p>It's important to know that in version 9.x or earlier, the occurrence of an identical result would reset the timer, thus reinitiating the 3-second count at that point. However, in version 10.2.10 and later, an identical result no longer resets the timer but is instead disregarded, and the duration count continues uninterrupted.</p>
726
+ </blockquote>
727
+ <p>Under certain circumstances, this duration can be extended with the method <code>setDuplicateForgetTime()</code>.</p>
728
+ <pre><code class="hljs js language-js"><span class="hljs-keyword">let</span> filter = <span class="hljs-keyword">new</span> Dynamsoft.Utility.MultiFrameResultCrossFilter();
729
+ filter.setDuplicateForgetTime(<span class="hljs-string">&quot;barcode&quot;</span>, <span class="hljs-number">5000</span>); <span class="hljs-comment">// Extend the duration to 5 seconds.</span>
730
+ <span class="hljs-keyword">await</span> cvRouter.addResultFilter(filter);
731
+ </code></pre>
732
+ <p>You can also enable both options at the same time:</p>
733
+ <pre><code class="hljs js language-js"><span class="hljs-keyword">let</span> filter = <span class="hljs-keyword">new</span> Dynamsoft.Utility.MultiFrameResultCrossFilter();
734
+ filter.enableResultCrossVerification(<span class="hljs-string">&quot;barcode&quot;</span>, <span class="hljs-literal">true</span>);
735
+ filter.enableResultDeduplication(<span class="hljs-string">&quot;barcode&quot;</span>, <span class="hljs-literal">true</span>);
736
+ filter.setDuplicateForgetTime(<span class="hljs-string">&quot;barcode&quot;</span>, <span class="hljs-number">5000</span>);
737
+ <span class="hljs-keyword">await</span> cvRouter.addResultFilter(filter);
738
+ </code></pre>
739
+ <h3 id="4-add-feedback">4. Add feedback</h3>
740
+ <p>When a barcode is detected within the video stream, its position is immediately displayed within the video. Furthermore, utilizing the "Dynamsoft Camera Enhancer" SDK, we can introduce feedback mechanisms, such as emitting a "beep" sound or triggering a "vibration".</p>
741
+ <p>The following code snippet adds a "beep" sound for when a barcode is found:</p>
742
+ <pre><code class="hljs js language-js"><span class="hljs-keyword">const</span> resultReceiver = <span class="hljs-keyword">new</span> Dynamsoft.CVR.CapturedResultReceiver();
743
+ resultReceiver.onDecodedBarcodesReceived = <span class="hljs-function">(<span class="hljs-params">result</span>) =&gt;</span> {
744
+ <span class="hljs-keyword">if</span> (result.barcodeResultItems.length &gt; <span class="hljs-number">0</span>) {
745
+ Dynamsoft.DCE.Feedback.beep();
746
+ }
747
+ };
748
+ <span class="hljs-keyword">await</span> cvRouter.addResultReceiver(resultReceiver);
749
+ </code></pre>
750
+ <h2 id="customizing-the-ui">Customizing the UI</h2>
751
+ <pre><code class="hljs javascript language-javascript"><span class="hljs-comment">// Create a CameraView instance with default settings</span>
752
+ <span class="hljs-keyword">let</span> cameraView = <span class="hljs-keyword">await</span> Dynamsoft.DCE.CameraView.createInstance();
753
+ <span class="hljs-comment">// Create a CameraView instance with a specified XML file path, typically a local or remote URL</span>
754
+ <span class="hljs-keyword">let</span> cameraView1 = <span class="hljs-keyword">await</span> Dynamsoft.DCE.CameraView.createInstance(<span class="hljs-string">&#x27;@engineResourcePath/dce.ui.v5.xml&#x27;</span>);
755
+ <span class="hljs-comment">// Create a CameraView instance within a specified DOM element</span>
756
+ <span class="hljs-keyword">let</span> cameraView2 = <span class="hljs-keyword">await</span> Dynamsoft.DCE.CameraView.createInstance(<span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">&#x27;my-ui&#x27;</span>));
757
+ <span class="hljs-comment">// Create a CameraView instance using a custom UI file path</span>
758
+ <span class="hljs-keyword">let</span> cameraView3 = <span class="hljs-keyword">await</span> Dynamsoft.DCE.CameraView.createInstance(<span class="hljs-string">&#x27;url/to/my/ui.xml&#x27;</span>);
759
+
760
+ <span class="hljs-comment">// Get the UI element associated with the cameraView instance</span>
761
+ <span class="hljs-keyword">let</span> uiElement = cameraView.getUIElement();
762
+ <span class="hljs-comment">// Remove the camera selection dropdown from the CameraView&#x27;s UI element</span>
763
+ uiElement.querySelector(<span class="hljs-string">&#x27;.dce-sel-camera&#x27;</span>).remove();
764
+ <span class="hljs-comment">// Remove the resolution selection dropdown from the CameraView&#x27;s UI element</span>
765
+ uiElement.querySelector(<span class="hljs-string">&#x27;.dce-sel-resolution&#x27;</span>).remove();
766
+ </code></pre>
767
+ <p>The UI is part of the auxiliary SDK "Dynamsoft Camera Enhancer", read more on how to <a href="https://www.dynamsoft.com/barcode-reader/docs/core/programming/features/ui-customization-js.html?lang=js">customize the UI</a>.</p>
768
+ <h2 id="documentation">Documentation</h2>
769
+ <h3 id="api-reference">API Reference</h3>
770
+ <p>You can check out the detailed documentation about the APIs of the SDK at<br />
771
+ <a href="https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/?ver=11.4.2000">https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/?ver=11.4.2000</a>.</p>
772
+ <!-- Compatibility is basically not an issue. Pls remove to another place
773
+
774
+ ## System Requirements
775
+
776
+ DBR requires the following features to work:
777
+
778
+ - Secure context (HTTPS deployment)
779
+
780
+ When deploying your application / website for production, make sure to serve it via a secure HTTPS connection. This is required for two reasons
781
+
782
+ - Access to the camera video stream is only granted in a security context. Most browsers impose this restriction.
783
+ > Some browsers like Chrome may grant the access for `http://127.0.0.1` and `http://localhost` or even for pages opened directly from the local disk (`file:///...`). This can be helpful for temporary development and test.
784
+
785
+ - Dynamsoft License requires a secure context to work.
786
+
787
+ - `WebAssembly`, `Blob`, `URL`/`createObjectURL`, `Web Workers`
788
+
789
+ The above four features are required for the SDK to work.
790
+
791
+ - `MediaDevices`/`getUserMedia`
792
+
793
+ This API is required for in-browser video streaming.
794
+
795
+ - `getSettings`
796
+
797
+ This API inspects the video input which is a `MediaStreamTrack` object about its constrainable properties.
798
+
799
+ The following table is a list of supported browsers based on the above requirements:
800
+
801
+ | Browser Name | Version |
802
+ | :----------: | :--------------: |
803
+ | Chrome | v88+<sup>1</sup> |
804
+ | Firefox | v68+<sup>1</sup> |
805
+ | Edge | v79+ |
806
+ | Safari | v14+ |
807
+
808
+ <sup>1</sup> devices running iOS needs to be on iOS 14.3+ for camera video streaming to work in Chrome, Firefox or other Apps using webviews.
809
+
810
+ 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.
811
+
812
+ -->
813
+ <h3 id="how-to-upgrade">How to Upgrade</h3>
814
+ <p>If you want to upgrade the SDK from an old version to a newer one, please see <a href="https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/migrate-from-v10/index.html">how to upgrade</a>.</p>
815
+ <h3 id="release-notes">Release Notes</h3>
816
+ <p>Learn about what are included in each release at <a href="https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/release-notes/index.html">https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/release-notes/index.html</a>.</p>
817
+ <h2 id="next-steps">Next Steps</h2>
818
+ <p>Now that you have got the SDK integrated, you can choose to move forward in the following directions</p>
393
819
  <ol>
394
- <li>Learn how to <a href="https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/user-guide/barcode-scanner-customization.html">Customize the Barcode Scanner</a></li>
395
- <li>Check out the <a href="https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/samples-demos/index.html?ver=11.2.4000">Official Samples and Demo</a></li>
396
- <li>Learn about the <a href="https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/barcode-scanner.html?ver=11.2.4000">APIs of BarcodeScanner</a></li>
820
+ <li>Learn how to <a href="https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/user-guide/use-in-framework.html">Use in Framework</a></li>
821
+ <li>Check out the <a href="https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/samples-demos/index.html">Official Samples and Demo</a></li>
822
+ <li>Learn about the <a href="https://www.dynamsoft.com/barcode-reader/docs/web/programming/javascript/api-reference/index.html">APIs of the SDK</a></li>
397
823
  </ol>
398
824
  </div>
399
825
  </body>