From e3835c1122a51a4ba5d1498ae12e5adac0a9048c Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 12 May 2024 01:53:21 -0600 Subject: [PATCH] Refactor XMPP connection handling in index.js --- index.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 330d59b..cb75f26 100644 --- a/index.js +++ b/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,8 +470,10 @@ xmpp.on("online", async (address) => { xmpp.on("close", () => { console.log(`${colors.yellow("[WARN]")} XMPP connection closed, trying to reconnect...`); - xmpp.stop().then(() => { - start(); + xmpp.disconnect().then(() => { + xmpp.stop().then(() => { + start(); + }) }) }) @@ -484,8 +486,10 @@ const start = () => { process.exit(1); } console.log(`${colors.red("[ERROR]")} XMPP failed to start: ${err}.`); - xmpp.stop().then(() => { - start(); + xmpp.disconnect().then(() => { + xmpp.stop().then(() => { + start(); + }) }) }); }