ffplayout/store/config.js

126 lines
3.9 KiB
JavaScript
Raw Normal View History

2020-04-09 18:30:28 +02:00
export const state = () => ({
configID: 0,
configCount: 0,
2020-04-15 18:11:29 +02:00
configGui: null,
netChoices: [],
configPlayout: [],
2020-04-15 18:11:29 +02:00
currentUser: null,
configUser: null
2020-04-09 18:30:28 +02:00
})
export const mutations = {
UPDATE_CONFIG_ID (state, id) {
state.configID = id
},
UPDATE_CONFIG_COUNT (state, count) {
state.configCount = count
},
2020-04-15 18:11:29 +02:00
UPDATE_GUI_CONFIG (state, config) {
state.configGui = config
},
UPDATE_NET_CHOICES (state, list) {
state.netChoices = list
},
UPDATE_PLAYLOUT_CONFIG (state, config) {
state.configPlayout = config
},
SET_CURRENT_USER (state, user) {
state.currentUser = user
},
UPDATE_USER_CONFIG (state, config) {
state.configUser = config
2020-04-09 18:30:28 +02:00
}
}
export const actions = {
2020-05-24 13:34:34 +02:00
async nuxtClientInit ({ commit, dispatch, rootState }) {
2020-05-24 17:51:28 +02:00
await dispatch('auth/inspectToken', null, { root: true })
2020-05-24 13:34:34 +02:00
if (rootState.auth.isLogin) {
await dispatch('getGuiConfig')
await dispatch('getPlayoutConfig')
await dispatch('getUserConfig')
}
},
2020-04-30 10:53:13 +02:00
async getGuiConfig ({ commit, state }) {
const options = await this.$axios.options('api/player/guisettings/')
const response = await this.$axios.get('api/player/guisettings/')
2020-04-15 18:11:29 +02:00
if (options.data) {
const choices = options.data.actions.POST.net_interface.choices.map(function (obj) {
obj.text = obj.display_name
delete obj.display_name
return obj
})
commit('UPDATE_NET_CHOICES', choices)
}
if (response.data && response.data[0]) {
for (const data of response.data) {
if (data.extra_extensions) {
data.extra_extensions = data.extra_extensions.split(',')
} else {
data.extra_extensions = []
}
}
commit('UPDATE_GUI_CONFIG', response.data)
commit('UPDATE_CONFIG_COUNT', response.data.length)
} else {
commit('UPDATE_GUI_CONFIG', [{
id: 1,
channel: '',
player_url: '',
playout_config: '',
net_interface: '',
media_disk: '',
extra_extensions: []
}])
2020-04-15 18:11:29 +02:00
}
},
2020-04-30 10:53:13 +02:00
async setGuiConfig ({ commit, state }, obj) {
const stringObj = JSON.parse(JSON.stringify(obj[state.configID]))
stringObj.extra_extensions = stringObj.extra_extensions.join(',')
let response
if (state.configPlayout.length === 0 || state.configCount !== stringObj.length) {
response = await this.$axios.post('api/player/guisettings/', stringObj)
} else {
response = await this.$axios.put(`api/player/guisettings/${obj[state.configID].id}/`, stringObj)
}
2020-05-24 13:34:34 +02:00
return response
2020-04-15 18:11:29 +02:00
},
2020-04-30 10:53:13 +02:00
async getPlayoutConfig ({ commit, state }) {
const response = await this.$axios.get('api/player/config/?configPlayout')
2020-04-15 18:11:29 +02:00
if (response.data) {
commit('UPDATE_PLAYLOUT_CONFIG', response.data)
}
},
2020-04-30 10:53:13 +02:00
async setPlayoutConfig ({ commit, state }, obj) {
const update = await this.$axios.post('api/player/config/?configPlayout', { data: obj })
2020-04-16 18:29:44 +02:00
return update
2020-04-15 18:11:29 +02:00
},
2020-04-09 18:30:28 +02:00
2020-04-30 10:53:13 +02:00
async getUserConfig ({ commit, state }) {
2020-05-04 12:16:04 +02:00
const user = await this.$axios.get('api/player/user/current/')
const response = await this.$axios.get(`api/player/user/users/?username=${user.data.username}`)
2020-04-15 18:11:29 +02:00
if (user.data) {
commit('SET_CURRENT_USER', user.data.username)
}
2020-04-09 18:30:28 +02:00
if (response.data) {
2020-04-16 18:29:44 +02:00
commit('UPDATE_USER_CONFIG', response.data[0])
2020-04-09 18:30:28 +02:00
}
},
2020-04-30 10:53:13 +02:00
async setUserConfig ({ commit, state }, obj) {
2020-05-04 12:16:04 +02:00
const update = await this.$axios.put(`api/player/user/users/${obj.id}/`, obj)
2020-04-16 18:29:44 +02:00
return update
2020-04-09 18:30:28 +02:00
}
}