Gathering detailed insights and metrics for react-html5-camera-photo
Gathering detailed insights and metrics for react-html5-camera-photo
Gathering detailed insights and metrics for react-html5-camera-photo
Gathering detailed insights and metrics for react-html5-camera-photo
npm install react-html5-camera-photo
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
208 Stars
268 Commits
94 Forks
3 Watching
5 Branches
6 Contributors
Updated on 01 Nov 2024
JavaScript (96.36%)
CSS (2.37%)
HTML (1.27%)
Cumulative downloads
Total Downloads
Last day
-1.6%
2,977
Compared to previous day
Last week
7.9%
17,283
Compared to previous week
Last month
5.5%
70,886
Compared to previous month
Last year
16.8%
1,006,645
Compared to previous year
1
46
The first objective of this package comes from the need to get the same look and feel of a native mobile camera app but with a react component.
For those who want to build with their own css and need an abstraction of getUserMedia()
take a look of jslib-html5-camera-photo with react.
Demo of react-html5-camera-photo
https or localhost : The getUserMedia()
method is only available in secure contexts (https or localhost)
. If a document isn't loaded in a secure context, the navigator.mediaDevices property is undefined, making access to getUserMedia() impossible. Attempting to access getUserMedia()
in this situation will result in a TypeError. See developer.mozilla.org
iOS >= 11 WebRTC issue with webkit (Chrome & Firefox) : Apple restricts WebRTC to Safari only so it mean that you can't use the getUserMedia()
with Firefox and Chrome. So getUserMedia()
is not supported yet, for "security reasons". See Stackoverflow
1npm install --save react-html5-camera-photo
1yarn add react-html5-camera-photo
TypeScript definitions are available from Definitely Typed
1npm install --save-dev @types/react-html5-camera-photo
1yarn add --dev @types/react-html5-camera-photo
parameter | Description |
---|---|
onTakePhoto(dataUri): | Event function called when a photo is taken. the dataUri is passed as a parameter. |
Minimum ES6 example
1import React from 'react'; 2import Camera from 'react-html5-camera-photo'; 3import 'react-html5-camera-photo/build/css/index.css'; 4 5function App (props) { 6 function handleTakePhoto (dataUri) { 7 // Do stuff with the photo... 8 console.log('takePhoto'); 9 } 10 11 return ( 12 <Camera 13 onTakePhoto = { (dataUri) => { handleTakePhoto(dataUri); } } 14 /> 15 ); 16} 17 18export default App;
Properties | Type | Default | Description |
---|---|---|---|
onCameraStart(): (optional) | Event | Callback called when the camera is started. | |
onCameraStop(): (optional) | Event | Callback called when the camera is stopped. | |
onCameraError(error): (Optional) | Event | Callback called with the error object as parameter when error occur while opening the camera. Often the permission. | |
onTakePhoto(dataUri): (Optional) | Event | The function called when a photo is taken. the dataUri is passed as a parameter. | |
onTakePhotoAnimationDone(dataUri): (Optional) | Event | The function called when a photo is taken and the animation is done. the dataUri is passed as a parameter. | |
idealFacingMode: (Optional) (Dynamic) | String | Browser default | The ideal facing mode of the camera, environment or user . Use FACING_MODES constant to get the right string. Example :. FACING_MODES.ENVIRONMENT or FACING_MODES.USER |
idealResolution: (Optional) (Dynamic) | Object | Browser default | Object of the ideal resolution of the camera, {width: Integer, height: Integer} . |
isMaxResolution: (Optional) (Dynamic) | Boolean | false | If is true, the camera will start with his own maximum resolution. |
isImageMirror: (Optional) | Boolean | true | If is true, the camera image will be mirror. |
isSilentMode:(Optional) | Boolean | false | If is true, the camera do not play click sound when the photo was taken. |
isFullscreen: (Optional) | Boolean | false | If is true, the camera image will be set fullscreen to force the maximum width and height of the viewport. |
isDisplayStartCameraError: (Optional) | Boolean | true | If is true, if the camera start with error, it will show the error between h1 tag on the top of the component. Useful to notify the user about permission error. |
sizeFactor: (Optional) | Number | 1 | Number of the factor resolution. Example, a sizeFactor of 1 get the same resolution of the camera while sizeFactor of 0.5 get the half resolution of the camera. The sizeFactor can be between range of ]0, 1] . |
imageType:: (Optional) | String | png | String used to get the desired image type between jpg or png . to specify the imageType use the constant IMAGE_TYPES, for example to specify jpg format use IMAGE_TYPES.JPG. Use IMAGE_TYPES constant to get the right image type Example:. IMAGE_TYPES.JPG or IMAGE_TYPES.PNG |
imageCompression:: (Optional) | Number | 0.92 | Number used to get the desired compression when jpg is selected. choose a compression between [0, 1] , 1 is maximum, 0 is minimum. |
Dynamic : If the prop is dynamic, it mean that you can change that prop dynamically without umount the component (removing it). You can do it by a setState() inside the parent component. Checkout the demo example: ./src/demo/AppWithDynamicProperties.js
Probably the typical usage of using this component is to preview the image and close the camera after take a photo. You can take a look of all the code including the ImagePreview component here : ./src/demo/AppWithImagePreview
1import React, { useState } from 'react'; 2import Camera from 'react-html5-camera-photo'; 3import 'react-html5-camera-photo/build/css/index.css'; 4 5import ImagePreview from './ImagePreview'; // source code : ./src/demo/AppWithImagePreview/ImagePreview 6 7function App (props) { 8 const [dataUri, setDataUri] = useState(''); 9 10 function handleTakePhotoAnimationDone (dataUri) { 11 console.log('takePhoto'); 12 setDataUri(dataUri); 13 } 14 15 const isFullscreen = false; 16 return ( 17 <div> 18 { 19 (dataUri) 20 ? <ImagePreview dataUri={dataUri} 21 isFullscreen={isFullscreen} 22 /> 23 : <Camera onTakePhotoAnimationDone = {handleTakePhotoAnimationDone} 24 isFullscreen={isFullscreen} 25 /> 26 } 27 </div> 28 ); 29} 30 31export default App;
1import React from 'react'; 2import Camera, { FACING_MODES, IMAGE_TYPES } from 'react-html5-camera-photo'; 3import 'react-html5-camera-photo/build/css/index.css'; 4 5function App (props) { 6 function handleTakePhoto (dataUri) { 7 // Do stuff with the photo... 8 console.log('takePhoto'); 9 } 10 11 function handleTakePhotoAnimationDone (dataUri) { 12 // Do stuff with the photo... 13 console.log('takePhoto'); 14 } 15 16 function handleCameraError (error) { 17 console.log('handleCameraError', error); 18 } 19 20 function handleCameraStart (stream) { 21 console.log('handleCameraStart'); 22 } 23 24 function handleCameraStop () { 25 console.log('handleCameraStop'); 26 } 27 28 return ( 29 <Camera 30 onTakePhoto = { (dataUri) => { handleTakePhoto(dataUri); } } 31 onTakePhotoAnimationDone = { (dataUri) => { handleTakePhotoAnimationDone(dataUri); } } 32 onCameraError = { (error) => { handleCameraError(error); } } 33 idealFacingMode = {FACING_MODES.ENVIRONMENT} 34 idealResolution = {{width: 640, height: 480}} 35 imageType = {IMAGE_TYPES.JPG} 36 imageCompression = {0.97} 37 isMaxResolution = {true} 38 isImageMirror = {false} 39 isSilentMode = {false} 40 isDisplayStartCameraError = {true} 41 isFullscreen = {false} 42 sizeFactor = {1} 43 onCameraStart = { (stream) => { handleCameraStart(stream); } } 44 onCameraStop = { () => { handleCameraStop(); } } 45 /> 46 ); 47} 48 49export default App;
Before sending a bug report of camera error, make sure that getUserMedia()
is supported by your browser. Please test your camera on : DetectRTC | Is WebRTC Supported In Your Browser? If the System has Webcam is supported
, please send the screenshot of the first 7 first rows of the table.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 2
Reason
Found 3/18 approved changesets -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
123 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More