diff --git a/code-websocket/server.js b/code-websocket/server.js index 366d106cb7..af2b015e0f 100644 --- a/code-websocket/server.js +++ b/code-websocket/server.js @@ -41,6 +41,13 @@ server.on('connection', (socket, request) => { // Send the current code to the newly connected client socket.send(JSON.stringify({ type: 'initialCode', content: sessionData[sessionID].code })); + const pingInterval = setInterval(() => { + if (socket.readyState === WebSocket.OPEN) { + socket.ping(); + console.log('ping ping ping'); + } + }, 30000); + // Handle incoming messages socket.on('message', (message) => { const parsedMessage = JSON.parse(message); @@ -91,6 +98,7 @@ server.on('connection', (socket, request) => { // Handle client disconnection socket.on('close', (code, reason) => { + clearInterval(pingInterval); console.log(`User ${userID} disconnected from session ${sessionID}, code: ${code}, reason: ${reason}`); // Remove the user from the active users list diff --git a/peer-prep-fe/src/collab-page/collab-page.component.ts b/peer-prep-fe/src/collab-page/collab-page.component.ts index 644aed554e..15ca41a82b 100644 --- a/peer-prep-fe/src/collab-page/collab-page.component.ts +++ b/peer-prep-fe/src/collab-page/collab-page.component.ts @@ -37,7 +37,7 @@ export class CollabPageComponent implements OnInit, OnDestroy { private route: ActivatedRoute, private collabService: CollabService, private editorWebSocketService: EditorWebSocketService, // Inject WebSocketService for code editor - private chatWebSocketService: ChatWebSocketService // Inject WebSocketService for chat + private chatWebSocketService: ChatWebSocketService, // Inject WebSocketService for chat ) {} ngOnInit(): void {