Easy typescript camera
Version 1.1.2
This package helps you to add camera support to your web application easily and support front and rear camera out of the box.
npm install easy-ts-camera
This package is created based on easy-js-camera
with some improvements and typescript support.
easy-js-camera link
Usage
Add your video and canvas as follow,
<video autoplay playsinline></video>
<canvas></canvas>
Import the Camera class as follow,
import ETC from 'easy-ts-camera';
To be able to access to all Video Inputs you first need to get the permission from the user.
Note: On some devices it is not needed to first get the permission but it is better to do that first since on some devices if the permission is not granted it doesn't return all the devices.
var video = document.getElementsByTagName('video')[0];
var canvas = document.getElementsByTagName('canvas')[0];
ETC.initWithUserCamera()
.streamFrom(video)
.drawInto(canvas)
.getCameraAsync()
.then(camera => {
camera.startAsync()
})
.catch(error => {
});
Note: In order to make sure that the browser supports MediaDevices you can do as follow.
import { CameraUtils } from 'easy-ts-camera';
CameraUtils.isCameraSupported();
Camera object props
- devices: Contains an array of available VideoInput devices
- builder: An instance of the CameraBuilder class which contains the
HtmlVideoELement
and HtmlCanvasElement
and also the MediaConstraints
.
- Builder now has a method to pick
4K
resolution if available by the camera. call pick4KResolution
before getting the camera. - Builder also supports the
FullHD
resolution. Please call this method before building camera.
Methods