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", () => {
|
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();
|
||||||
})
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue