js-webcam
A simple core polyfill for access to user media camera
Using from react
First install the package
npm i js-webcam
Then you can use it from any component:
;; const WIDTH = 620;const HEIGHT = 440; { thistrackerContext = thistrackerCanvas; thiswebcam = WIDTH HEIGHT; thiswebcamstart; this; } { this; } webcam; trackerContext; frameId; { if !thisframeId thisframeId = window; } { this; thisframeId = window; } { window; } { thistrackerContext; thistrackerContext; } { return <div> <canvas ref= { thistrackerCanvas = c; } width=WIDTH height=HEIGHT /> </div> ; } const mapStateToProps = state; ;
The start function activate the frontal camera, if you need the back camera you can use startBackCamera instead.
thiswebcam;
Or you can use the start function passing the facing mode parameter, on error and on success functions:
const onError = {}; // call when the camera can not activate. const onSuccess = {}; // call when the camera can activate successfully const facingMode = 'user'; // or 'environment' for back camera. thiswebcamstartonSuccess onError facingMode;