Realtime WebSocket API

The Realtime API exposes a long-lived WebSocket endpoint at /api/v2/realtime for streaming subscription, presence, and event push.

Endpoint

wss://cdn.brlvpn.com/api/v2/realtime

Connections are kept open for the lifetime of the session. Use exponential backoff (initial 500 ms, max 30 s, jitter ±25%) for reconnect attempts.

Authentication

Authentication is performed during the WebSocket upgrade. The client presents a session token; the server validates and either accepts the upgrade (101 Switching Protocols) or rejects with 401 Unauthorized.

Requests to /api/v2/realtime without a valid Upgrade: websocket header or without authentication will receive a structured JSON 401 response pointing back to this documentation page.

Probe (curl)

$ curl -i https://cdn.brlvpn.com/api/v2/realtime
HTTP/2 401
content-type: application/json
{"error":"unauthorized","code":"missing_token","status":401}

Message framing

Messages are binary WebSocket frames. The first byte of each frame indicates the message kind:

ByteKindDirection
0x01SUBSCRIBEclient → server
0x02UNSUBSCRIBEclient → server
0x10EVENTserver → client
0x20PINGbidirectional
0x21PONGbidirectional
0xFFERRORserver → client

SUBSCRIBE

Subscribe to a topic with an optional filter expression. Topic names are ASCII [a-z0-9._-]+; filter expressions are evaluated server-side.

PING / PONG

The server sends a PING every 30 s of idle. Clients SHOULD respond within 10 s with PONG. Three consecutive missed pongs trigger server-side close.

Status & quotas

StatusMeaning
1000Normal close
1001Going away (server restart)
1008Policy violation (quota / abuse)
1011Internal error
4401Auth expired mid-session — reconnect with fresh token

Concurrent connection limit per token: 8. Idle-without-subscribe limit: 60 s. Maximum subscriptions per connection: 64.

See also