1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add ws heartbeat to keep connection alive through firewall

This commit is contained in:
Nick O'Leary 2014-04-24 23:42:44 +01:00
parent b5a8a7288b
commit 13deef189d
2 changed files with 25 additions and 1 deletions

View File

@ -134,6 +134,9 @@
}
ws.onmessage = function(event) {
var o = JSON.parse(event.data);
if (o.heartbeat) {
return;
}
//console.log(msg);
var msg = document.createElement("div");
msg.onmouseover = function() {

View File

@ -57,6 +57,26 @@ function DebugNode(n) {
});
}
var lastSentTime = (new Date()).getTime();
setInterval(function() {
var now = (new Date()).getTime();
if (now-lastSentTime > 15000) {
lastSentTime = now;
for (var i in DebugNode.activeConnections) {
var ws = DebugNode.activeConnections[i];
try {
var p = JSON.stringify({heartbeat:lastSentTime});
ws.send(p);
} catch(err) {
util.log("[debug] ws heartbeat error : "+err);
}
}
}
}, 15000);
RED.nodes.registerType("debug",DebugNode);
DebugNode.send = function(msg) {
@ -85,7 +105,7 @@ DebugNode.send = function(msg) {
if (msg.msg.length > debuglength) {
msg.msg = msg.msg.substr(0,debuglength) +" ....";
}
for (var i in DebugNode.activeConnections) {
var ws = DebugNode.activeConnections[i];
try {
@ -95,6 +115,7 @@ DebugNode.send = function(msg) {
util.log("[debug] ws error : "+err);
}
}
lastSentTime = (new Date()).getTime();
}
DebugNode.activeConnections = [];