From a9d1ca04916dc145ec6f1dfb4a7b3b6f6a82bd64 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 26 Feb 2021 16:05:03 +0000 Subject: [PATCH] xmpp disconnect more cleanly/correctly --- social/xmpp/92-xmpp.js | 20 ++++++++++---------- social/xmpp/package.json | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/social/xmpp/92-xmpp.js b/social/xmpp/92-xmpp.js index d6b2bb0c..7cb59583 100644 --- a/social/xmpp/92-xmpp.js +++ b/social/xmpp/92-xmpp.js @@ -211,18 +211,18 @@ module.exports = function(RED) { for (const room of rooms) { await that.client.send(xml('presence', {to:room, type:'unavailable'})); } - // if (that.client.connected) { - await that.client.send(xml('presence', {type:'unavailable'})); - try{ - if (RED.settings.verbose || LOGITALL) { - that.log("Calling stop() after close, status is "+that.client.status); + if (that.connected) { + await that.client.send(xml('presence', {type:'unavailable'})); + try{ + if (RED.settings.verbose || LOGITALL) { + that.log("Calling stop() after close, status is "+that.client.status); + } + await that.client.stop().then(that.log("XMPP client stopped")).catch(error=>{that.warn("Got an error whilst closing xmpp session: "+error)}); + } + catch(e) { + that.warn(e); } - await that.client.stop().then(that.log("XMPP client stopped")).catch(error=>{that.warn("Got an error whilst closing xmpp session: "+error)}); } - catch(e) { - that.warn(e); - } - // } done(); }); } diff --git a/social/xmpp/package.json b/social/xmpp/package.json index ad6bf3cf..4bafae0a 100644 --- a/social/xmpp/package.json +++ b/social/xmpp/package.json @@ -1,6 +1,6 @@ { "name": "node-red-node-xmpp", - "version": "0.4.1", + "version": "0.4.2", "description": "A Node-RED node to talk to an XMPP server", "dependencies": { "@xmpp/client": "^0.12.0"