easy-js-camera
Advanced tools
Comparing version 1.1.2 to 2.0.0
@@ -14,2 +14,6 @@ 'use strict'; | ||
var _OutputType = require('./OutputType'); | ||
var _OutputType2 = _interopRequireDefault(_OutputType); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -108,16 +112,42 @@ | ||
context.drawImage(this.videoElement, 0, 0, this.canvasElement.width, this.canvasElement.height); | ||
return this.canvasElement; | ||
} | ||
/** | ||
* @return String | ||
*/ | ||
}, { | ||
key: 'snapAsBase64', | ||
value: function snapAsBase64() { | ||
this.snap(); | ||
var data = this.canvasElement.toDataURL('image/png'); | ||
return data; | ||
} | ||
/** | ||
* @return Promise | ||
*/ | ||
}, { | ||
key: 'snapAsBlob', | ||
value: function snapAsBlob() { | ||
var _this2 = this; | ||
this.snap(); | ||
new Promise(function (resolve) { | ||
_this2.canvasElement.toBlob(function (blob) { | ||
resolve(blob); | ||
}, 'image/png', 1); | ||
}); | ||
} | ||
}, { | ||
key: 'start', | ||
value: function start() { | ||
var _this2 = this; | ||
var _this3 = this; | ||
return new Promise(async function (resolve, reject) { | ||
try { | ||
await _this2.getDevices(); | ||
var stream = await navigator.mediaDevices.getUserMedia(_this2.constraints.getConstraint()); | ||
_this2.videoElement.srcObject = stream; | ||
_this2.stream = stream; | ||
await _this3.getDevices(); | ||
var stream = await navigator.mediaDevices.getUserMedia(_this3.constraints.getConstraint()); | ||
_this3.videoElement.srcObject = stream; | ||
_this3.stream = stream; | ||
resolve(); | ||
@@ -142,3 +172,3 @@ } catch (error) { | ||
value: function _switch() { | ||
var _this3 = this; | ||
var _this4 = this; | ||
@@ -148,6 +178,6 @@ var tryAgain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
return new Promise(async function (resolve, reject) { | ||
_this3.constraints = _this3.constraints.switchFacingMode(tryAgain); | ||
_this3.stop(); | ||
_this4.constraints = _this4.constraints.switchFacingMode(tryAgain); | ||
_this4.stop(); | ||
try { | ||
await _this3.start(); | ||
await _this4.start(); | ||
resolve(); | ||
@@ -154,0 +184,0 @@ } catch (error) { |
{ | ||
"name": "easy-js-camera", | ||
"version": "1.1.2", | ||
"version": "2.0.0", | ||
"description": "A package which helps with adding camera support to a web application", | ||
@@ -5,0 +5,0 @@ "main": "lib/Camera.js", |
@@ -46,3 +46,5 @@ # Intro | ||
* **setVideoConstraints:** By default only `facingMode` key of the video constraints is set. With this method you can expand the constraints and add your own costraints but please **NOTICE** that the `facingMode` is being used in switch method. | ||
* **snap:** It is the `fun` part. This method will take a picture and will return it as a base64 string. | ||
* **snap:** This method will take a picture and will return the canvasElement so you can extract the picture as whatever format you like. | ||
* **snapAsBase64:** This method will take a picture and will return it as a base64 string. | ||
* **snapAsBlob:** This method will take a picture and will return a promise which on resolve will deliver a `blob`. | ||
* **start:** This method starts the camera and will return a promise for the result of the action. | ||
@@ -55,3 +57,3 @@ * **stop:** This method is responsible for stoping the stream. | ||
.catch(() => { | ||
if(tryAgain) return; // This line prevent loops. Because the tryAgain may also fail | ||
if(tryAgain) return; // This line prevents loops. Because the tryAgain may also fail | ||
this.camera.switch(true); | ||
@@ -58,0 +60,0 @@ }); |
import CameraModel from "./CameraModel"; | ||
import OutputType from './OutputType'; | ||
export class Constraints { | ||
@@ -70,5 +70,23 @@ constructor() { | ||
context.drawImage(this.videoElement, 0, 0, this.canvasElement.width, this.canvasElement.height); | ||
return this.canvasElement; | ||
} | ||
/** | ||
* @return String | ||
*/ | ||
snapAsBase64() { | ||
this.snap(); | ||
let data = this.canvasElement.toDataURL('image/png'); | ||
return data; | ||
} | ||
/** | ||
* @return Promise | ||
*/ | ||
snapAsBlob() { | ||
this.snap(); | ||
new Promise((resolve) => { | ||
this.canvasElement.toBlob((blob) => { | ||
resolve(blob); | ||
}, 'image/png', 1); | ||
}); | ||
} | ||
start() { | ||
@@ -75,0 +93,0 @@ return new Promise(async (resolve, reject) => { |
16182
336
60