refactor(navigation): better camera usage

This commit is contained in:
wryk 2019-03-18 15:25:20 +01:00
parent 0ab48094fc
commit 061b739ad2
4 changed files with 18 additions and 14 deletions

View file

@ -31,10 +31,6 @@ export default {
handleVisibilityChange (event) {
if (document.hidden) {
this.$store.commit('stopCamera')
} else {
if (this.welcomed) {
this.$store.dispatch('requestCamera', false)
}
}
}
},

View file

@ -84,10 +84,6 @@ export default new Vuex.Store({
}
},
actions: {
welcome ({ commit, dispatch }) {
commit('updateWelcomed', true)
dispatch('requestCamera', false)
},
requestCamera ({ state, commit }, inverseFacingMode) {
const shouldFaceUser = inverseFacingMode
? !state.capturing.shouldFaceUser
@ -136,10 +132,7 @@ export default new Vuex.Store({
encoding.once('error', error => console.error(error))
encoding.on('progress', value => {
console.log(`Encoding progress ${Math.round(value * 100)}% (${value})`)
commit('updateEncodingState', Math.round(value * 100))
})
encoding.on('progress', value => commit('updateEncodingState', Math.round(value * 100)))
encoding.once('done', objectUrl => {
commit('stopEncoding')

View file

@ -43,6 +43,16 @@ export default {
startCapture () {
this.$store.dispatch('capture')
},
ensureCameraStarted () {
if (!this.mediaStream) {
this.$store.dispatch('requestCamera', false)
}
},
handleVisibilityChange (event) {
if (!document.hidden) {
this.ensureCameraStarted()
}
},
updatePreviewMediaStream() {
this.$refs.preview.srcObject = this.mediaStream
}
@ -54,14 +64,19 @@ export default {
},
mounted: function () {
this.updatePreviewMediaStream()
window.objectFitPolyfill(this.$refs.preview)
document.addEventListener('visibilitychange', this.handleVisibilityChange)
document.body.classList.add('capture-body')
window.objectFitPolyfill(this.$refs.preview)
this.ensureCameraStarted()
},
updated: function () {
this.updatePreviewMediaStream()
},
destroyed: function () {
document.body.classList.remove('capture-body')
document.removeEventListener('visibilitychange', this.handleVisibilityChange)
}
}
</script>

View file

@ -23,7 +23,7 @@ export default {
},
methods: {
welcome () {
this.$store.dispatch('welcome')
this.$store.commit('updateWelcomed', true)
}
}
}