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:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user