Websocket handler

From berkcangumusisik/claude-code-practices · View interactive version

Websocket handler is an AI agent skill from the GitHub repository berkcangumusisik/claude-code-practices. Implements WebSocket handlers with rooms, authentication, and reconnection logic

How to use this skill

Skill file

WebSocket Implementation

Feature: $ARGUMENTS

  1. Detect WebSocket library:
cat package.json | grep -E '"socket.io"|"ws"|"@fastify/websocket"|"hono.*ws"|"partykit"'
  1. Generate server-side handler:
// Socket.io example
io.on('connection', (socket) => {
  // Auth check
  const userId = socket.handshake.auth.token
  if (!isValidToken(userId)) {
    socket.disconnect()
    return
  }

  // Room management
  socket.join(`user:${userId}`)

  socket.on('message', async (data) => {
    // Validate input
    // Handle event
    // Broadcast to relevant room
    io.to(`room:${data.roomId}`).emit('message', response)
  })

  socket.on('disconnect', () => {
    // Cleanup
  })
})
  1. Generate client-side hook with:
  1. Add error handling for:
  1. Include a message type registry to keep events typed end-to-end.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.