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,9 +470,11 @@ 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.disconnect().then(() => {
xmpp.stop().then(() => { xmpp.stop().then(() => {
start(); start();
}) })
})
}) })
const start = () => { const start = () => {
@ -484,9 +486,11 @@ 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.disconnect().then(() => {
xmpp.stop().then(() => { xmpp.stop().then(() => {
start(); start();
}) })
})
}); });
} }