Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
react-camera-pro
Advanced tools
Universal Camera component for React. Designed with focus on Android, iOS cameras and standard webcams.
Universal Camera component for React.
Designed with focus on Android and iOS cameras. Works with standard webcams as well.
See this for browser compatibility.
Note: WebRTC is only supported on secure connections. So you need to serve it from https. You can test and debug in Chrome from localhost though (this doesn't work in Safari).
npm install --save react-camera-pro
https://purple-technology.github.io/react-camera-pro/
https://github.com/purple-technology/react-camera-pro/blob/master/example/src/App.tsx
import React, { useState, useRef } from "react";
import {Camera} from "react-camera-pro";
const Component = () => {
const camera = useRef(null);
const [image, setImage] = useState(null);
return (
<div>
<Camera ref={camera} />
<button onClick={() => setImage(camera.current.takePhoto())}>Take photo</button>
<img src={image} alt='Taken photo'/>
</div>
);
}
export Component;
prop | type | default | notes |
---|---|---|---|
facingMode | 'user'|'environment' | 'user' | default camera - 'user' or 'environment' |
aspectRatio | 'cover'|number | 'cover' | aspect ratio of video (16/9, 4/3); |
numberOfCamerasCallback | (numberOfCameras: number):void | () => null | callback is called if number of cameras change |
errorMessages | object? see below | see below | Error messages object (optional) |
Type:
errorMessages: {
noCameraAccessible?: string;
permissionDenied?: string;
switchCamera?: string;
canvas?: string;
};
Default:
{
noCameraAccessible: 'No camera device accessible. Please connect your camera or try a different browser.',
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.'
}
takePhoto(): string
- Returns a base64 encoded string of the taken image.switchCamera(): 'user'|'environment'
- Switches the camera - user to environment or environment to user. Returns the new value 'user' or 'environment'.getNumberOfCameras(): number
- Returns number of available cameras.
const Component = () => {
const camera = useRef(null);
const [numberOfCameras, setNumberOfCameras] = useState(0);
const [image, setImage] = useState(null);
//...
return (
<Camera ref={camera} numberOfCamerasCallback={setNumberOfCameras} />
<img src={image} alt='Image preview' />
<button
onClick={() => {
const photo = camera.current.takePhoto();
setImage(photo);
}}
/>
<button
hidden={numberOfCameras <= 1}
onClick={() => {
camera.current.switchCamera();
}}
/>
)
const Cam = () => <Camera ref={camera} facingMode='environment'} />
const Cam = () => <Camera ref={camera} aspectRatio={16 / 9} />;
<iframe src="https://example.com/camera-pro-iframe" allow="camera;"/>
MIT
FAQs
Universal Camera component for React. Designed with focus on Android, iOS cameras and standard webcams.
The npm package react-camera-pro receives a total of 5,623 weekly downloads. As such, react-camera-pro popularity was classified as popular.
We found that react-camera-pro demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.