Parcourir la source

Disconnect and reconnect on login, logout and account creation to fix socket.io notification issues

sbkwgh il y a 7 ans
Parent
commit
f8a6689a97
3 fichiers modifiés avec 15 ajouts et 10 suppressions
  1. 4 2
      frontend/src/App.vue
  2. 9 0
      frontend/src/main.js
  3. 2 8
      lib/sockets.js

+ 4 - 2
frontend/src/App.vue

@@ -245,6 +245,8 @@
 					this.$store.commit('setUsername', '')
 					this.$store.commit('setAdmin', res.data.admin)
 
+					socket.emit('accountEvent')
+
 					this.$router.push('/')
 				}).catch(err => {
 					this.loadingLogout = false
@@ -301,7 +303,7 @@
 						this.$store.commit('setAdmin', res.data.admin)
 						this.closeAccountModal()
 
-						socket.emit('login')
+						socket.emit('accountEvent')
 					}).catch(e => {
 						this.signup.loading = false
 
@@ -333,7 +335,7 @@
 					this.$store.commit('setAdmin', res.data.admin)
 					this.closeAccountModal()
 
-					socket.emit('login')
+					socket.emit('accountEvent')
 				}).catch(e => {
 					this.login.loading = false
 					this.ajaxErrorHandler(e, (error) => {

+ 9 - 0
frontend/src/main.js

@@ -1,6 +1,15 @@
 import IO from 'socket.io-client'
 window.socket = IO()
 
+socket.on('disconnect', () => {
+	socket.connect('http://localhost:3000', {
+		reconnection: true,
+		reconnectionDelay: 1000,
+		reconnectionDelayMax : 5000,
+		reconnectionAttempts: Infinity
+	} );
+})
+
 import Vue from 'vue'
 import VueRouter from 'vue-router'
 import Vuex from 'vuex'

+ 2 - 8
lib/sockets.js

@@ -27,14 +27,8 @@ module.exports = {
 				socket.leave(room)
 			})
 
-			socket.on('login', _ => {
-				socket.handshake.session.reload(err => {
-					if(!err) {
-						setIoSockets(socket)
-					} else {
-						console.log(err)
-					}
-				})
+			socket.on('accountEvent', _ => {
+				socket.disconnect()
 			})
 		})