Compare commits

..

No commits in common. "9c836c926276e5ae882d2aedd33f32bcdd3cec87" and "73d802ff0df2e6db154300f86cc7f92df009c113" have entirely different histories.

3 changed files with 31 additions and 66 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "node-red-contrib-matrix-chat", "name": "node-red-contrib-matrix-chat",
"version": "0.2.6", "version": "0.2.4",
"description": "Matrix chat server client for Node-RED", "description": "Matrix chat server client for Node-RED",
"dependencies": { "dependencies": {
"fs-extra": "^9.1.0", "fs-extra": "^9.1.0",

View File

@ -89,7 +89,6 @@ module.exports = function(RED) {
if(!node.server.isConnected()) { if(!node.server.isConnected()) {
node.error("Matrix server connection is currently closed"); node.error("Matrix server connection is currently closed");
node.send([null, msg]); node.send([null, msg]);
return;
} }
msg.topic = node.roomId || msg.topic; msg.topic = node.roomId || msg.topic;

View File

@ -133,70 +133,36 @@ module.exports = function(RED) {
}); });
node.matrixClient.on("sync", async function(state, prevState, data) { node.matrixClient.on("sync", async function(state, prevState, data) {
node.debug("SYNC [STATE=" + state + "] [PREVSTATE=" + prevState + "]"); switch (state) {
if(prevState === null && state === "PREPARED" ) { case "ERROR":
// Occurs when the initial sync is completed first time. node.setConnected(false, function(){
// This involves setting up filters and obtaining push rules. node.error("Connection to Matrix server lost");
node.setConnected(true, function(){ });
node.log("Matrix client connected"); break;
});
} else if(prevState === null && state === "ERROR") { case "RECONNECTING":
// Occurs when the initial sync failed first time. node.setConnected(false, function(){
node.setConnected(false, function(){ node.log("Trying to reconnect to matrix server");
node.error("Failed to connect to Matrix server"); });
}); break;
} else if(prevState === "ERROR" && state === "PREPARED") { case "STOPPED":
// Occurs when the initial sync succeeds node.setConnected(false, function(){
// after previously failing. node.log("Matrix client stopped");
node.setConnected(true, function(){ });
node.log("Matrix client connected"); break;
});
} else if(prevState === "PREPARED" && state === "SYNCING") { case "SYNCING":
// Occurs immediately after transitioning to PREPARED. case "PREPARED":
// Starts listening for live updates rather than catching up. node.setConnected(true, function(){
node.setConnected(true, function(){ node.log("Matrix client connected");
node.log("Matrix client connected"); });
}); break;
} else if(prevState === "SYNCING" && state === "RECONNECTING") {
// Occurs when the live update fails. // case "PREPARED":
node.setConnected(false, function(){ // // the client instance is ready to be queried.
node.error("Connection to Matrix server lost"); // node.log("Matrix server connection ready.");
}); // node.setConnected(true);
} else if(prevState === "RECONNECTING" && state === "RECONNECTING") { // break;
// Can occur if the update calls continue to fail,
// but the keepalive calls (to /versions) succeed.
node.setConnected(false, function(){
node.error("Connection to Matrix server lost");
});
} else if(prevState === "RECONNECTING" && state === "ERROR") {
// Occurs when the keepalive call also fails
node.setConnected(false, function(){
node.error("Connection to Matrix server lost");
});
} else if(prevState === "ERROR" && state === "SYNCING") {
// Occurs when the client has performed a
// live update after having previously failed.
node.setConnected(true, function(){
node.log("Matrix client connected");
});
} else if(prevState === "ERROR" && state === "ERROR") {
// Occurs when the client has failed to
// keepalive for a second time or more.
node.setConnected(false, function(){
node.error("Connection to Matrix server lost");
});
} else if(prevState === "SYNCING" && state === "SYNCING") {
// Occurs when the client has performed a live update.
// This is called <i>after</i> processing.
node.setConnected(true, function(){
node.log("Matrix client connected");
});
} else if(state === "STOPPED") {
// Occurs once the client has stopped syncing or
// trying to sync after stopClient has been called.
node.setConnected(false, function(){
node.error("Connection to Matrix server lost");
});
} }
}); });