Skip to content

Commit

Permalink
Create V2.2.1 version (#457)
Browse files Browse the repository at this point in the history
* Add version 2.2.1 with some refactors to code

Change log.

### Version 2.2.1
 - Added support for `supportedScanType` in `Html5QrcodeScanner`. This feature
    was implemented by our latest contributor - [mohsinaav@](https://github.com/mohsinaav)

   Now users can decide to only use camera based scan or file based scan or use
   them in different order. How to use:

   ```js
    function onScanSuccess(decodedText, decodedResult) {
        // handle the scanned code as you like, for example:
        console.log(`Code matched = ${decodedText}`, decodedResult);
    }

    let config = {
        fps: 10,
        qrbox: {width: 100, height: 100},
        rememberLastUsedCamera: true,
        // Only support camera scan type.
        supportedScanTypes: [Html5QrcodeScanType.SCAN_TYPE_CAMERA]
    };

    let html5QrcodeScanner = new Html5QrcodeScanner(
        "reader", config, /* verbose= */ false);
    html5QrcodeScanner.render(onScanSuccess);
   ```

   For file based scan only choose:
   ```js
   supportedScanTypes: [Html5QrcodeScanType.SCAN_TYPE_FILE]
   ```

   For supporting both as it is today, you can ignore this field or set as:
   ```js
   supportedScanTypes: [
       Html5QrcodeScanType.SCAN_TYPE_CAMERA,
        Html5QrcodeScanType.SCAN_TYPE_FILE]
   ```

   To set the file based scan as defult change the order:
   ```js
      supportedScanTypes: [
        Html5QrcodeScanType.SCAN_TYPE_FILE,
        Html5QrcodeScanType.SCAN_TYPE_CAMERA]
   ```

* Add test for ScanTypeSelector

* Codacy fixes
  • Loading branch information
mebjas authored Apr 7, 2022
1 parent d225934 commit ced1209
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 107 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ package-lock.json
.vscode/
dist/
src/*.d.ts
src/*/*.d.ts
src/*/*/*.d.ts
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,23 @@ interface Html5QrcodeScannerConfig
* start for previously used camera.
*/
rememberLastUsedCamera?: boolean | undefined;

/**
* Sets the desired scan types to be supported in the scanner.
*
* - Not setting a value will follow the default order supported by
* library.
* - First value would be used as the default value. Example:
* - [SCAN_TYPE_CAMERA, SCAN_TYPE_FILE]: Camera will be default type,
* user can switch to file based scan.
* - [SCAN_TYPE_FILE, SCAN_TYPE_CAMERA]: File based scan will be default
* type, user can switch to camera based scan.
* - Setting only value will disable option to switch to other. Example:
* - [SCAN_TYPE_CAMERA] - Only camera based scan supported.
* - [SCAN_TYPE_FILE] - Only file based scan supported.
* - Setting wrong values or multiple values will fail.
*/
supportedScanTypes: Array<Html5QrcodeScanType> | [];
};

class Html5Qrcode {
Expand Down Expand Up @@ -731,6 +748,53 @@ If `true` the library shall remember if the camera permissions were previously
granted and what camera was last used. If the permissions is already granted for
"camera", QR code scanning will automatically * start for previously used camera.

#### `supportedScanTypes` - `Array<Html5QrcodeScanType> | []`
Default = `[Html5QrcodeScanType.SCAN_TYPE_CAMERA, Html5QrcodeScanType.SCAN_TYPE_FILE]`

This field can be used to:
- Limit support to either of `Camera` or `File` based scan.
- Change default scan type.

How to use:

```js
function onScanSuccess(decodedText, decodedResult) {
// handle the scanned code as you like, for example:
console.log(`Code matched = ${decodedText}`, decodedResult);
}

let config = {
fps: 10,
qrbox: {width: 100, height: 100},
rememberLastUsedCamera: true,
// Only support camera scan type.
supportedScanTypes: [Html5QrcodeScanType.SCAN_TYPE_CAMERA]
};

let html5QrcodeScanner = new Html5QrcodeScanner(
"reader", config, /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess);
```

For file based scan only choose:
```js
supportedScanTypes: [Html5QrcodeScanType.SCAN_TYPE_FILE]
```

For supporting both as it is today, you can ignore this field or set as:
```js
supportedScanTypes: [
Html5QrcodeScanType.SCAN_TYPE_CAMERA,
Html5QrcodeScanType.SCAN_TYPE_FILE]
```

To set the file based scan as defult change the order:
```js
supportedScanTypes: [
Html5QrcodeScanType.SCAN_TYPE_FILE,
Html5QrcodeScanType.SCAN_TYPE_CAMERA]
```

### Scanning only specific formats
By default, both camera stream and image files are scanned against all the
supported code formats. Both `Html5QrcodeScanner` and `Html5Qrcode` classes can
Expand Down
46 changes: 46 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
### Version 2.2.1
- Added support for `supportedScanType` in `Html5QrcodeScanner`. This feature
was implemented by our latest contributor - [mohsinaav@](https://github.com/mohsinaav)

Now users can decide to only use camera based scan or file based scan or use
them in different order. How to use:


```js
function onScanSuccess(decodedText, decodedResult) {
// handle the scanned code as you like, for example:
console.log(`Code matched = ${decodedText}`, decodedResult);
}

let config = {
fps: 10,
qrbox: {width: 100, height: 100},
rememberLastUsedCamera: true,
// Only support camera scan type.
supportedScanTypes: [Html5QrcodeScanType.SCAN_TYPE_CAMERA]
};

let html5QrcodeScanner = new Html5QrcodeScanner(
"reader", config, /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess);
```

For file based scan only choose:
```js
supportedScanTypes: [Html5QrcodeScanType.SCAN_TYPE_FILE]
```

For supporting both as it is today, you can ignore this field or set as:
```js
supportedScanTypes: [
Html5QrcodeScanType.SCAN_TYPE_CAMERA,
Html5QrcodeScanType.SCAN_TYPE_FILE]
```

To set the file based scan as defult change the order:
```js
supportedScanTypes: [
Html5QrcodeScanType.SCAN_TYPE_FILE,
Html5QrcodeScanType.SCAN_TYPE_CAMERA]
```

### Version 2.2.0
- `config.qrbox` now supports consuming function of type

Expand Down
24 changes: 17 additions & 7 deletions minified/html5-qrcode.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html5-qrcode",
"version": "2.2.0",
"version": "2.2.1",
"description": "A cross platform HTML5 QR Code & bar code scanner",
"main": "./cjs/index.js",
"module": "./esm/index.js",
Expand Down
22 changes: 16 additions & 6 deletions scripts/webpack_append_data.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
/** Append the libary components to globals for backwards compatibility. */
if (window && !Html5QrcodeScanner) {
var Html5QrcodeScanner = window.__Html5QrcodeLibrary__.Html5QrcodeScanner;
var Html5Qrcode = window.__Html5QrcodeLibrary__.Html5Qrcode;
var Html5QrcodeSupportedFormats = window.__Html5QrcodeLibrary__.Html5QrcodeSupportedFormats
var Html5QrcodeScannerState = window.__Html5QrcodeLibrary__.Html5QrcodeScannerState;
var Html5QrcodeScanType = window.__Html5QrcodeLibrary__.Html5QrcodeScanType;
if (window) {
if (!Html5QrcodeScanner) {
var Html5QrcodeScanner = window.__Html5QrcodeLibrary__.Html5QrcodeScanner;
}
if (!Html5Qrcode) {
var Html5Qrcode = window.__Html5QrcodeLibrary__.Html5Qrcode;
}
if (!Html5QrcodeSupportedFormats) {
var Html5QrcodeSupportedFormats = window.__Html5QrcodeLibrary__.Html5QrcodeSupportedFormats
}
if (!Html5QrcodeScannerState) {
var Html5QrcodeScannerState = window.__Html5QrcodeLibrary__.Html5QrcodeScannerState;
}
if (!Html5QrcodeScanType) {
var Html5QrcodeScanType = window.__Html5QrcodeLibrary__.Html5QrcodeScanType;
}
}
3 changes: 2 additions & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export class Html5QrcodeConstants {
static SCAN_DEFAULT_FPS = 2;
static DEFAULT_DISABLE_FLIP = false;
static DEFAULT_REMEMBER_LAST_CAMERA_USED = true;
static DEFAULT_SUPPORTED_SCAN_TYPE = [Html5QrcodeScanType.SCAN_TYPE_CAMERA,
static DEFAULT_SUPPORTED_SCAN_TYPE = [
Html5QrcodeScanType.SCAN_TYPE_CAMERA,
Html5QrcodeScanType.SCAN_TYPE_FILE];
}

Expand Down
Loading

0 comments on commit ced1209

Please sign in to comment.