Webcam Easy JS
This is a javascript library for accessing webcam stream and taking photos.
You can easily add it as a module to your own app.
- Streaming webcam on desktop computer or mobile
- Switch back or front cameras on mobile
- Take pictures and be able to download.
Live Demo
https://bensonruan.com/how-to-access-webcam-and-take-photo-with-javascript/
Installation
Use Git Clone
git https://github.com/bensonruan/webcam-easy.git
OR Use NPM
npm install webcam-easy
Usage
1. Include script tag in html
or Import into javascript
;
2. Place elements in HTML
3. Call constructor in javascript
const webcamElement = document;const canvasElement = document;const snapSoundElement = document;const webcam = webcamElement 'user' canvasElement snapSoundElement;
4. Start Webcam
webcamstart;
5. Take Photo
var picture = webcam;
6. Stop Webcam
webcam;
Functions
-
start(startStream) : start streaming webcam
- get permission from user
- get all video input devices info
- select camera based on facingMode
- start stream
startStream is optional parameter, default value is true
-
stop() : stop streaming webcam
-
stream() : start streaming webcam to video element
-
snap() : take photo from webcam
-
flip() : change Facing mode and selected camera
Properties
- facingMode : 'user' or 'enviroment'
- webcamList : all available camera device
- webcamCount : number of available camera device