Graphorin API reference v0.1.0
Graphorin API reference / @graphorin/protocol / subprotocol
subprotocol
Subprotocol identifier + negotiation helpers for the Graphorin WebSocket protocol.
Clients announce supported subprotocols in the Sec-WebSocket-Protocol upgrade header. The server is expected to pick exactly one and echo it back; mismatches abort the handshake per RFC 6455 § 4. Browsers also accept additional comma-separated tokens — Graphorin uses this slot to attach a single-use ticket via the ticket.<value> form (the WebSocket browser API does not accept arbitrary headers, so the ticket has to ride the subprotocol channel).
Variables
| Variable | Description |
|---|---|
| PROTOCOL_VERSION | Wire-format major version literal carried on every message body. The pair (SUBPROTOCOL_NAME, PROTOCOL_VERSION) is the binding contract a client commits to when it receives a successful upgrade. |
| SUBPROTOCOL_NAME | Canonical subprotocol identifier for the v1 wire format. |
| TICKET_SUBPROTOCOL_PREFIX | Prefix for the single-use ticket that browser clients attach to the Sec-WebSocket-Protocol header. The server's upgrade handler splits the comma-separated list, finds the first ticket.<value> token, and validates the value against the in-memory ticket store before granting the connection. |
Functions
| Function | Description |
|---|---|
| formatTicketSubprotocol | Format a ticket value as a Sec-WebSocket-Protocol token suitable for browser clients (which cannot attach an Authorization header on the WebSocket upgrade). The companion server helper is parseTicketSubprotocol. |
| negotiateSubprotocol | Pick the single subprotocol the server should echo back. Returns SUBPROTOCOL_NAME when the client offered it, or null when no compatible variant was advertised. The function ignores ticket.* tokens — those are handled separately via parseTicketSubprotocol. |
| parseTicketSubprotocol | Extract the ticket value from a single comma-separated client list (e.g. 'graphorin.protocol.v1, ticket.abc-123'). Returns undefined if no ticket.* token is present. Whitespace around each comma-separated token is ignored. |