react-qr-barcode-scanner 2.0.0 → 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/package.json +8 -8
- package/dist/BarcodeScannerComponent.d.ts +0 -14
- package/dist/BarcodeScannerComponent.js +0 -64
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-qr-barcode-scanner",
|
|
3
|
-
"version": "2.0.
|
|
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",
|
|
@@ -36,15 +36,15 @@
|
|
|
36
36
|
"react-dom": "^18.2.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@types/react": "^
|
|
39
|
+
"@types/react": "^19.0.2",
|
|
40
40
|
"@zxing/library": "^0.21.3",
|
|
41
41
|
"react-webcam": "^7.1.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
45
|
-
"@typescript-eslint/parser": "^8.
|
|
46
|
-
"eslint": "^9.
|
|
47
|
-
"eslint-plugin-react": "^7.
|
|
48
|
-
"typescript": "^5.
|
|
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
|
-
export 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,64 +0,0 @@
|
|
|
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();
|
|
11
|
-
if (imageSrc) {
|
|
12
|
-
codeReader
|
|
13
|
-
.decodeFromImage(undefined, imageSrc)
|
|
14
|
-
.then((result) => {
|
|
15
|
-
onUpdate(null, result);
|
|
16
|
-
})
|
|
17
|
-
.catch((err) => {
|
|
18
|
-
onUpdate(err);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}, [onUpdate]);
|
|
22
|
-
React.useEffect(() => {
|
|
23
|
-
// Turn on the flashlight if prop is defined and device has the capability
|
|
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
|
|
30
|
-
if (track &&
|
|
31
|
-
track.getCapabilities().torch &&
|
|
32
|
-
!track.getConstraints().torch) {
|
|
33
|
-
track
|
|
34
|
-
.applyConstraints({
|
|
35
|
-
advanced: [{ torch }],
|
|
36
|
-
})
|
|
37
|
-
.catch((err) => onUpdate(err));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}, [torch, onUpdate]);
|
|
41
|
-
React.useEffect(() => {
|
|
42
|
-
if (stopStream) {
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
let stream = webcamRef?.current?.video.srcObject;
|
|
45
|
-
if (stream) {
|
|
46
|
-
stream.getTracks().forEach((track) => {
|
|
47
|
-
stream.removeTrack(track);
|
|
48
|
-
track.stop();
|
|
49
|
-
});
|
|
50
|
-
stream = null;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}, [stopStream]);
|
|
54
|
-
React.useEffect(() => {
|
|
55
|
-
const interval = setInterval(capture, delay);
|
|
56
|
-
return () => {
|
|
57
|
-
clearInterval(interval);
|
|
58
|
-
};
|
|
59
|
-
}, []);
|
|
60
|
-
return (_jsx(Webcam, { width: width, height: height, ref: webcamRef, screenshotFormat: "image/jpeg", videoConstraints: videoConstraints || {
|
|
61
|
-
facingMode,
|
|
62
|
-
}, audio: false, onUserMediaError: onError }));
|
|
63
|
-
};
|
|
64
|
-
export default BarcodeScannerComponent;
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED