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

Merge pull request #3344 from node-red/fix-ws-hb

Only setup ws client heartbeat once it is connected
This commit is contained in:
Nick O'Leary 2022-01-12 22:53:51 +00:00 committed by GitHub
commit 48fb1a8127
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -105,8 +105,11 @@ module.exports = function(RED) {
if (node.isServer) { if (node.isServer) {
node._clients[id] = socket; node._clients[id] = socket;
node.emit('opened',{count:Object.keys(node._clients).length,id:id}); node.emit('opened',{count:Object.keys(node._clients).length,id:id});
} else { }
socket.on('open',function() {
if (!node.isServer) {
if (node.heartbeat) { if (node.heartbeat) {
clearInterval(node.heartbeatInterval);
node.heartbeatInterval = setInterval(function() { node.heartbeatInterval = setInterval(function() {
if (socket.nrPendingHeartbeat) { if (socket.nrPendingHeartbeat) {
// No pong received // No pong received
@ -115,12 +118,11 @@ module.exports = function(RED) {
return; return;
} }
socket.nrPendingHeartbeat = true; socket.nrPendingHeartbeat = true;
try {
socket.ping(); socket.ping();
} catch(err) {}
},node.heartbeat); },node.heartbeat);
} }
}
socket.on('open',function() {
if (!node.isServer) {
node.emit('opened',{count:'',id:id}); node.emit('opened',{count:'',id:id});
} }
}); });