adjust timings of socket health check

This commit is contained in:
HF 2022-07-03 22:31:38 +02:00
parent bb89d6e55b
commit 09157955fa
3 changed files with 4 additions and 10 deletions

View File

@ -60,7 +60,7 @@ class SocketClient extends EventEmitter {
checkHealth() { checkHealth() {
if (this.readyState === WebSocket.OPEN) { if (this.readyState === WebSocket.OPEN) {
const now = Date.now(); const now = Date.now();
if (now - 20000 > this.timeLastPing) { if (now - 25000 > this.timeLastPing) {
// server didn't send anything, probably dead // server didn't send anything, probably dead
console.log('Server is silent, killing websocket'); console.log('Server is silent, killing websocket');
this.readyState = WebSocket.CLOSING; this.readyState = WebSocket.CLOSING;
@ -213,22 +213,16 @@ class SocketClient extends EventEmitter {
const data = new DataView(buffer); const data = new DataView(buffer);
const opcode = data.getUint8(0); const opcode = data.getUint8(0);
this.timeLastPing = Date.now();
switch (opcode) { switch (opcode) {
case PixelUpdate.OP_CODE: case PixelUpdate.OP_CODE:
this.emit('pixelUpdate', PixelUpdate.hydrate(data)); this.emit('pixelUpdate', PixelUpdate.hydrate(data));
break; break;
case PixelReturn.OP_CODE: case PixelReturn.OP_CODE:
/*
* using online counter and pxlReturn as sign-of-life ping
*/
this.timeLastPing = Date.now();
this.emit('pixelReturn', PixelReturn.hydrate(data)); this.emit('pixelReturn', PixelReturn.hydrate(data));
break; break;
case OnlineCounter.OP_CODE: case OnlineCounter.OP_CODE:
/*
* using online counter and pxlReturn as sign-of-life ping
*/
this.timeLastPing = Date.now();
this.emit('onlineCounter', OnlineCounter.hydrate(data)); this.emit('onlineCounter', OnlineCounter.hydrate(data));
break; break;
case CoolDownPacket.OP_CODE: case CoolDownPacket.OP_CODE:

View File

@ -348,7 +348,7 @@ class SocketServer {
} }
checkHealth() { checkHealth() {
const ts = Date.now() - 120 * 1000; const ts = Date.now() - 60 * 1000;
this.wss.clients.forEach((ws) => { this.wss.clients.forEach((ws) => {
if ( if (
ws.readyState === WebSocket.OPEN ws.readyState === WebSocket.OPEN

BIN
utils/italy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB