forked from ppfun/pixelplanet
promisify terminating dead websockets
This commit is contained in:
parent
14aaa3211d
commit
09ba826b33
|
@ -338,15 +338,21 @@ class SocketServer {
|
|||
|
||||
checkHealth() {
|
||||
const ts = Date.now() - 60 * 1000;
|
||||
const promises = [];
|
||||
this.wss.clients.forEach((ws) => {
|
||||
if (
|
||||
ws.readyState === WebSocket.OPEN
|
||||
&& ts > ws.timeLastMsg
|
||||
) {
|
||||
logger.info(`Killing dead websocket from ${ws.user.ip}`);
|
||||
ws.terminate();
|
||||
}
|
||||
promises.push(new Promise((resolve) => {
|
||||
if (
|
||||
ws.readyState === WebSocket.OPEN
|
||||
&& ts > ws.timeLastMsg
|
||||
) {
|
||||
logger.info(`Killing dead websocket from ${ws.user.ip}`);
|
||||
ws.terminate();
|
||||
resolve();
|
||||
}
|
||||
}),
|
||||
);
|
||||
});
|
||||
return promises;
|
||||
}
|
||||
|
||||
onlineCounterBroadcast() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user