1
0
Fork 0

[client] Fix phantom disconnect on page load

This commit is contained in:
Starbeamrainbowlabs 2017-06-27 10:57:50 +01:00
parent 41e6b46311
commit eeee26e720
1 changed files with 9 additions and 0 deletions

View File

@ -15,7 +15,12 @@ class RippleLink extends EventEmitter
this.settings = this.boardWindow.settings;
// Create the websocket and commect to the server
// Whether the link ot the nibri server is open or not
this.linkOpen = false;
// The underlying websocket
this.websocket = new WebSocket(this.socketUrl, [ this.settings.WebsocketProtocol ]);
// Attach some event listeners
this.websocket.addEventListener("open", this.handleConnection.bind(this));
this.websocket.addEventListener("message", this.handleMessage.bind(this));
this.websocket.addEventListener("close", this.handleDisconnection.bind(this));
@ -32,11 +37,15 @@ class RippleLink extends EventEmitter
handleConnection(event) {
console.info("[ripple link] Established connection successfully.");
this.linkOpen = true;
// Tell everyone about it
this.emit("connect", event);
}
handleDisconnection(event) {
// If the link was already down, then ignore this phantom disconnection
if(!this.linkOpen)
return;
console.error("[ripple link] Lost connection.");
this.boardWindow.interface.setConnectedStatus(false);