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