ffplayout/store/config.js

113 lines
3.5 KiB
JavaScript
Raw Normal View History

2020-04-09 18:30:28 +02:00
export const state = () => ({
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 = {
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]) {
if (response.data[0].extra_extensions) {
2020-07-06 11:55:30 +02:00
response.data[0].extra_extensions = response.data[0].extra_extensions.split(',')
} else {
response.data[0].extra_extensions = []
}
2020-04-16 18:29:44 +02:00
commit('UPDATE_GUI_CONFIG', response.data[0])
} else {
commit('UPDATE_GUI_CONFIG', {
id: 0,
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) {
2020-04-16 18:29:44 +02:00
const stringObj = JSON.parse(JSON.stringify(obj))
2020-07-06 11:55:30 +02:00
stringObj.extra_extensions = obj.extra_extensions.join(',')
let response
if (state.configPlayout.length === 0) {
response = await this.$axios.post('api/player/guisettings/', stringObj)
} else {
response = await this.$axios.put(`api/player/guisettings/${obj.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
}
}