minecraft: reconnect to bridge gateway on error as well

This commit is contained in:
hippoz 2022-02-15 14:25:26 +02:00
parent ee2e192204
commit d6a302ecee
Signed by: hippoz
GPG key ID: 7C52899193467641

View file

@ -40,6 +40,17 @@ export default class GatewayClient {
if (!token)
token = this.token;
if (this.ws) {
console.log("gateway: connect() but connection already exists, killing existing connection...");
try {
this.ws.removeAllListeners();
this.ws.close();
this.ws = null;
} catch (e) {
console.log("gateway: error while closing existing connection - it might not be established yet");
}
}
console.log("gateway: connecting");
this.ws = new WebSocket(this.gatewayPath);
@ -99,6 +110,14 @@ export default class GatewayClient {
this.connect(token);
}, 4000);
});
this.ws.on("error", (e) => {
console.error("gateway: error", e);
console.log("gateway: reconnecting in 4000ms due to previous error");
setTimeout(() => {
console.log("gateway: reconnecting");
this.connect(token);
}, 4000);
});
}
_checkMessageSchema(message) {