diff options
| author | slice <ryaneft@gmail.com> | 2019-03-10 11:23:27 -0700 |
|---|---|---|
| committer | slice <ryaneft@gmail.com> | 2019-03-10 11:25:36 -0700 |
| commit | e618c6ffb0b974156b89f3e54737e738e94b12b3 (patch) | |
| tree | 5197a0bc55ac81cad80e05686bb664c644da9109 /src/modules/chat.js | |
| parent | a67881b096dc4e49db804b7267c3bf49ff78bca6 (diff) | |
Only connect to chat when authenticating in the first place
To avoid duplication of the connection, the chat socket is destroyed
upon logging out.
Diffstat (limited to 'src/modules/chat.js')
| -rw-r--r-- | src/modules/chat.js | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/modules/chat.js b/src/modules/chat.js index 383ac75c..2804e577 100644 --- a/src/modules/chat.js +++ b/src/modules/chat.js @@ -1,12 +1,16 @@ const chat = { state: { messages: [], - channel: {state: ''} + channel: {state: ''}, + socket: null }, mutations: { setChannel (state, channel) { state.channel = channel }, + setSocket (state, socket) { + state.socket = socket + }, addMessage (state, message) { state.messages.push(message) state.messages = state.messages.slice(-19, 20) @@ -16,8 +20,12 @@ const chat = { } }, actions: { + disconnectFromChat (store) { + store.state.socket.disconnect() + }, initializeChat (store, socket) { const channel = socket.channel('chat:public') + store.commit('setSocket', socket) channel.on('new_msg', (msg) => { store.commit('addMessage', msg) }) |
