home / skills / a5c-ai / babysitter / websocket
/plugins/babysitter/skills/babysit/process/specializations/web-development/skills/websocket
This skill helps you implement robust WebSocket real-time features, including server setup, connection lifecycle, scaling, and authentication.
npx playbooks add skill a5c-ai/babysitter --skill websocketReview the files below or copy the command above to add this skill to your agents.
---
name: websocket
description: WebSocket implementation, connection management, scaling patterns, and real-time features.
allowed-tools: Read, Write, Edit, Bash, Glob, Grep
---
# WebSocket Skill
Expert assistance for implementing WebSocket real-time communication.
## Capabilities
- Implement WebSocket servers
- Handle connection lifecycle
- Build pub/sub patterns
- Scale with Redis adapter
- Implement reconnection logic
- Handle authentication
## Usage
Invoke this skill when you need to:
- Add real-time features
- Build chat applications
- Implement live updates
- Handle bidirectional communication
## Server Implementation
```typescript
import { WebSocketServer, WebSocket } from 'ws';
import { createServer } from 'http';
const server = createServer();
const wss = new WebSocketServer({ server });
const clients = new Map<string, WebSocket>();
wss.on('connection', (ws, req) => {
const userId = authenticateConnection(req);
clients.set(userId, ws);
ws.on('message', (data) => {
const message = JSON.parse(data.toString());
handleMessage(userId, message);
});
ws.on('close', () => {
clients.delete(userId);
});
});
function broadcast(message: object) {
const data = JSON.stringify(message);
clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN) {
client.send(data);
}
});
}
```
## Best Practices
- Implement heartbeat/ping-pong
- Handle reconnection gracefully
- Use message queues for scaling
- Authenticate connections
## Target Processes
- real-time-features
- chat-application
- live-updates
This skill provides practical guidance and code patterns for building WebSocket-based real-time systems in JavaScript. It focuses on connection lifecycle management, pub/sub patterns, scaling techniques, and secure reconnection flows. Use it to add deterministic, resumable real-time behavior to agent orchestration and interactive apps.
The skill inspects common WebSocket server and client workflows: accepting connections, authenticating users, routing messages, and cleaning up on disconnect. It describes pub/sub and broadcast patterns, heartbeat/ping-pong health checks, and using Redis or message queues as adapters to scale across processes. It also outlines reconnection strategies and where to place authentication and rate limiting.
How should I handle connection authentication?
Authenticate during the initial WebSocket handshake using headers or a short-lived token, then store user ID/session info on the socket for routing and authorization checks.
When do I need a Redis adapter?
Use a Redis or message-queue adapter when your service runs multiple server instances and you need to broadcast messages or sync presence across processes.