From ff6622268799c80e8e7bb572b96f1701c30abda8 Mon Sep 17 00:00:00 2001 From: Skylar Sadlier Date: Fri, 3 Sep 2021 08:43:13 -0600 Subject: [PATCH] Fix global variable for matrix client online status not setting to false when connection fails --- src/matrix-server-config.js | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/matrix-server-config.js b/src/matrix-server-config.js index 7dfbdb2..de2555e 100644 --- a/src/matrix-server-config.js +++ b/src/matrix-server-config.js @@ -26,7 +26,7 @@ module.exports = function(RED) { node.setMaxListeners(1000); - this.connected = false; + this.connected = null; this.name = n.name; this.userId = this.credentials.userId; this.deviceId = this.credentials.deviceId || null; @@ -43,6 +43,23 @@ module.exports = function(RED) { } else if(!this.userId) { node.log("Matrix connection failed: missing user ID."); } else { + node.setConnected = function(connected) { + if (node.connected !== connected) { + node.connected = connected; + if (connected) { + node.log("Matrix server connection ready."); + node.emit("connected"); + } else { + node.emit("disconnected"); + } + + if(this.globalAccess) { + this.context().global.set('matrixClientOnline["'+this.userId+'"]', connected); + } + } + }; + node.setConnected(false); + let localStorageDir = storageDir + '/' + MatrixFolderNameFromUserId(this.userId); fs.ensureDirSync(storageDir); // create storage directory if it doesn't exist @@ -72,22 +89,6 @@ module.exports = function(RED) { done(); }); - node.setConnected = function(connected) { - if (node.connected !== connected) { - node.connected = connected; - if (connected) { - node.log("Matrix server connection ready."); - node.emit("connected"); - } else { - node.emit("disconnected"); - } - - if(this.globalAccess) { - this.context().global.set('matrixClientOnline["'+this.userId+'"]', connected); - } - } - }; - node.isConnected = function() { return node.connected; };