2019-03-08 23:17:59 +01:00
|
|
|
import Vue from 'vue'
|
|
|
|
import Vuex from 'vuex'
|
|
|
|
|
2019-03-22 17:30:04 +01:00
|
|
|
import { getCamera } from '/services/camera.js'
|
2019-03-10 04:13:25 +01:00
|
|
|
|
2019-03-08 23:17:59 +01:00
|
|
|
Vue.use(Vuex)
|
|
|
|
|
|
|
|
export default new Vuex.Store({
|
2019-03-12 10:34:41 +01:00
|
|
|
strict: process.env.NODE_ENV !== 'production',
|
2019-03-08 23:17:59 +01:00
|
|
|
state: {
|
2019-04-05 17:46:36 +02:00
|
|
|
cameraShouldFaceUser: true,
|
2019-03-29 17:17:42 +01:00
|
|
|
duration: {
|
2019-03-09 22:54:07 +01:00
|
|
|
selected: 2,
|
|
|
|
list: [2, 3, 5]
|
2019-03-10 00:14:30 +01:00
|
|
|
},
|
2019-03-29 17:17:42 +01:00
|
|
|
boomerang: false,
|
2019-04-23 00:41:01 +02:00
|
|
|
timer: 0,
|
2019-04-05 17:46:36 +02:00
|
|
|
camera: null,
|
|
|
|
capture: null,
|
2019-04-06 21:18:18 +02:00
|
|
|
gif: null,
|
|
|
|
needRefresh: false
|
2019-03-08 23:17:59 +01:00
|
|
|
},
|
|
|
|
mutations: {
|
2019-04-05 17:46:36 +02:00
|
|
|
updateCameraShouldFaceUser (state, cameraShouldFaceUser) {
|
|
|
|
state.cameraShouldFaceUser = cameraShouldFaceUser
|
2019-03-09 22:54:07 +01:00
|
|
|
},
|
2019-03-29 17:17:42 +01:00
|
|
|
updateDuration (state, time) {
|
|
|
|
state.duration.selected = time
|
|
|
|
},
|
|
|
|
updateBoomerang (state, value) {
|
|
|
|
state.boomerang = value
|
2019-03-10 00:14:30 +01:00
|
|
|
},
|
2019-04-23 00:41:01 +02:00
|
|
|
updateTimer (state, value) {
|
|
|
|
state.timer = value
|
|
|
|
},
|
2019-04-05 17:46:36 +02:00
|
|
|
updateCamera (state, camera) {
|
|
|
|
if (state.camera) {
|
|
|
|
state.camera.mediaStream.getTracks().forEach(track => track.stop())
|
2019-03-10 23:35:26 +01:00
|
|
|
}
|
2019-04-05 17:46:36 +02:00
|
|
|
state.camera = camera
|
|
|
|
},
|
|
|
|
updateCapture (state, capture) {
|
|
|
|
state.capture = capture
|
|
|
|
},
|
|
|
|
updateGif (state, gif) {
|
|
|
|
state.gif = gif
|
2019-04-06 21:18:18 +02:00
|
|
|
},
|
|
|
|
updateRefreshBanner (state, value) {
|
|
|
|
state.needRefresh = value
|
2019-03-09 22:54:07 +01:00
|
|
|
}
|
2019-03-08 23:17:59 +01:00
|
|
|
},
|
|
|
|
actions: {
|
2019-03-22 17:30:04 +01:00
|
|
|
async requestCamera ({ state, commit }, inverseFacingMode) {
|
2019-04-05 17:46:36 +02:00
|
|
|
commit('updateCamera', null)
|
2019-03-22 17:30:04 +01:00
|
|
|
|
2019-03-12 17:41:30 +01:00
|
|
|
const shouldFaceUser = inverseFacingMode
|
2019-04-05 17:46:36 +02:00
|
|
|
? !state.cameraShouldFaceUser
|
|
|
|
: state.cameraShouldFaceUser
|
|
|
|
|
|
|
|
commit('updateCamera', await getCamera(shouldFaceUser))
|
2019-03-12 17:41:30 +01:00
|
|
|
|
2019-04-05 04:03:08 +02:00
|
|
|
if (inverseFacingMode) {
|
2019-04-05 17:46:36 +02:00
|
|
|
commit('updateCameraShouldFaceUser', shouldFaceUser)
|
2019-03-22 17:30:04 +01:00
|
|
|
}
|
2019-03-10 02:28:07 +01:00
|
|
|
}
|
2019-03-08 23:17:59 +01:00
|
|
|
}
|
|
|
|
})
|