minecraft: reconnect to bridge gateway on error as well
This commit is contained in:
parent
ee2e192204
commit
d6a302ecee
1 changed files with 19 additions and 0 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue