diff --git a/api/v1/gateway/index.js b/api/v1/gateway/index.js index d4c504f..f7263cf 100644 --- a/api/v1/gateway/index.js +++ b/api/v1/gateway/index.js @@ -15,6 +15,7 @@ class GatewayServer { GatewayServer.prototype.authDisconnect = function(socket, callback) { socket.isConnected = false; + socket.disconnect(); socket.disconnect(true); callback(new Error('ERR_GATEWAY_AUTH_FAIL')); }; @@ -26,6 +27,7 @@ GatewayServer.prototype.eventSetup = function() { setTimeout(() => { console.log('[*] [gateway] User still not connected after timeout, removing...'); + socket.disconnect(); socket.disconnect(true); }, config.gatewayStillNotConnectedTimeoutMS); diff --git a/app/app.html b/app/app.html index 121f5eb..9f05b32 100755 --- a/app/app.html +++ b/app/app.html @@ -97,7 +97,7 @@
- +
by {{ post.creator.username }} @@ -106,7 +106,7 @@ - {{ button.text }} + {{ button.text }}
diff --git a/app/resources/js/app.js b/app/resources/js/app.js index 788ba8c..6d60a21 100755 --- a/app/resources/js/app.js +++ b/app/resources/js/app.js @@ -57,6 +57,10 @@ class GatewayConnection { constructor() { this.isConnected = false; this.socket = null; + + // TODO: set up proper event listening and such, not this dumb crap + this.onDisconnect = () => {} + this.onConnect = () => {} } } @@ -72,19 +76,23 @@ GatewayConnection.prototype.connect = function(token) { this.socket.on('hello', () => { console.log('[*] [gateway] [handshake] Got hello from server, sending yoo...'); this.socket.emit('yoo'); + this.onConnect('CONNECT_RECEIVED_HELLO'); }); this.socket.on('error', (e) => { console.log('[E] [gateway] Gateway error', e); this.isConnected = false; + this.onDisconnect('DISCONNECT_ERR', e); }); this.socket.on('disconnectNotification', (e) => { console.log('[E] [gateway] Received disconnect notfication', e); this.isConnected = false; + this.onDisconnect('DISCONNECT_NOTIF', e); }); this.socket.on('disconnect', (e) => { console.log('[E] [gateway] Disconnected from gateway: ', e); this.isConnected = false; + this.onDisconnect('DISCONNECT', e); }); }; @@ -192,6 +200,10 @@ const app = new Vue({ }, performGatewayConnection: function() { // TODO: again, the thing im doing with the token is not very secure, since its being sent by the current user info endpoint and is also being send through query parameters + this.gateway.onDisconnect = (e) => { + this.resetSnackbarButton(); + this.notification('ERROR: You have been disconnected from the gateway. Realtime features such as chat will not work and unexpected errors may occur.'); + }; this.gateway.connect(this.loggedInUser.token); }, button: function(text, click) {