Refactor XMPP connection handling in index.js

This commit is contained in:
Christopher Cookman 2024-05-12 01:53:21 -06:00
parent 60e9031325
commit e3835c1122
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -245,11 +245,11 @@ xmpp.on("error", (err) => {
xmpp.on("offline", () => { xmpp.on("offline", () => {
console.log(`${colors.yellow("[WARN]")} XMPP offline, trying to reconnect...`); console.log(`${colors.yellow("[WARN]")} XMPP offline, trying to reconnect...`);
setTimeout(() => { xmpp.disconnect().then(() => {
xmpp.stop().then(() => { xmpp.stop().then(() => {
start(); start();
}); })
}, 5000); })
}); });
@ -470,8 +470,10 @@ xmpp.on("online", async (address) => {
xmpp.on("close", () => { xmpp.on("close", () => {
console.log(`${colors.yellow("[WARN]")} XMPP connection closed, trying to reconnect...`); console.log(`${colors.yellow("[WARN]")} XMPP connection closed, trying to reconnect...`);
xmpp.stop().then(() => { xmpp.disconnect().then(() => {
start(); xmpp.stop().then(() => {
start();
})
}) })
}) })
@ -484,8 +486,10 @@ const start = () => {
process.exit(1); process.exit(1);
} }
console.log(`${colors.red("[ERROR]")} XMPP failed to start: ${err}.`); console.log(`${colors.red("[ERROR]")} XMPP failed to start: ${err}.`);
xmpp.stop().then(() => { xmpp.disconnect().then(() => {
start(); xmpp.stop().then(() => {
start();
})
}) })
}); });
} }