forked from smronju/vue-webcam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VueWebcam.min.js
1 lines (1 loc) · 1.56 KB
/
VueWebcam.min.js
1
'use strict';var Vue=require('vue'),WebcamComponent=Vue.extend({render:function render(a){return a('video',{ref:'video',attrs:{width:this.width,height:this.height,src:this.src,autoplay:this.autoplay}})},props:{autoplay:{type:Boolean,default:!0},width:{type:Number,default:400},height:{type:Number,default:300},mirror:{type:Boolean,default:!0},screenshotFormat:{type:String,default:'image/jpeg'}},data:function data(){return{video:'',src:'',stream:'',hasUserMedia:!1,styleObject:{transform:'scale(-1, 1)',filter:'FlipH'}}},methods:{getPhoto:function getPhoto(){if(!this.hasUserMedia)return null;var a=this.getCanvas();return a.toDataURL(this.screenshotFormat)},getCanvas:function getCanvas(){if(!this.hasUserMedia)return null;var c=this.$refs.video;if(!this.ctx){var d=document.createElement('canvas');d.height=c.clientHeight,d.width=c.clientWidth,this.canvas=d,this.ctx=d.getContext('2d')}var a=this.ctx,b=this.canvas;return a.drawImage(c,0,0,b.width,b.height),b}},mounted:function mounted(){var a=this;this.video=this.$refs.video,navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia||navigator.oGetUserMedia,navigator.getUserMedia&&navigator.getUserMedia({video:!0},function(b){a.src=window.URL.createObjectURL(b),a.stream=b,a.hasUserMedia=!0},function(b){console.log(b)})},beforeDestroy:function beforeDestroy(){this.video.pause(),this.src='',this.stream.getTracks()[0].stop()},destroyed:function destroyed(){console.log('Destroyed')}}),VueWebcam=Vue.component('vue-webcam',WebcamComponent);module.exports=VueWebcam;