Skip to content

Commit

Permalink
Add dist
Browse files Browse the repository at this point in the history
  • Loading branch information
jamenamcinteer committed Apr 8, 2021
1 parent 03ca1bd commit 16f5c87
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 2 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
14 changes: 14 additions & 0 deletions dist/BarcodeScannerComponent.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import { Result } from "@zxing/library";
declare const BarcodeScannerComponent: ({ onUpdate, onError, width, height, facingMode, torch, delay, videoConstraints, stopStream, }: {
onUpdate: (arg0: unknown, arg1?: Result) => void;
onError?: (arg0: string | DOMException) => void;
width?: number | string;
height?: number | string;
facingMode?: "environment" | "user";
torch?: boolean;
delay?: number;
videoConstraints?: MediaTrackConstraints;
stopStream?: boolean;
}) => React.ReactElement;
export default BarcodeScannerComponent;
72 changes: 72 additions & 0 deletions dist/BarcodeScannerComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"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, onError, width = "100%", height = "100%", facingMode = "environment", torch, delay = 500, videoConstraints, stopStream, }) => {
const webcamRef = react_1.default.useRef(null);
const capture = react_1.default.useCallback(() => {
var _a;
const codeReader = new library_1.BrowserMultiFormatReader();
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);
});
}
}, [onUpdate]);
react_1.default.useEffect(() => {
var _a, _b;
// Turn on the flashlight if prop is defined and device has the capability
if (typeof torch === "boolean" && ((_a =
// @ts-ignore
navigator === null ||
// @ts-ignore
navigator === void 0 ? void 0 :
// @ts-ignore
navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getSupportedConstraints().torch)) {
const stream = (_b = webcamRef === null || webcamRef === void 0 ? void 0 : webcamRef.current) === null || _b === void 0 ? void 0 : _b.video.srcObject;
const track = stream === null || stream === void 0 ? void 0 : stream.getVideoTracks()[0]; // get the active track of the stream
if (track &&
track.getCapabilities().torch &&
!track.getConstraints().torch) {
track
.applyConstraints({
advanced: [{ torch }],
})
.catch((err) => onUpdate(err));
}
}
}, [torch, onUpdate]);
react_1.default.useEffect(() => {
var _a;
if (stopStream) {
let stream = (_a = webcamRef === null || webcamRef === void 0 ? void 0 : webcamRef.current) === null || _a === void 0 ? void 0 : _a.video.srcObject;
if (stream) {
stream.getTracks().forEach((track) => {
stream.removeTrack(track);
track.stop();
});
stream = null;
}
}
}, [stopStream]);
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, onUserMediaError: onError }));
};
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;

0 comments on commit 16f5c87

Please sign in to comment.