Refactor XMPP connection handling in index.js
This commit is contained in:
parent
60e9031325
commit
e3835c1122
10
index.js
10
index.js
|
@ -245,11 +245,11 @@ xmpp.on("error", (err) => {
|
|||
|
||||
xmpp.on("offline", () => {
|
||||
console.log(`${colors.yellow("[WARN]")} XMPP offline, trying to reconnect...`);
|
||||
setTimeout(() => {
|
||||
xmpp.disconnect().then(() => {
|
||||
xmpp.stop().then(() => {
|
||||
start();
|
||||
});
|
||||
}, 5000);
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
|
@ -470,10 +470,12 @@ xmpp.on("online", async (address) => {
|
|||
|
||||
xmpp.on("close", () => {
|
||||
console.log(`${colors.yellow("[WARN]")} XMPP connection closed, trying to reconnect...`);
|
||||
xmpp.disconnect().then(() => {
|
||||
xmpp.stop().then(() => {
|
||||
start();
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
const start = () => {
|
||||
startup = true;
|
||||
|
@ -484,9 +486,11 @@ const start = () => {
|
|||
process.exit(1);
|
||||
}
|
||||
console.log(`${colors.red("[ERROR]")} XMPP failed to start: ${err}.`);
|
||||
xmpp.disconnect().then(() => {
|
||||
xmpp.stop().then(() => {
|
||||
start();
|
||||
})
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue