Skip to content
This repository has been archived by the owner on Feb 19, 2024. It is now read-only.

add autosetup and canvasEl for customize setup #62

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "vue-web-cam",
"version": "1.9.0",
"description": "Webcam component for Vuejs applications",
"name": "@nickfan/vue-web-cam",
"version": "1.9.4",
"description": "forked version of vue-web-cam Webcam component for Vuejs applications",
"repository": {
"type": "git",
"url": "https://github.com/vinceg/vue-web-cam"
"url": "https://github.com/nickfan/vue-web-cam"
},
"license": "MIT",
"author": {
Expand Down
59 changes: 57 additions & 2 deletions src/webcam.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<video
ref="video"
:id="vid"
:width="width"
:height="height"
:src="source"
Expand All @@ -14,6 +15,17 @@ export default {
name: "VueWebCam",

props: {
vid: {
type: String,
default:
"vid_" +
Math.random()
.toString(36)
.substring(2, 15) +
Math.random()
.toString(36)
.substring(2, 15)
},
width: {
type: [Number, String],
default: "100%"
Expand All @@ -30,6 +42,10 @@ export default {
type: String,
default: "image/jpeg"
},
autosetup: {
type: Boolean,
default: true
},
selectFirstDevice: {
type: Boolean,
default: false
Expand All @@ -48,6 +64,10 @@ export default {
validator: value => {
return value.height && value.width;
}
},
canvasEl: {
type: Object,
default: null
}
},

Expand All @@ -67,7 +87,9 @@ export default {
},

mounted() {
this.setupMedia();
if (this.autosetup) {
this.setupMedia();
}
},

beforeDestroy() {
Expand Down Expand Up @@ -273,7 +295,12 @@ export default {
getCanvas() {
let video = this.$refs.video;
if (!this.ctx) {
let canvas = document.createElement("canvas");
let canvas;
if (this.$refs.canvasEl) {
canvas = this.$refs.canvasEl;
} else {
canvas = document.createElement("canvas");
}
canvas.height = video.videoHeight;
canvas.width = video.videoWidth;
this.canvas = canvas;
Expand All @@ -285,6 +312,34 @@ export default {
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);

return canvas;
},

/**
* getVideo
*/
getVideo() {
return this.$refs.video;
},
/**
* getVideoId
*/
getVid() {
return this.vid;
},
/**
* getThisCanvas
*/
getThisCanvas() {
this.getCanvas();
return this.canvas;
},

/**
* getCanvasContext
*/
getCanvasContext() {
this.getCanvas();
return this.ctx;
}
}
};
Expand Down