Skip to content

Commit

Permalink
minor: new version release
Browse files Browse the repository at this point in the history
  • Loading branch information
xurban42 committed Apr 25, 2023
1 parent b43dd50 commit b025e6a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
34 changes: 18 additions & 16 deletions example/src/Camera/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,30 @@ var Camera = React.forwardRef(function (_a, ref) {
permissionDenied: 'Permission denied. Please refresh and give camera permission.',
switchCamera: 'It is not possible to switch camera to different one because there is only one video device accessible.',
canvas: 'Canvas is not supported.',
} : _f;
} : _f, _g = _a.videoReadyCallback, videoReadyCallback = _g === void 0 ? function () { return null; } : _g;
var player = useRef(null);
var canvas = useRef(null);
var container = useRef(null);
var _g = useState(0), numberOfCameras = _g[0], setNumberOfCameras = _g[1];
var _h = useState(null), stream = _h[0], setStream = _h[1];
var _j = useState(facingMode), currentFacingMode = _j[0], setFacingMode = _j[1];
var _k = useState(false), notSupported = _k[0], setNotSupported = _k[1];
var _l = useState(false), permissionDenied = _l[0], setPermissionDenied = _l[1];
var _h = useState(0), numberOfCameras = _h[0], setNumberOfCameras = _h[1];
var _j = useState(null), stream = _j[0], setStream = _j[1];
var _k = useState(facingMode), currentFacingMode = _k[0], setFacingMode = _k[1];
var _l = useState(false), notSupported = _l[0], setNotSupported = _l[1];
var _m = useState(false), permissionDenied = _m[0], setPermissionDenied = _m[1];
useEffect(function () {
numberOfCamerasCallback(numberOfCameras);
}, [numberOfCameras]);
useImperativeHandle(ref, function () { return ({
takePhoto: function () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
var _a, _b, _c, _d;
if (numberOfCameras < 1) {
throw new Error(errorMessages.noCameraAccessible);
}
if ((_a = canvas) === null || _a === void 0 ? void 0 : _a.current) {
var playerWidth = ((_c = (_b = player) === null || _b === void 0 ? void 0 : _b.current) === null || _c === void 0 ? void 0 : _c.videoWidth) || 1280;
var playerHeight = ((_e = (_d = player) === null || _d === void 0 ? void 0 : _d.current) === null || _e === void 0 ? void 0 : _e.videoHeight) || 720;
if (canvas === null || canvas === void 0 ? void 0 : canvas.current) {
var playerWidth = ((_a = player === null || player === void 0 ? void 0 : player.current) === null || _a === void 0 ? void 0 : _a.videoWidth) || 1280;
var playerHeight = ((_b = player === null || player === void 0 ? void 0 : player.current) === null || _b === void 0 ? void 0 : _b.videoHeight) || 720;
var playerAR = playerWidth / playerHeight;
var canvasWidth = ((_g = (_f = container) === null || _f === void 0 ? void 0 : _f.current) === null || _g === void 0 ? void 0 : _g.offsetWidth) || 1280;
var canvasHeight = ((_j = (_h = container) === null || _h === void 0 ? void 0 : _h.current) === null || _j === void 0 ? void 0 : _j.offsetHeight) || 1280;
var canvasWidth = ((_c = container === null || container === void 0 ? void 0 : container.current) === null || _c === void 0 ? void 0 : _c.offsetWidth) || 1280;
var canvasHeight = ((_d = container === null || container === void 0 ? void 0 : container.current) === null || _d === void 0 ? void 0 : _d.offsetHeight) || 1280;
var canvasAR = canvasWidth / canvasHeight;
var sX = void 0, sY = void 0, sW = void 0, sH = void 0;
if (playerAR > canvasAR) {
Expand All @@ -85,7 +85,7 @@ var Camera = React.forwardRef(function (_a, ref) {
canvas.current.width = sW;
canvas.current.height = sH;
var context = canvas.current.getContext('2d');
if (context && ((_k = player) === null || _k === void 0 ? void 0 : _k.current)) {
if (context && (player === null || player === void 0 ? void 0 : player.current)) {
context.drawImage(player.current, sX, sY, sW, sH, 0, 0, sW, sH);
}
var imgData = canvas.current.toDataURL('image/jpeg');
Expand Down Expand Up @@ -129,12 +129,14 @@ var Camera = React.forwardRef(function (_a, ref) {
React.createElement(Wrapper, null,
notSupported ? React.createElement(ErrorMsg, null, errorMessages.noCameraAccessible) : null,
permissionDenied ? React.createElement(ErrorMsg, null, errorMessages.permissionDenied) : null,
React.createElement(Cam, { ref: player, id: "video", muted: true, autoPlay: true, playsInline: true, mirrored: currentFacingMode === 'user' ? true : false }),
React.createElement(Cam, { ref: player, id: "video", muted: true, autoPlay: true, playsInline: true, mirrored: currentFacingMode === 'user' ? true : false, onLoadedData: function () {
videoReadyCallback();
} }),
React.createElement(Canvas, { ref: canvas }))));
});
Camera.displayName = 'Camera';
var initCameraStream = function (stream, setStream, currentFacingMode, videoSourceDeviceId, setNumberOfCameras, setNotSupported, setPermissionDenied) {
var _a, _b;
var _a;
// stop any active streams in the window
if (stream) {
stream.getTracks().forEach(function (track) {
Expand All @@ -150,7 +152,7 @@ var initCameraStream = function (stream, setStream, currentFacingMode, videoSour
height: { ideal: 1920 },
},
};
if ((_b = (_a = navigator) === null || _a === void 0 ? void 0 : _a.mediaDevices) === null || _b === void 0 ? void 0 : _b.getUserMedia) {
if ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia) {
navigator.mediaDevices
.getUserMedia(constraints)
.then(function (stream) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-camera-pro",
"description": "Universal Camera component for React. Designed with focus on Android, iOS cameras and standard webcams.",
"version": "1.2.2",
"version": "1.3.0",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"keywords": [
Expand Down

0 comments on commit b025e6a

Please sign in to comment.