Move chat to own module.
This commit is contained in:
parent
0e51fac2b2
commit
27be1e0fa3
5 changed files with 55 additions and 22 deletions
|
@ -1,10 +1,12 @@
|
|||
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
|
||||
import {isArray} from 'lodash'
|
||||
import { Socket } from 'phoenix'
|
||||
|
||||
const api = {
|
||||
state: {
|
||||
backendInteractor: backendInteractorService(),
|
||||
fetchers: {}
|
||||
fetchers: {},
|
||||
socket: null
|
||||
},
|
||||
mutations: {
|
||||
setBackendInteractor (state, backendInteractor) {
|
||||
|
@ -15,6 +17,9 @@ const api = {
|
|||
},
|
||||
removeFetcher (state, {timeline}) {
|
||||
delete state.fetchers[timeline]
|
||||
},
|
||||
setSocket (state, socket) {
|
||||
state.socket = socket
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
|
@ -37,6 +42,12 @@ const api = {
|
|||
const fetcher = store.state.fetchers[timeline]
|
||||
window.clearInterval(fetcher)
|
||||
store.commit('removeFetcher', {timeline})
|
||||
},
|
||||
initializeSocket (store, token) {
|
||||
// Set up websocket connection
|
||||
let socket = new Socket('/socket', {params: {token: token}})
|
||||
socket.connect()
|
||||
store.dispatch('initializeChat', socket)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue