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