websocket implementation

This commit is contained in:
Čarodej
2022-03-09 07:40:05 +01:00
parent 2a0b01e888
commit 8495ed5422
15 changed files with 1816 additions and 226 deletions
+32
View File
@@ -0,0 +1,32 @@
const defaultState = {
isRunningConnection: false,
}
const actions = {
runConnection: ({ commit, getters }) => {
commit('SET_RUNNING_COMMUNICATION')
Echo.private(`test.${getters.user.data.id}`)
.listen('.Domain\\Notifications\\Events\\TestUpdate', (e) => {
console.log(e);
});
},
}
const mutations = {
SET_RUNNING_COMMUNICATION(state) {
state.isRunningConnection = true
},
}
const getters = {
isRunningConnection: (state) => state.isRunningConnection,
}
export default {
state: defaultState,
getters,
actions,
mutations,
}
+5 -1
View File
@@ -10,7 +10,7 @@ const defaultState = {
}
const actions = {
getAppData: ({ commit, getters }) => {
getAppData: ({ commit, getters, dispatch }) => {
return new Promise((resolve, reject) => {
axios
.get(getters.api + '/user' + getters.sorting.URI)
@@ -18,6 +18,10 @@ const actions = {
resolve(response)
commit('RETRIEVE_USER', response.data)
if (! getters.isRunningConnection) {
dispatch('runConnection')
}
})
.catch((error) => {
reject(error)