mirror of
https://github.com/Skylar-Tech/node-red-contrib-matrix-chat.git
synced 2025-04-20 13:03:12 -06:00
Fix global variable for matrix client online status not setting to false when connection fails
This commit is contained in:
parent
fa92f79304
commit
ff66222687
@ -26,7 +26,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
node.setMaxListeners(1000);
|
node.setMaxListeners(1000);
|
||||||
|
|
||||||
this.connected = false;
|
this.connected = null;
|
||||||
this.name = n.name;
|
this.name = n.name;
|
||||||
this.userId = this.credentials.userId;
|
this.userId = this.credentials.userId;
|
||||||
this.deviceId = this.credentials.deviceId || null;
|
this.deviceId = this.credentials.deviceId || null;
|
||||||
@ -43,6 +43,23 @@ module.exports = function(RED) {
|
|||||||
} else if(!this.userId) {
|
} else if(!this.userId) {
|
||||||
node.log("Matrix connection failed: missing user ID.");
|
node.log("Matrix connection failed: missing user ID.");
|
||||||
} else {
|
} 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);
|
let localStorageDir = storageDir + '/' + MatrixFolderNameFromUserId(this.userId);
|
||||||
|
|
||||||
fs.ensureDirSync(storageDir); // create storage directory if it doesn't exist
|
fs.ensureDirSync(storageDir); // create storage directory if it doesn't exist
|
||||||
@ -72,22 +89,6 @@ module.exports = function(RED) {
|
|||||||
done();
|
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() {
|
node.isConnected = function() {
|
||||||
return node.connected;
|
return node.connected;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user