react-qr-barcode-scanner 1.0.6 → 2.0.1
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 +13 -1
- package/package.json +13 -13
- package/dist/BarcodeScannerComponent.d.ts +0 -14
- package/dist/BarcodeScannerComponent.js +0 -72
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -7
package/README.md
CHANGED
|
@@ -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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-qr-barcode-scanner",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
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": "^19.0.2",
|
|
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.24.0",
|
|
45
|
+
"@typescript-eslint/parser": "^8.24.0",
|
|
46
|
+
"eslint": "^9.20.1",
|
|
47
|
+
"eslint-plugin-react": "^7.37.3",
|
|
48
|
+
"typescript": "^5.7.2"
|
|
49
49
|
}
|
|
50
|
-
}
|
|
50
|
+
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Result } from "@zxing/library";
|
|
3
|
-
declare const BarcodeScannerComponent: ({ onUpdate, onError, width, height, facingMode, torch, delay, videoConstraints, stopStream, }: {
|
|
4
|
-
onUpdate: (arg0: unknown, arg1?: Result) => void;
|
|
5
|
-
onError?: (arg0: string | DOMException) => void;
|
|
6
|
-
width?: number | string;
|
|
7
|
-
height?: number | string;
|
|
8
|
-
facingMode?: "environment" | "user";
|
|
9
|
-
torch?: boolean;
|
|
10
|
-
delay?: number;
|
|
11
|
-
videoConstraints?: MediaTrackConstraints;
|
|
12
|
-
stopStream?: boolean;
|
|
13
|
-
}) => React.ReactElement;
|
|
14
|
-
export default BarcodeScannerComponent;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const library_1 = require("@zxing/library");
|
|
8
|
-
const react_webcam_1 = __importDefault(require("react-webcam"));
|
|
9
|
-
const BarcodeScannerComponent = ({ onUpdate, onError, width = "100%", height = "100%", facingMode = "environment", torch, delay = 500, videoConstraints, stopStream, }) => {
|
|
10
|
-
const webcamRef = react_1.default.useRef(null);
|
|
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();
|
|
15
|
-
if (imageSrc) {
|
|
16
|
-
codeReader
|
|
17
|
-
.decodeFromImage(undefined, imageSrc)
|
|
18
|
-
.then((result) => {
|
|
19
|
-
onUpdate(null, result);
|
|
20
|
-
})
|
|
21
|
-
.catch((err) => {
|
|
22
|
-
onUpdate(err);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}, [onUpdate]);
|
|
26
|
-
react_1.default.useEffect(() => {
|
|
27
|
-
var _a, _b;
|
|
28
|
-
// Turn on the flashlight if prop is defined and device has the capability
|
|
29
|
-
if (typeof torch === "boolean" && ((_a =
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
navigator === null ||
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
navigator === void 0 ? void 0 :
|
|
34
|
-
// @ts-ignore
|
|
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
|
|
38
|
-
if (track &&
|
|
39
|
-
track.getCapabilities().torch &&
|
|
40
|
-
!track.getConstraints().torch) {
|
|
41
|
-
track
|
|
42
|
-
.applyConstraints({
|
|
43
|
-
advanced: [{ torch }],
|
|
44
|
-
})
|
|
45
|
-
.catch((err) => onUpdate(err));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}, [torch, onUpdate]);
|
|
49
|
-
react_1.default.useEffect(() => {
|
|
50
|
-
var _a;
|
|
51
|
-
if (stopStream) {
|
|
52
|
-
let stream = (_a = webcamRef === null || webcamRef === void 0 ? void 0 : webcamRef.current) === null || _a === void 0 ? void 0 : _a.video.srcObject;
|
|
53
|
-
if (stream) {
|
|
54
|
-
stream.getTracks().forEach((track) => {
|
|
55
|
-
stream.removeTrack(track);
|
|
56
|
-
track.stop();
|
|
57
|
-
});
|
|
58
|
-
stream = null;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}, [stopStream]);
|
|
62
|
-
react_1.default.useEffect(() => {
|
|
63
|
-
const interval = setInterval(capture, delay);
|
|
64
|
-
return () => {
|
|
65
|
-
clearInterval(interval);
|
|
66
|
-
};
|
|
67
|
-
}, []);
|
|
68
|
-
return (react_1.default.createElement(react_webcam_1.default, { width: width, height: height, ref: webcamRef, screenshotFormat: "image/jpeg", videoConstraints: videoConstraints || {
|
|
69
|
-
facingMode,
|
|
70
|
-
}, audio: false, onUserMediaError: onError }));
|
|
71
|
-
};
|
|
72
|
-
exports.default = BarcodeScannerComponent;
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
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;
|