feat(websocket): add ping/pong mechanism to maintain connection

- Add proxy timeouts in nginx.conf to handle long connections
- Implement ping/pong handling in server.js WebSocket listener
- Refactor App.js to class component with lifecycle methods and ping interval for WebSocket keep-alive
This commit is contained in:
sebseb7
2025-09-02 08:45:18 +00:00
parent 9cfbe4c0f7
commit a8ca291555
3 changed files with 58 additions and 27 deletions

View File

@@ -33,7 +33,13 @@ wss.on('connection', (ws) => {
console.log('Client connected');
ws.on('message', (message) => {
console.log('Received:', Buffer.from(message).toString());
const msg = Buffer.from(message).toString();
if (msg === '{"type":"ping"}') {
// Respond to ping to keep connection alive
ws.send(JSON.stringify({ type: 'pong' }));
} else {
console.log('Received:', msg);
}
});
ws.on('error', (error) => {