WebSocket
Installation
SKILL.md
Reconnection (Always Forget)
- Connections drop silently—TCP FIN may never arrive; don't assume
onclosefires - Exponential backoff: 1s, 2s, 4s, 8s... cap at 30s—prevents thundering herd on server recovery
- Add jitter:
delay * (0.5 + Math.random())—prevents synchronized reconnection storms - Track reconnection state—queue messages during reconnect, replay after
- Max retry limit then surface error to user—don't retry forever silently
Heartbeats (Critical)
- Ping/pong frames at protocol level—browser doesn't expose; use application-level ping
- Send ping every 30s, expect pong within 10s—no pong = connection dead, reconnect
- Server should ping too—detects dead clients, cleans up resources
- Idle timeout in proxies (60-120s typical)—heartbeat must be more frequent
- Don't rely on TCP keepalive—too infrequent, not reliable through proxies