Gathering detailed insights and metrics for @rinse/react-html5-camera-photo
Gathering detailed insights and metrics for @rinse/react-html5-camera-photo
Gathering detailed insights and metrics for @rinse/react-html5-camera-photo
Gathering detailed insights and metrics for @rinse/react-html5-camera-photo
npm install @rinse/react-html5-camera-photo
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
243 Commits
1 Watching
5 Branches
Updated on 28 Oct 2019
JavaScript (96.01%)
CSS (2.72%)
HTML (1.27%)
Cumulative downloads
Total Downloads
Last day
-94.6%
2
Compared to previous day
Last week
-14%
92
Compared to previous week
Last month
33.7%
607
Compared to previous month
Last year
49%
8,927
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
Both Yarn and npm download packages from the npm registry.
parameter | Description |
---|---|
onTakePhoto(dataUri): | Event function called when a photo is taken. the dataUri is passed as a parameter. |
Minimum ES6 example
1import React, { Component } from 'react'; 2import Camera from 'react-html5-camera-photo'; 3import 'react-html5-camera-photo/build/css/index.css'; 4 5class App extends Component { 6 onTakePhoto (dataUri) { 7 // Do stuff with the dataUri photo... 8 console.log('takePhoto'); 9 } 10 11 render () { 12 return ( 13 <div className="App"> 14 <Camera 15 onTakePhoto = { (dataUri) => { this.onTakePhoto(dataUri); } } 16 /> 17 </div> 18 ); 19 } 20} 21 22export default App;
Properties | Type | 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 | The ideal facing mode of the camera, environment or user , the default is the default of the browser. Use FACING_MODES constant to get the right string. Example :. FACING_MODES.ENVIRONMENT or FACING_MODES.USER |
idealResolution: (Optional) (Dynamic) | Object | Object of the ideal resolution of the camera, {width: Integer, height: Integer} , the default is the default of the browser. |
isMaxResolution: (Optional) (Dynamic) | Boolean | If is true, the camera will start with his own maximum resolution, the default is false. |
isImageMirror: (Optional) | Boolean | If is true, the camera image will be mirror, the default is true. |
isSilentMode:(Optional) | Boolean | If is true, the camera do not play click sound when the photo was taken, the default is false. |
isFullscreen: (Optional) | Boolean | If is true, the camera image will be set fullscreen to force the maximum width and height of the viewport, the default is false. |
isDisplayStartCameraError: (Optional) | Boolean | 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, the default is true. |
sizeFactor: (Optional) | Number | 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] and the default value is 1 . |
imageType:: (Optional) | String | 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. The default imageType is png . Use IMAGE_TYPES constant to get the right image type Example:. IMAGE_TYPES.JPG or IMAGE_TYPES.PNG |
imageCompression:: (Optional) | Number | Number used to get the desired compression when jpg is selected. choose a compression between [0, 1] , 1 is maximum, 0 is minimum. The default value imageCompression is 0.92 . |
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, { Component } 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 7class App extends Component { 8 constructor (props, context) { 9 super(props, context); 10 this.state = { dataUri: null }; 11 this.onTakePhotoAnimationDone = this.onTakePhotoAnimationDone.bind(this); 12 } 13 14 onTakePhotoAnimationDone (dataUri) { 15 console.log('takePhoto'); 16 this.setState({ dataUri }); 17 } 18 19 render () { 20 return ( 21 <div className="App"> 22 { 23 (this.state.dataUri) 24 ? <ImagePreview dataUri={this.state.dataUri} /> 25 : <Camera onTakePhotoAnimationDone = {this.onTakePhotoAnimationDone} /> 26 } 27 </div> 28 ); 29 } 30} 31 32export default App;
1import React, { Component } from 'react'; 2import Camera, { FACING_MODES, IMAGE_TYPES } from 'react-html5-camera-photo'; 3import 'react-html5-camera-photo/build/css/index.css'; 4 5class App extends Component { 6 onTakePhoto (dataUri) { 7 // Do stuff with the photo... 8 console.log('takePhoto'); 9 } 10 11 onTakePhotoAnimationDone (dataUri) { 12 // Do stuff with the photo... 13 console.log('takePhoto'); 14 } 15 16 onCameraError (error) { 17 console.error('onCameraError', error); 18 } 19 20 onCameraStart (stream) { 21 console.log('onCameraStart'); 22 } 23 24 onCameraStop () { 25 console.log('onCameraStop'); 26 } 27 28 render () { 29 return ( 30 <div className="App"> 31 <Camera 32 onTakePhoto = { (dataUri) => { this.onTakePhoto(dataUri); } } 33 onTakePhotoAnimationDone = { (dataUri) => { this.onTakePhotoAnimationDone(dataUri); } } 34 onCameraError = { (error) => { this.onCameraError(error); } } 35 idealFacingMode = {FACING_MODES.ENVIRONMENT} 36 idealResolution = {{width: 640, height: 480}} 37 imageType = {IMAGE_TYPES.JPG} 38 imageCompression = {0.97} 39 isMaxResolution = {false} 40 isImageMirror = {false} 41 isSilentMode = {true} 42 isDisplayStartCameraError = {true} 43 isFullscreen = {true} 44 sizeFactor = {1} 45 onCameraStart = { (stream) => { this.onCameraStart(stream); } } 46 onCameraStop = { () => { this.onCameraStop(); } } 47 /> 48 </div> 49 ); 50 } 51} 52 53export 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
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
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
branch protection not enabled on development/release branches
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