agentleFS
harrissohail6harrissohail6/claude-code-config/skills/websockets-realtime/SKILL.md

websockets-realtime

Skill1 starsChanged 11 months agoMITView on GitHub

WebSocket and real-time communication patterns. Auto-activates when implementing chat, notifications, or live updates.

  • Reads credentials
Files
SKILL.md

WebSockets & Real-time

Socket.IO Server

import { Server } from 'socket.io';

const io = new Server(server, {
  cors: {
    origin: process.env.CLIENT_URL,
    methods: ['GET', 'POST']
  }
});

// Authentication middleware
io.use((socket, next) => {
  const token = socket.handshake.auth.token;
  try {
    const user = verifyToken(token);
    socket.data.user = user;
    next();
  } catch {
    next(new Error('Authentication failed'));
  }
});

// Connection handling
io.on('connection', (socket) => {
  console.log(`User connected: ${socket.data.user.id}`);

  // Join user's room
  socket.join(`user:${socket.data.user.id}`);

  // Handle events
  socket.on('message', async (data) => {
    const message = await saveMessage(data);
    io.to(data.roomId).emit('message', message);
  });

  socket.on('disconnect', () => {
    console.log(`User disconnected: ${socket.data.user.id}`);
  });
});

Socket.IO Client

import { io } from 'socket.io-client';

const socket = io(SERVER_URL, {
  auth: { token: getAuthToken() },
  reconnection: true,
  reconnectionAttempts: 5
});

socket.on('connect', () => {
  console.log('Connected');
});

socket.on('message', (message) => {
  addMessageToUI(message);
});

// Send message
socket.emit('message', {
  roomId: 'room-123',
  content: 'Hello!'
});

Room Patterns

// Join room
socket.join('room:123');

// Leave room
socket.leave('room:123');

// Broadcast to room
io.to('room:123').emit('event', data);

// Broadcast to all except sender
socket.to('room:123').emit('event', data);

// Private message
io.to(`user:${userId}`).emit('private', message);

Scaling with Redis

import { createAdapter } from '@socket.io/redis-adapter';
import { createClient } from 'redis';

const pubClient = createClient({ url: REDIS_URL });
const subClient = pubClient.duplicate();

io.adapter(createAdapter(pubClient, subClient));

Use Cases

FeatureImplementation
ChatRooms + messages
NotificationsUser rooms + emit
Live updatesBroadcast on DB change
PresenceTrack connections
Typing indicatorsDebounced events

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.