fix: improved ping-pong events

This commit is contained in:
Lukian 2025-04-09 11:51:28 +02:00
parent 1fee32f1d2
commit 3ecac00706
2 changed files with 8 additions and 1 deletions

View file

@ -33,6 +33,13 @@ router.ws('/', function(ws, req) {
ws.on('close', () => {
sockets.delete(ws);
});
ws.on('message', (msg) => {
const data = JSON.parse(msg);
if (data.type === 'ping') {
ws.send(JSON.stringify({ type: 'pong' }));
}
});
});
function socketsMiddleware(req, res, next) {