mirror of
https://github.com/GuerillaStudio/souvenir.git
synced 2024-11-08 09:11:52 +00:00
feat(capture option): Switch camera
This commit is contained in:
parent
8e5f0b5907
commit
7e7502f507
5 changed files with 47 additions and 37 deletions
27
package-lock.json
generated
27
package-lock.json
generated
|
@ -3489,8 +3489,7 @@
|
|||
"ansi-regex": {
|
||||
"version": "2.1.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"aproba": {
|
||||
"version": "1.2.0",
|
||||
|
@ -3533,8 +3532,7 @@
|
|||
"code-point-at": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
|
@ -3545,8 +3543,7 @@
|
|||
"console-control-strings": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.2",
|
||||
|
@ -3663,8 +3660,7 @@
|
|||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"ini": {
|
||||
"version": "1.3.5",
|
||||
|
@ -3676,7 +3672,6 @@
|
|||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"number-is-nan": "^1.0.0"
|
||||
}
|
||||
|
@ -3706,7 +3701,6 @@
|
|||
"version": "2.3.5",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"safe-buffer": "^5.1.2",
|
||||
"yallist": "^3.0.0"
|
||||
|
@ -3725,7 +3719,6 @@
|
|||
"version": "0.5.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"minimist": "0.0.8"
|
||||
}
|
||||
|
@ -3819,7 +3812,6 @@
|
|||
"version": "1.4.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
|
@ -3905,8 +3897,7 @@
|
|||
"safe-buffer": {
|
||||
"version": "5.1.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
|
@ -3942,7 +3933,6 @@
|
|||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"code-point-at": "^1.0.0",
|
||||
"is-fullwidth-code-point": "^1.0.0",
|
||||
|
@ -3962,7 +3952,6 @@
|
|||
"version": "3.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"ansi-regex": "^2.0.0"
|
||||
}
|
||||
|
@ -4006,14 +3995,12 @@
|
|||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"yallist": {
|
||||
"version": "3.0.3",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<template lang="html">
|
||||
<div class="layout">
|
||||
<welcome-screen v-if="!mediaStream && !downloading.status"></welcome-screen>
|
||||
<capture-screen v-if="mediaStream && !downloading.status"></capture-screen>
|
||||
<welcome-screen v-if="!welcomed && !downloading.status"></welcome-screen>
|
||||
<capture-screen v-if="welcomed && !downloading.status"></capture-screen>
|
||||
<download-screen v-if="downloading.status"></download-screen>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -23,7 +23,7 @@ export default {
|
|||
},
|
||||
computed: {
|
||||
...mapState([
|
||||
'mediaStream',
|
||||
'welcomed',
|
||||
'downloading'
|
||||
])
|
||||
}
|
||||
|
|
43
src/store.js
43
src/store.js
|
@ -9,6 +9,7 @@ Vue.use(Vuex)
|
|||
export default new Vuex.Store({
|
||||
strict: process.env.NODE_ENV !== 'production',
|
||||
state: {
|
||||
welcomed: false,
|
||||
mediaStream: null,
|
||||
timer: {
|
||||
selected: 2,
|
||||
|
@ -16,6 +17,7 @@ export default new Vuex.Store({
|
|||
},
|
||||
capturing: {
|
||||
status: false,
|
||||
shouldFaceUser: true,
|
||||
state: 0
|
||||
},
|
||||
encoding: {
|
||||
|
@ -28,12 +30,19 @@ export default new Vuex.Store({
|
|||
}
|
||||
},
|
||||
mutations: {
|
||||
updateMediaStream (store, mediaStream) {
|
||||
if (store.mediaStream) {
|
||||
store.mediaStream.getTracks().forEach(track => track.stop())
|
||||
welcome (state) {
|
||||
state.welcomed = true;
|
||||
},
|
||||
startCamera (state, mediaStream) {
|
||||
state.mediaStream = mediaStream
|
||||
},
|
||||
stopCamera (state) {
|
||||
if (state.mediaStream) {
|
||||
state.mediaStream.getTracks().forEach(track => track.stop())
|
||||
}
|
||||
|
||||
store.mediaStream = mediaStream
|
||||
},
|
||||
inverseFacingMode (store) {
|
||||
store.capturing.shouldFaceUser = !store.capturing.shouldFaceUser
|
||||
},
|
||||
updateTimer (store, time) {
|
||||
store.timer.selected = time
|
||||
|
@ -69,17 +78,31 @@ export default new Vuex.Store({
|
|||
}
|
||||
},
|
||||
actions: {
|
||||
requestCamera ({ commit }) {
|
||||
const constaints = {
|
||||
welcome ({ commit, dispatch }) {
|
||||
commit('welcome')
|
||||
dispatch('requestCamera', false)
|
||||
},
|
||||
requestCamera ({ state, commit }, inverseFacingMode) {
|
||||
const shouldFaceUser = inverseFacingMode
|
||||
? !state.capturing.shouldFaceUser
|
||||
: state.capturing.shouldFaceUser
|
||||
|
||||
const constraints = {
|
||||
video: {
|
||||
facingMode: 'user'
|
||||
facingMode: shouldFaceUser ? 'user' : 'environment'
|
||||
},
|
||||
audio: false
|
||||
}
|
||||
|
||||
navigator.mediaDevices.getUserMedia(constaints)
|
||||
commit('stopCamera')
|
||||
|
||||
navigator.mediaDevices.getUserMedia(constraints)
|
||||
.then(mediaStream => {
|
||||
commit('updateMediaStream', mediaStream)
|
||||
commit('startCamera', mediaStream)
|
||||
|
||||
if (inverseFacingMode) {
|
||||
commit('inverseFacingMode')
|
||||
}
|
||||
})
|
||||
.catch(error => console.error(error))
|
||||
},
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
{{ timeLabel(time) }}
|
||||
</option>
|
||||
</select>
|
||||
<button class="options__btn" :disabled="encoding.status" @click="back"><icon-switch></icon-switch>switch</button>
|
||||
<button class="options__btn" :disabled="encoding.status" @click="switchCamera"><icon-switch></icon-switch>switch</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -26,8 +26,8 @@ export default {
|
|||
])
|
||||
},
|
||||
methods: {
|
||||
back () {
|
||||
this.$store.commit('updateMediaStream', null)
|
||||
switchCamera () {
|
||||
this.$store.dispatch('requestCamera', true)
|
||||
},
|
||||
timeLabel (time) {
|
||||
return time + 's'
|
||||
|
|
|
@ -17,7 +17,7 @@ export default {
|
|||
name: 'welcome',
|
||||
methods: {
|
||||
welcome () {
|
||||
this.$store.dispatch('requestCamera')
|
||||
this.$store.dispatch('welcome')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue