forked from hippoz/brainlet
add events for gateway connection and fix vue warns
This commit is contained in:
parent
046b4d2b01
commit
efffd3bc66
3 changed files with 16 additions and 2 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@
|
|||
</md-toolbar>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
|
@ -106,7 +106,7 @@
|
|||
<md-card-content v-html="post.body"></md-card-content>
|
||||
|
||||
<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>
|
||||
</div>
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue