-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a1b6d2
commit 30a510a
Showing
7 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
node_modules | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from "react"; | ||
import { Result } from "@zxing/library"; | ||
declare const BarcodeScannerComponent: ({ onUpdate, width, height, facingMode, delay, videoConstraints, }: { | ||
onUpdate: (arg0: unknown, arg1?: Result) => void; | ||
width?: number | string; | ||
height?: number | string; | ||
facingMode?: "environment" | "user"; | ||
delay?: number; | ||
videoConstraints?: MediaTrackConstraints; | ||
}) => React.ReactElement; | ||
export default BarcodeScannerComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const react_1 = __importDefault(require("react")); | ||
const library_1 = require("@zxing/library"); | ||
const react_webcam_1 = __importDefault(require("react-webcam")); | ||
const BarcodeScannerComponent = ({ onUpdate, width = "100%", height = "100%", facingMode = "environment", delay = 500, videoConstraints, }) => { | ||
const webcamRef = react_1.default.useRef(null); | ||
const codeReader = new library_1.BrowserMultiFormatReader(); | ||
const capture = react_1.default.useCallback(() => { | ||
var _a; | ||
const imageSrc = (_a = webcamRef === null || webcamRef === void 0 ? void 0 : webcamRef.current) === null || _a === void 0 ? void 0 : _a.getScreenshot(); | ||
if (imageSrc) { | ||
codeReader | ||
.decodeFromImage(undefined, imageSrc) | ||
.then((result) => { | ||
onUpdate(null, result); | ||
}) | ||
.catch((err) => { | ||
onUpdate(err); | ||
}); | ||
} | ||
}, [codeReader, onUpdate]); | ||
react_1.default.useEffect(() => { | ||
const interval = setInterval(capture, delay); | ||
return () => { | ||
clearInterval(interval); | ||
}; | ||
}, []); | ||
return (react_1.default.createElement(react_webcam_1.default, { width: width, height: height, ref: webcamRef, screenshotFormat: "image/jpeg", videoConstraints: videoConstraints || { | ||
facingMode, | ||
}, audio: false })); | ||
}; | ||
exports.default = BarcodeScannerComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import BarcodeScannerComponent from './BarcodeScannerComponent'; | ||
export default BarcodeScannerComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const BarcodeScannerComponent_1 = __importDefault(require("./BarcodeScannerComponent")); | ||
exports.default = BarcodeScannerComponent_1.default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters