diff --git a/bfrontend/src/API/Gateway/GatewayConnection.js b/bfrontend/src/API/Gateway/GatewayConnection.js index a1dbb99..49701ae 100644 --- a/bfrontend/src/API/Gateway/GatewayConnection.js +++ b/bfrontend/src/API/Gateway/GatewayConnection.js @@ -63,6 +63,8 @@ GatewayConnection.prototype.connect = function(token) { if (token) this.token = token; if (this.token) token = this.token; + this.connectionAttemptStartedTime = new Date(); + this.ws = new WebSocket(this.gatewayUrl); this.handshakeCompleted = false; @@ -73,7 +75,7 @@ GatewayConnection.prototype.connect = function(token) { this.ws.onclose = (e) => { this.handshakeCompleted = false; logGateway(`Close: ${e.code}:${e.reason}`); - this.fire("onclose", e); + this.fire("onclose", e.code); }; this.ws.onmessage = async (message) => { try { @@ -107,7 +109,8 @@ GatewayConnection.prototype.connect = function(token) { logGateway("Got YOO_ACK", packet.data); this.handshakeCompleted = true; this.sessionInformation = packet.data; - logGateway("Handshake complete"); + this.handshakeCompletedTime = (new Date()).getTime() - this.connectionAttemptStartedTime.getTime(); + logGateway(`Handshake complete in ${this.handshakeCompletedTime}ms`); this.fire("onopen", packet.data); break; } diff --git a/bfrontend/src/API/Gateway/globalGatewayConnection.js b/bfrontend/src/API/Gateway/globalGatewayConnection.js index e8c2f42..d1648b3 100644 --- a/bfrontend/src/API/Gateway/globalGatewayConnection.js +++ b/bfrontend/src/API/Gateway/globalGatewayConnection.js @@ -26,7 +26,6 @@ globalGatewayConnection.onopen = (sessionData) => { ...experimentModifiers || {} }; store.dispatch({ type: 'application/updateexperiments', experiments }); - store.dispatch({ type: 'application/updatebannertext', text: "Experiment overrides are enabled! Things could go haywire!" }); } else { store.dispatch({ type: 'application/updateexperiments', experiments: sessionData.__global_experiments || {} }); } @@ -40,16 +39,26 @@ globalGatewayConnection.presenceUpdate = (presence) => { store.dispatch({ type: 'channels/updatepresence', clientListEvent: presence }); }; -globalGatewayConnection.onclose = function() { - if (currentlyReconnecting || globalGatewayConnection.ws.readyState === 1) return; - currentlyReconnecting = true; - warn("Gateway connection closed"); +const dispatchConnectionClose = () => { store.dispatch({ type: 'authenticator/updatelocaluserobject', user: undefined }); store.dispatch({ type: 'gateway/connectionstatus', gateway: { isConnected: false } }); store.dispatch({ type: 'application/updatebannertext', text: "Hang tight! You've lost connection!" }); - const interval = setInterval(() => { +}; + +let reconnectInterval; +globalGatewayConnection.onclose = function(code) { + if (code === 4006) { + clearInterval(reconnectInterval); + dispatchConnectionClose(); + return; + } + if (currentlyReconnecting || globalGatewayConnection.ws.readyState === 1) return; + currentlyReconnecting = true; + warn("Gateway connection closed"); + dispatchConnectionClose(); + reconnectInterval = setInterval(() => { if (globalGatewayConnection.ws.readyState === 1) { - clearInterval(interval); + clearInterval(reconnectInterval); currentlyReconnecting = false; return; } diff --git a/bfrontend/src/Components/Auth/Create.js b/bfrontend/src/Components/Auth/Create.js index 5953600..0efee37 100644 --- a/bfrontend/src/Components/Auth/Create.js +++ b/bfrontend/src/Components/Auth/Create.js @@ -78,18 +78,26 @@ export default function Create() { ); return ( -