2019-03-08 22:17:59 +00:00
|
|
|
import Vue from 'vue'
|
|
|
|
import Vuex from 'vuex'
|
|
|
|
|
2019-03-10 03:13:25 +00:00
|
|
|
import { capture } from './services/capture.js'
|
|
|
|
import { encode } from './services/encode.js'
|
|
|
|
|
2019-03-08 22:17:59 +00:00
|
|
|
Vue.use(Vuex)
|
|
|
|
|
|
|
|
export default new Vuex.Store({
|
|
|
|
state: {
|
2019-03-10 01:28:07 +00:00
|
|
|
mediaStream: null,
|
2019-03-09 21:54:07 +00:00
|
|
|
timer: {
|
|
|
|
selected: 2,
|
|
|
|
list: [2, 3, 5]
|
2019-03-09 23:14:30 +00:00
|
|
|
},
|
|
|
|
capturing: {
|
|
|
|
status: false,
|
|
|
|
state: 0
|
2019-03-09 23:28:47 +00:00
|
|
|
},
|
|
|
|
encoding: {
|
|
|
|
status: false
|
2019-03-09 23:55:37 +00:00
|
|
|
},
|
|
|
|
downloading: {
|
|
|
|
status: false
|
2019-03-09 21:54:07 +00:00
|
|
|
}
|
2019-03-08 22:17:59 +00:00
|
|
|
},
|
|
|
|
mutations: {
|
2019-03-10 03:13:25 +00:00
|
|
|
updateMediaStream (store, mediaStream) {
|
2019-03-10 01:28:07 +00:00
|
|
|
if (store.mediaStream) {
|
|
|
|
store.mediaStream.getTracks().forEach(track => track.stop())
|
|
|
|
}
|
|
|
|
|
|
|
|
store.mediaStream = mediaStream
|
2019-03-09 21:54:07 +00:00
|
|
|
},
|
|
|
|
updateTimer (store, time) {
|
|
|
|
store.timer.selected = time
|
2019-03-09 23:14:30 +00:00
|
|
|
},
|
|
|
|
startCapture (store) {
|
|
|
|
store.capturing.status = true
|
|
|
|
},
|
|
|
|
stopCapture (store) {
|
|
|
|
store.capturing.status = false
|
|
|
|
},
|
|
|
|
updateCaptureState (store, percent) {
|
|
|
|
store.capturing.state = percent
|
2019-03-09 23:28:47 +00:00
|
|
|
},
|
|
|
|
startEncoding (store) {
|
|
|
|
store.encoding.status = true
|
|
|
|
},
|
|
|
|
stopEncoding (store) {
|
|
|
|
store.encoding.status = false
|
2019-03-09 23:55:37 +00:00
|
|
|
},
|
|
|
|
startDownloading (store) {
|
|
|
|
store.downloading.status = true
|
|
|
|
},
|
|
|
|
stopDownloading (store) {
|
|
|
|
store.downloading.status = false
|
2019-03-09 21:54:07 +00:00
|
|
|
}
|
2019-03-08 22:17:59 +00:00
|
|
|
},
|
|
|
|
actions: {
|
2019-03-10 01:28:07 +00:00
|
|
|
requestCamera ({ commit }) {
|
|
|
|
navigator.mediaDevices.getUserMedia({ video: true, audio: false })
|
|
|
|
.then(mediaStream => {
|
|
|
|
commit('updateMediaStream', mediaStream)
|
|
|
|
})
|
|
|
|
.catch(error => console.error(error))
|
2019-03-10 03:13:25 +00:00
|
|
|
},
|
|
|
|
capture ({ commit, dispatch, state }) {
|
|
|
|
commit('startCapture')
|
|
|
|
|
|
|
|
capture(commit, state.mediaStream, state.timer.selected * 1000)
|
|
|
|
.then(captureData => {
|
|
|
|
commit('stopCapture')
|
|
|
|
commit('updateCaptureState', 0)
|
|
|
|
dispatch('encode', captureData)
|
|
|
|
})
|
|
|
|
.catch(error => console.error(error))
|
|
|
|
},
|
|
|
|
encode ({ commit }, captureData) {
|
|
|
|
commit('startEncoding')
|
|
|
|
|
|
|
|
console.log(captureData)
|
|
|
|
|
|
|
|
encode(captureData)
|
|
|
|
.then(clipDataUrl => {
|
|
|
|
commit('stopEncoding')
|
|
|
|
commit('startDownloading')
|
|
|
|
console.log(clipDataUrl)
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error)
|
|
|
|
commit('stopEncoding')
|
|
|
|
commit('startDownloading')
|
|
|
|
})
|
2019-03-10 01:28:07 +00:00
|
|
|
}
|
2019-03-08 22:17:59 +00:00
|
|
|
}
|
|
|
|
})
|