- Can now access the matrix client globally so it can be used in function nodes (this way you are not limited by only the nodes we have published)
- Added example for using the Matrix Client in a function to redact messages. This should be a great example to show people what is possible.
This commit is contained in:
2021-09-03 08:24:02 -06:00
parent d5519a6828
commit 6a310de708
6 changed files with 158 additions and 2 deletions
+10
View File
@@ -34,6 +34,7 @@ module.exports = function(RED) {
this.autoAcceptRoomInvites = n.autoAcceptRoomInvites;
this.enableE2ee = n.enableE2ee || false;
this.e2ee = (this.enableE2ee && this.deviceId);
this.globalAccess = n.global;
if(!this.credentials.accessToken) {
node.log("Matrix connection failed: missing access token.");
@@ -56,6 +57,11 @@ module.exports = function(RED) {
deviceId: this.deviceId || undefined,
});
// set globally if configured to do so
if(this.globalAccess) {
this.context().global.set('matrixClient["'+this.userId+'"]', node.matrixClient);
}
node.on('close', function(done) {
if(node.matrixClient) {
node.matrixClient.close();
@@ -75,6 +81,10 @@ module.exports = function(RED) {
} else {
node.emit("disconnected");
}
if(this.globalAccess) {
this.context().global.set('matrixClientOnline["'+this.userId+'"]', connected);
}
}
};