Skip to content

Commit

Permalink
build release
Browse files Browse the repository at this point in the history
  • Loading branch information
jamenamcinteer committed Apr 7, 2021
1 parent 8a1b6d2 commit 30a510a
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node_modules
dist
node_modules
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# React Webcam Barcode Scanner
# React QR Barcode Scanner

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).

Expand Down
11 changes: 11 additions & 0 deletions dist/BarcodeScannerComponent.d.ts
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;
36 changes: 36 additions & 0 deletions dist/BarcodeScannerComponent.js
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;
2 changes: 2 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import BarcodeScannerComponent from './BarcodeScannerComponent';
export default BarcodeScannerComponent;
7 changes: 7 additions & 0 deletions dist/index.js
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;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-qr-barcode-scanner",
"version": "1.0.3",
"version": "1.0.4",
"description": "A simple React Component using the client's webcam to read barcodes and QR codes.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit 30a510a

Please sign in to comment.