API Reference
Socket API
Channel management, broadcasting, and connection status endpoints.
The Socket API provides REST endpoints for managing WebSocket channels and broadcasting messages server-side.
List Channels
GET /api/socket/channelsReturns all currently active channels with member counts.
Response:
[
{ "name": "chat:room1", "memberCount": 5 },
{ "name": "notifications:user123", "memberCount": 1 }
]Channel Members
GET /api/socket/channels/:channel/membersExample:
curl http://localhost:3000/api/socket/channels/chat:room1/membersResponse:
[
{ "socketId": "abc123", "joinedAt": 1710000000000 },
{ "socketId": "def456", "joinedAt": 1710000100000 }
]Connection Count
GET /api/socket/connectionsResponse:
{
"count": 42
}Broadcast
Send a message to all members of a channel via REST (useful for server-side broadcasting):
POST /api/socket/broadcastRequest Body:
{
"channel": "chat:room1",
"event": "message",
"data": {
"text": "Server announcement",
"sender": "system"
}
}WebSocket Events
These events are used over the Socket.IO WebSocket connection (not REST):
| Event | Direction | Payload | Description |
|---|---|---|---|
subscribe | Client → Server | { topic, filter?, returnMode? } | Subscribe to a domain topic. returnMode controls sync event payload shape ('full', 'diff', or 'both'). |
unsubscribe | Client → Server | { subscriptionId } | Unsubscribe from a topic |
event | Server → Client | RealtimeEvent | Delivered event matching subscription |
Plain WebSocket Protocol
For plain WebSocket clients connected on /ws, the JSON message protocol is:
Client → Server:
{ "type": "subscribe", "topic": "sync.session.updated", "filter": {}, "returnMode": "diff" }{ "type": "unsubscribe", "subscriptionId": "sub_abc123" }{ "type": "ping" }Server → Client:
{ "type": "subscribed", "subscriptionId": "sub_abc123", "topic": "sync.session.updated" }{ "type": "event", "topic": "sync.session.updated", "data": { ... } }{ "type": "pong" }