mirror of
https://github.com/GuerillaStudio/souvenir.git
synced 2024-11-08 09:11:52 +00:00
add camera preview
This commit is contained in:
parent
8f1f54e574
commit
beefe38b3b
6 changed files with 27 additions and 15 deletions
6
package-lock.json
generated
6
package-lock.json
generated
|
@ -2826,8 +2826,7 @@
|
|||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz",
|
||||
"integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"coa": {
|
||||
"version": "2.0.2",
|
||||
|
@ -9536,8 +9535,7 @@
|
|||
"version": "4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-4.0.8.tgz",
|
||||
"integrity": "sha1-Cx4Rr4vESDbwSmQH6S2kJGe3lEQ=",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"rx-lite-aggregates": {
|
||||
"version": "4.0.8",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<div class="layout">
|
||||
<welcome-screen v-if="!welcomed && !downloading.status"/>
|
||||
<capture-screen v-if="welcomed && !downloading.status"/>
|
||||
<welcome-screen v-if="!mediaStream && !downloading.status"/>
|
||||
<capture-screen v-if="mediaStream && !downloading.status"/>
|
||||
<download-screen v-if="downloading.status"/>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -23,7 +23,7 @@ export default {
|
|||
},
|
||||
computed: {
|
||||
...mapState([
|
||||
'welcomed',
|
||||
'mediaStream',
|
||||
'downloading'
|
||||
])
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
back () {
|
||||
this.$store.commit('welcome', false)
|
||||
this.$store.commit('updateMediaStream', null)
|
||||
},
|
||||
timeLabel (time) {
|
||||
return time + 's'
|
||||
|
|
18
src/store.js
18
src/store.js
|
@ -5,7 +5,7 @@ Vue.use(Vuex)
|
|||
|
||||
export default new Vuex.Store({
|
||||
state: {
|
||||
welcomed: false,
|
||||
mediaStream: null,
|
||||
timer: {
|
||||
selected: 2,
|
||||
list: [2, 3, 5]
|
||||
|
@ -22,8 +22,12 @@ export default new Vuex.Store({
|
|||
}
|
||||
},
|
||||
mutations: {
|
||||
welcome (store, value) {
|
||||
store.welcomed = value
|
||||
updateMediaStream(store, mediaStream) {
|
||||
if (store.mediaStream) {
|
||||
store.mediaStream.getTracks().forEach(track => track.stop())
|
||||
}
|
||||
|
||||
store.mediaStream = mediaStream
|
||||
},
|
||||
updateTimer (store, time) {
|
||||
store.timer.selected = time
|
||||
|
@ -51,6 +55,12 @@ export default new Vuex.Store({
|
|||
}
|
||||
},
|
||||
actions: {
|
||||
|
||||
requestCamera ({ commit }) {
|
||||
navigator.mediaDevices.getUserMedia({ video: true, audio: false })
|
||||
.then(mediaStream => {
|
||||
commit('updateMediaStream', mediaStream)
|
||||
})
|
||||
.catch(error => console.error(error))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<capture-options v-else/>
|
||||
|
||||
<div class="preview">
|
||||
<video class="preview-visual" height="200px"></video>
|
||||
<video ref="preview" class="preview-visual" height="200px" autoplay></video>
|
||||
</div>
|
||||
|
||||
<button class="capture-btn" :class="{ 'capture-btn--capturing': capturing.status }" @click="startCapture">Capture</button>
|
||||
|
@ -31,6 +31,7 @@ export default {
|
|||
},
|
||||
computed: {
|
||||
...mapState([
|
||||
'mediaStream',
|
||||
'capturing',
|
||||
'timer',
|
||||
'encoding'
|
||||
|
@ -54,6 +55,9 @@ export default {
|
|||
}
|
||||
}, interval)
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted: function () {
|
||||
this.$refs.preview.srcObject = this.mediaStream
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -17,7 +17,7 @@ export default {
|
|||
name: 'welcome',
|
||||
methods: {
|
||||
welcome () {
|
||||
this.$store.commit('welcome', true)
|
||||
this.$store.dispatch('requestCamera')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue