mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge #3531 websocket status improvements
call done after ws disconnects
This commit is contained in:
commit
e092f41074
@ -35,8 +35,6 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var listenerNodes = {};
|
var listenerNodes = {};
|
||||||
var activeListenerNodes = 0;
|
|
||||||
|
|
||||||
|
|
||||||
// A node red node that sets up a local websocket server
|
// A node red node that sets up a local websocket server
|
||||||
function WebSocketListenerNode(n) {
|
function WebSocketListenerNode(n) {
|
||||||
@ -166,7 +164,6 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node.isServer) {
|
if (node.isServer) {
|
||||||
activeListenerNodes++;
|
|
||||||
if (!serverUpgradeAdded) {
|
if (!serverUpgradeAdded) {
|
||||||
RED.server.on('upgrade', handleServerUpgrade);
|
RED.server.on('upgrade', handleServerUpgrade);
|
||||||
serverUpgradeAdded = true
|
serverUpgradeAdded = true
|
||||||
@ -210,7 +207,7 @@ module.exports = function(RED) {
|
|||||||
startconn(); // start outbound connection
|
startconn(); // start outbound connection
|
||||||
}
|
}
|
||||||
|
|
||||||
node.on("close", function() {
|
node.on("close", function(done) {
|
||||||
if (node.heartbeatInterval) {
|
if (node.heartbeatInterval) {
|
||||||
clearInterval(node.heartbeatInterval);
|
clearInterval(node.heartbeatInterval);
|
||||||
}
|
}
|
||||||
@ -218,19 +215,25 @@ module.exports = function(RED) {
|
|||||||
delete listenerNodes[node.fullPath];
|
delete listenerNodes[node.fullPath];
|
||||||
node.server.close();
|
node.server.close();
|
||||||
node._inputNodes = [];
|
node._inputNodes = [];
|
||||||
activeListenerNodes--;
|
|
||||||
// if (activeListenerNodes === 0 && serverUpgradeAdded) {
|
|
||||||
// RED.server.removeListener('upgrade', handleServerUpgrade);
|
|
||||||
// serverUpgradeAdded = false;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
node.closing = true;
|
node.closing = true;
|
||||||
node.server.close();
|
node.server.close();
|
||||||
if (node.tout) {
|
//wait 20*50 (1000ms max) for ws to close.
|
||||||
clearTimeout(node.tout);
|
//call done when readyState === ws.CLOSED (or 1000ms, whichever comes fist)
|
||||||
node.tout = null;
|
const closeMonitorInterval = 20;
|
||||||
}
|
let closeMonitorCount = 50;
|
||||||
|
let si = setInterval(() => {
|
||||||
|
if(node.server.readyState === ws.CLOSED || closeMonitorCount <= 0) {
|
||||||
|
if (node.tout) {
|
||||||
|
clearTimeout(node.tout);
|
||||||
|
node.tout = null;
|
||||||
|
}
|
||||||
|
clearInterval(si);
|
||||||
|
return done();
|
||||||
|
}
|
||||||
|
closeMonitorCount--;
|
||||||
|
}, closeMonitorInterval);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user