add events for gateway connection and fix vue warns

This commit is contained in:
hippoz 2020-11-16 21:33:03 +02:00
parent 046b4d2b01
commit efffd3bc66
3 changed files with 16 additions and 2 deletions

View file

@ -15,6 +15,7 @@ class GatewayServer {
GatewayServer.prototype.authDisconnect = function(socket, callback) { GatewayServer.prototype.authDisconnect = function(socket, callback) {
socket.isConnected = false; socket.isConnected = false;
socket.disconnect();
socket.disconnect(true); socket.disconnect(true);
callback(new Error('ERR_GATEWAY_AUTH_FAIL')); callback(new Error('ERR_GATEWAY_AUTH_FAIL'));
}; };
@ -26,6 +27,7 @@ GatewayServer.prototype.eventSetup = function() {
setTimeout(() => { setTimeout(() => {
console.log('[*] [gateway] User still not connected after timeout, removing...'); console.log('[*] [gateway] User still not connected after timeout, removing...');
socket.disconnect();
socket.disconnect(true); socket.disconnect(true);
}, config.gatewayStillNotConnectedTimeoutMS); }, config.gatewayStillNotConnectedTimeoutMS);

View file

@ -97,7 +97,7 @@
</md-toolbar> </md-toolbar>
<div id="posts-container" v-if="selection.category.browsing"> <div id="posts-container" v-if="selection.category.browsing">
<md-card v-for="post in selection.posts"> <md-card v-for="post in selection.posts" v-bind:key="post._id">
<md-card-header> <md-card-header>
<div class="md-title" v-html="post.title"></div> <div class="md-title" v-html="post.title"></div>
<span>by <a class="md-dense cursor" v-on:click="viewProfile(post.creator._id)">{{ post.creator.username }}</a></span> <span>by <a class="md-dense cursor" v-on:click="viewProfile(post.creator._id)">{{ post.creator.username }}</a></span>
@ -106,7 +106,7 @@
<md-card-content v-html="post.body"></md-card-content> <md-card-content v-html="post.body"></md-card-content>
<md-card-actions> <md-card-actions>
<md-button v-for="button in cardButtons" @click="button.click(post)">{{ button.text }}</md-button> <md-button v-for="button in cardButtons" v-bind:key="button.text" @click="button.click(post)">{{ button.text }}</md-button>
</md-card-actions> </md-card-actions>
</md-card> </md-card>
</div> </div>

View file

@ -57,6 +57,10 @@ class GatewayConnection {
constructor() { constructor() {
this.isConnected = false; this.isConnected = false;
this.socket = null; 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', () => { this.socket.on('hello', () => {
console.log('[*] [gateway] [handshake] Got hello from server, sending yoo...'); console.log('[*] [gateway] [handshake] Got hello from server, sending yoo...');
this.socket.emit('yoo'); this.socket.emit('yoo');
this.onConnect('CONNECT_RECEIVED_HELLO');
}); });
this.socket.on('error', (e) => { this.socket.on('error', (e) => {
console.log('[E] [gateway] Gateway error', e); console.log('[E] [gateway] Gateway error', e);
this.isConnected = false; this.isConnected = false;
this.onDisconnect('DISCONNECT_ERR', e);
}); });
this.socket.on('disconnectNotification', (e) => { this.socket.on('disconnectNotification', (e) => {
console.log('[E] [gateway] Received disconnect notfication', e); console.log('[E] [gateway] Received disconnect notfication', e);
this.isConnected = false; this.isConnected = false;
this.onDisconnect('DISCONNECT_NOTIF', e);
}); });
this.socket.on('disconnect', (e) => { this.socket.on('disconnect', (e) => {
console.log('[E] [gateway] Disconnected from gateway: ', e); console.log('[E] [gateway] Disconnected from gateway: ', e);
this.isConnected = false; this.isConnected = false;
this.onDisconnect('DISCONNECT', e);
}); });
}; };
@ -192,6 +200,10 @@ const app = new Vue({
}, },
performGatewayConnection: function() { 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 // 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); this.gateway.connect(this.loggedInUser.token);
}, },
button: function(text, click) { button: function(text, click) {