MCPcopy
hub / github.com/simstudioai/sim / setupConnectionHandlers

Function setupConnectionHandlers

apps/realtime/src/handlers/connection.ts:9–37  ·  view source on GitHub ↗
(socket: AuthenticatedSocket, roomManager: IRoomManager)

Source from the content-addressed store, hash-verified

7const logger = createLogger('ConnectionHandlers')
8
9export function setupConnectionHandlers(socket: AuthenticatedSocket, roomManager: IRoomManager) {
10 socket.on('error', (error) => {
11 logger.error(`Socket ${socket.id} error:`, error)
12 })
13
14 socket.conn.on('error', (error) => {
15 logger.error(`Socket ${socket.id} connection error:`, error)
16 })
17
18 socket.on('disconnect', async (reason) => {
19 try {
20 // Clean up pending debounce entries for this socket to prevent memory leaks
21 cleanupPendingSubblocksForSocket(socket.id)
22 cleanupPendingVariablesForSocket(socket.id)
23
24 const workflowIdHint = [...socket.rooms].find((roomId) => roomId !== socket.id)
25 const workflowId = await roomManager.removeUserFromRoom(socket.id, workflowIdHint)
26
27 if (workflowId) {
28 await roomManager.broadcastPresenceUpdate(workflowId)
29 logger.info(
30 `Socket ${socket.id} disconnected from workflow ${workflowId} (reason: ${reason})`
31 )
32 }
33 } catch (error) {
34 logger.error(`Error handling disconnect for socket ${socket.id}:`, error)
35 }
36 })
37}

Callers 1

setupAllHandlersFunction · 0.90

Calls 7

onMethod · 0.80
errorMethod · 0.80
infoMethod · 0.80
removeUserFromRoomMethod · 0.65

Tested by

no test coverage detected