react-qr-barcode-scanner 1.0.5 → 2.0.0
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.
- package/README.md +14 -2
- package/dist/BarcodeScannerComponent.d.ts +1 -1
- package/dist/BarcodeScannerComponent.js +23 -31
- package/dist/index.js +2 -7
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# React
|
|
1
|
+
# React QR Barcode Scanner
|
|
2
2
|
|
|
3
3
|
This is a simple React component built in Typescript to provide a webcam-based barcode scanner using [react-webcam](https://github.com/mozmorris/react-webcam) and [@zxing/library](https://github.com/zxing-js/library). This component works on Computers and Mobile Devices (iOS 11 and above and Android Phones).
|
|
4
4
|
|
|
@@ -10,6 +10,9 @@ Thanks to the initial repo: https://github.com/dashboardphilippines/react-webcam
|
|
|
10
10
|
npm i react-qr-barcode-scanner
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
## Demo
|
|
14
|
+
Try a demo of the scanner [here](https://jamenamcinteer.github.io/react-qr-barcode-scanner/).
|
|
15
|
+
|
|
13
16
|
## Usage in React:
|
|
14
17
|
|
|
15
18
|
```jsx
|
|
@@ -43,7 +46,7 @@ export default App;
|
|
|
43
46
|
|
|
44
47
|
Type: `function`, Required, Argument: `error`, `result`
|
|
45
48
|
|
|
46
|
-
Function that returns the result for every captured frame. Text from barcode can be accessed from `result.
|
|
49
|
+
Function that returns the result for every captured frame. Text from barcode can be accessed from `result.getText()` if there is a result.
|
|
47
50
|
|
|
48
51
|
### onError
|
|
49
52
|
|
|
@@ -126,3 +129,12 @@ These formats are supported by ZXing:
|
|
|
126
129
|
<button onClick={dismissQrReader}>
|
|
127
130
|
</Modal>
|
|
128
131
|
```
|
|
132
|
+
|
|
133
|
+
## Contributing
|
|
134
|
+
We welcome contributions to react-qr-barcode-scanner.
|
|
135
|
+
|
|
136
|
+
If you have an idea for a new feature or have discovered a bug, please open an issue.
|
|
137
|
+
|
|
138
|
+
Please `yarn build` in the root and `docs_src` directories before pushing changes.
|
|
139
|
+
|
|
140
|
+
Don't forget to add a title and a description explaining the issue you're trying to solve and your proposed solution.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Result } from "@zxing/library";
|
|
3
|
-
declare const BarcodeScannerComponent: ({ onUpdate, onError, width, height, facingMode, torch, delay, videoConstraints, stopStream, }: {
|
|
3
|
+
export declare const BarcodeScannerComponent: ({ onUpdate, onError, width, height, facingMode, torch, delay, videoConstraints, stopStream, }: {
|
|
4
4
|
onUpdate: (arg0: unknown, arg1?: Result) => void;
|
|
5
5
|
onError?: (arg0: string | DOMException) => void;
|
|
6
6
|
width?: number | string;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const capture = react_1.default.useCallback(() => {
|
|
12
|
-
var _a;
|
|
13
|
-
const codeReader = new library_1.BrowserMultiFormatReader();
|
|
14
|
-
const imageSrc = (_a = webcamRef === null || webcamRef === void 0 ? void 0 : webcamRef.current) === null || _a === void 0 ? void 0 : _a.getScreenshot();
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { BrowserMultiFormatReader } from "@zxing/library";
|
|
4
|
+
import Webcam from "react-webcam";
|
|
5
|
+
export const BarcodeScannerComponent = ({ onUpdate, onError, width = "100%", height = "100%", facingMode = "environment", torch, delay = 500, videoConstraints, stopStream, }) => {
|
|
6
|
+
const webcamRef = React.useRef(null);
|
|
7
|
+
const capture = React.useCallback(() => {
|
|
8
|
+
const codeReader = new BrowserMultiFormatReader();
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
const imageSrc = webcamRef?.current?.getScreenshot();
|
|
15
11
|
if (imageSrc) {
|
|
16
12
|
codeReader
|
|
17
13
|
.decodeFromImage(undefined, imageSrc)
|
|
@@ -23,18 +19,14 @@ const BarcodeScannerComponent = ({ onUpdate, onError, width = "100%", height = "
|
|
|
23
19
|
});
|
|
24
20
|
}
|
|
25
21
|
}, [onUpdate]);
|
|
26
|
-
|
|
27
|
-
var _a, _b;
|
|
22
|
+
React.useEffect(() => {
|
|
28
23
|
// Turn on the flashlight if prop is defined and device has the capability
|
|
29
|
-
if (typeof torch === "boolean" &&
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getSupportedConstraints().torch)) {
|
|
36
|
-
const stream = (_b = webcamRef === null || webcamRef === void 0 ? void 0 : webcamRef.current) === null || _b === void 0 ? void 0 : _b.video.srcObject;
|
|
37
|
-
const track = stream === null || stream === void 0 ? void 0 : stream.getVideoTracks()[0]; // get the active track of the stream
|
|
24
|
+
if (typeof torch === "boolean" &&
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
navigator?.mediaDevices?.getSupportedConstraints().torch) {
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
const stream = webcamRef?.current?.video.srcObject;
|
|
29
|
+
const track = stream?.getVideoTracks()[0]; // get the active track of the stream
|
|
38
30
|
if (track &&
|
|
39
31
|
track.getCapabilities().torch &&
|
|
40
32
|
!track.getConstraints().torch) {
|
|
@@ -46,10 +38,10 @@ const BarcodeScannerComponent = ({ onUpdate, onError, width = "100%", height = "
|
|
|
46
38
|
}
|
|
47
39
|
}
|
|
48
40
|
}, [torch, onUpdate]);
|
|
49
|
-
|
|
50
|
-
var _a;
|
|
41
|
+
React.useEffect(() => {
|
|
51
42
|
if (stopStream) {
|
|
52
|
-
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
let stream = webcamRef?.current?.video.srcObject;
|
|
53
45
|
if (stream) {
|
|
54
46
|
stream.getTracks().forEach((track) => {
|
|
55
47
|
stream.removeTrack(track);
|
|
@@ -59,14 +51,14 @@ const BarcodeScannerComponent = ({ onUpdate, onError, width = "100%", height = "
|
|
|
59
51
|
}
|
|
60
52
|
}
|
|
61
53
|
}, [stopStream]);
|
|
62
|
-
|
|
54
|
+
React.useEffect(() => {
|
|
63
55
|
const interval = setInterval(capture, delay);
|
|
64
56
|
return () => {
|
|
65
57
|
clearInterval(interval);
|
|
66
58
|
};
|
|
67
59
|
}, []);
|
|
68
|
-
return (
|
|
60
|
+
return (_jsx(Webcam, { width: width, height: height, ref: webcamRef, screenshotFormat: "image/jpeg", videoConstraints: videoConstraints || {
|
|
69
61
|
facingMode,
|
|
70
62
|
}, audio: false, onUserMediaError: onError }));
|
|
71
63
|
};
|
|
72
|
-
|
|
64
|
+
export default BarcodeScannerComponent;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const BarcodeScannerComponent_1 = __importDefault(require("./BarcodeScannerComponent"));
|
|
7
|
-
exports.default = BarcodeScannerComponent_1.default;
|
|
1
|
+
import BarcodeScannerComponent from './BarcodeScannerComponent';
|
|
2
|
+
export default BarcodeScannerComponent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-qr-barcode-scanner",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A simple React Component using the client's webcam to read barcodes and QR codes.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
12
|
"lint": "eslint ./src --ext .js,.jsx,.ts,.tsx --fix",
|
|
13
|
-
"build": "rm -rf dist && tsc --build tsconfig.json",
|
|
13
|
+
"build": "rm -rf dist && tsc --build tsconfig.json --declaration",
|
|
14
14
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
@@ -32,19 +32,19 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://github.com/jamenamcinteer/react-qr-barcode-scanner#readme",
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"react": "^
|
|
36
|
-
"react-dom": "^
|
|
35
|
+
"react": "^18.2.0",
|
|
36
|
+
"react-dom": "^18.2.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@types/react": "^
|
|
40
|
-
"@zxing/library": "^0.
|
|
41
|
-
"react-webcam": "^
|
|
39
|
+
"@types/react": "^18.2.0",
|
|
40
|
+
"@zxing/library": "^0.21.3",
|
|
41
|
+
"react-webcam": "^7.1.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
45
|
-
"@typescript-eslint/parser": "^
|
|
46
|
-
"eslint": "^
|
|
47
|
-
"eslint-plugin-react": "^7.
|
|
48
|
-
"typescript": "^
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^8.8.0",
|
|
45
|
+
"@typescript-eslint/parser": "^8.8.0",
|
|
46
|
+
"eslint": "^9.12.0",
|
|
47
|
+
"eslint-plugin-react": "^7.33.2",
|
|
48
|
+
"typescript": "^5.2.2"
|
|
49
49
|
}
|
|
50
50
|
}
|