streaming-frontend/src/store.js

97 lines
2.4 KiB
JavaScript

import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
import io from 'socket.io-client'
Vue.use(Vuex)
const API_HOST = '10.8.0.95'
const api = axios.create({
baseURL: 'http://' + API_HOST + ':5000/api/1',
timeout: 1000
})
export default new Vuex.Store({
state: {
feeds: {},
images: {},
scenes: {}
},
getters: {
scenes: state => state.scenes
},
mutations: {
LOAD_SCENES (state, data) {
console.info('Scenes:', data)
state.scenes = data
},
LOAD_IMAGES (state, data) {
console.info('Images:', data)
state.images = data
},
LOAD_FEEDS (state, data) {
console.info('Feeds:', data)
state.feeds = data
}
},
actions: {
initialize ({ commit }) {
this.socket = io('http://' + API_HOST + ':5000')
this.socket.on('connect', () => {
console.log('Socket.IO connected:', this.socket.id)
})
this.socket.on('feeds', (data) => commit('LOAD_FEEDS', data))
this.socket.on('scenes', (data) => commit('LOAD_SCENES', data))
this.socket.on('images', (data) => commit('LOAD_IMAGES', data))
},
setSceneAlpha ({ commit }, [scene, type, alpha]) {
console.info(scene.id, type, alpha)
if (!type) {
type = ''
} else {
type += '_'
}
scene[type + 'alpha'] = alpha
this.socket.emit('scene_mod', {
'id': scene.id,
[type + 'alpha']: alpha
})
},
setFrameAlpha ({ commit }, [sceneId, frameId, side, alpha]) {
console.info('Setting alpha for', frameId, alpha)
this.state.scenes[sceneId].frames[frameId][side].alpha = alpha
return api.patch('/scenes/' + sceneId + '/' + frameId, {
[side]: {
'alpha': alpha
}
})
},
setFrameSource ({ commit }, [sceneId, frameId, side, source]) {
return api.patch('/scenes/' + sceneId + '/' + frameId, {
[side]: {
'source': source
}
})
},
setFrameActive ({ commit }, [sceneId, frameId, active]) {
return api.patch('/scenes/' + sceneId + '/' + frameId, {
'active': active
})
},
sceneFade ({ commit }, scene) {
this.socket.emit('scene_fade', { id: scene.id })
console.info('Fading', scene)
},
sceneCut ({ commit }, scene) {
this.socket.emit('scene_cut', { id: scene.id })
console.info('Cutting', scene)
}
}
})