node-red-contrib-remote 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,6 +36,9 @@ You will find more information on [www.remote-red-com](https://www.remote-red.co
36
36
 
37
37
  ## Version History
38
38
 
39
+ Version 2.0.3
40
+ - More stable handling of connection losses
41
+
39
42
  Version 2.0.2
40
43
  - Crash on Node-RED startup fixed, extended error reporting
41
44
 
@@ -12,12 +12,7 @@ module.exports = function(RED) {
12
12
  // Is there a old node.sshprocess object?
13
13
  if (node.sshprocess !== undefined) {
14
14
  node.log(`ssh process with pid ${node.sshprocess.pid} already existing`);
15
- node.sshprocess.removeAllListeners('close');
16
- node.sshprocess.removeAllListeners('exit');
17
- node.sshprocess.removeAllListeners('error');
18
- node.sshprocess.stdout.removeAllListeners('data');
19
- node.sshprocess.stderr.removeAllListeners('data');
20
- node.sshprocess = undefined;
15
+ killSSHProcess(node);
21
16
  }
22
17
 
23
18
  // Reset heartbeat status
@@ -103,6 +98,7 @@ module.exports = function(RED) {
103
98
  // Is this instance banned?
104
99
  if ( node.instanceIsBanned ) {
105
100
  reject(new Error('Instance banned'));
101
+ return;
106
102
  }
107
103
 
108
104
  // Create object with config values to send to server
@@ -120,7 +116,7 @@ module.exports = function(RED) {
120
116
  const configString = JSON.stringify(config);
121
117
  const configStringBuffer = Buffer.from(configString);
122
118
  const configStringBase64 = configStringBuffer.toString('base64');
123
- node.log(`Sending config to server: ${configString}`);
119
+ // node.log(`Sending config to server: ${configString}`);
124
120
 
125
121
  // Call API to retrive server and port.
126
122
  const axiosInstance = commons.createAxiosInstance();
@@ -153,6 +149,8 @@ module.exports = function(RED) {
153
149
  if ( error.response.status === 403 ) {
154
150
  setStatus(node, {fill:"red",shape:"dot",text:"remote-access.status.banned"});
155
151
  node.instanceIsBanned = true;
152
+ reject(new Error('Instance banned'));
153
+ return;
156
154
  }
157
155
  }
158
156
 
@@ -218,8 +216,11 @@ module.exports = function(RED) {
218
216
  }
219
217
  node.lastHeartbeatStatus = response.data.status
220
218
 
221
- // If the communication is not ok...
222
- if ( node.lastHeartbeatStatus === 'NOTFOUND' ) {
219
+ // Based on the status...
220
+ if ( node.lastHeartbeatStatus === 'OK' ) {
221
+ node.initialHeartbeatStatus = node.lastHeartbeatStatus; // Wenn es jetzt OK ist, zählt es auch wie initial OK
222
+ setStatus(node, {fill:"green",shape:"dot",text:"remote-access.status.serving"});
223
+ } else if ( node.lastHeartbeatStatus === 'NOTFOUND' ) {
223
224
  // The local endpoint responed a 404...
224
225
  setStatus(node, {fill:"yellow",shape:"dot",text:"remote-access.status.heartbeaterrornotfound"});
225
226
  node.log(`Heartbeat detected no valid endpoint, got a 404 response. Please check the base URL in the connection settings.`);
@@ -227,8 +228,8 @@ module.exports = function(RED) {
227
228
  if ( node.initialHeartbeatStatus === 'OK' ) {
228
229
  // If the status before was ok > Restart communication
229
230
  setStatus(node, {fill:"red",shape:"dot",text:"remote-access.status.heartbeaterror"});
230
- killSSHProcess(node)
231
231
  node.log(`Heartbeat error. Reconnecting soon.`);
232
+ killSSHProcess(node)
232
233
  } else {
233
234
  // If the status before had also an error > Just change the label.
234
235
  setStatus(node, {fill:"yellow",shape:"dot",text:"remote-access.status.heartbeaterroractive"});
@@ -238,7 +239,7 @@ module.exports = function(RED) {
238
239
  })
239
240
  .catch((error) => {
240
241
  // Error on api call > Log error
241
- node.error('heartbeat: ' + commons.getNetworkErrorString(error))
242
+ commons.reportError(error, node, 'heartbeat');
242
243
  if ( commons.getNetworkErrorCustomString(error) !== undefined) {
243
244
  node.error(commons.getNetworkErrorCustomString(error));
244
245
  }
@@ -251,7 +252,13 @@ module.exports = function(RED) {
251
252
  try {
252
253
  if (node.sshprocess !== undefined) {
253
254
  node.log(`Killing process ${node.sshprocess.pid}`);
255
+ node.sshprocess.removeAllListeners('close');
256
+ node.sshprocess.removeAllListeners('exit');
257
+ node.sshprocess.removeAllListeners('error');
258
+ node.sshprocess.stdout.removeAllListeners('data');
259
+ node.sshprocess.stderr.removeAllListeners('data');
254
260
  node.sshprocess.kill();
261
+ node.sshprocess = undefined;
255
262
  }
256
263
  node.serving = false
257
264
  } catch (error) {
@@ -88,7 +88,10 @@ module.exports = {
88
88
  this.reportError(errorElem, node, caller);
89
89
  });
90
90
  } else {
91
- node.error(`${caller}: ${error.code}: ${(error.stack !== undefined) ? error.stack : error.message}`);
91
+ node.error(`${caller}: ${error.code}: ${error.message}`);
92
+ if ( error.stack !== undefined ) {
93
+ node.debug(error.stack);
94
+ }
92
95
  }
93
96
  }
94
97
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-remote",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "Remote-RED is an ecosystem to bring remote access, push notification and geofencing to Node-RED. There are also additional functions like directly answer on a notification and homescreen widgets.",
5
5
  "author": "Thorsten Heilmann",
6
6
  "license": "GPL-3.0",