Skip to content

The gRPC API

The gRPC API

The API is gRPC, proto/turn/v1/turnd.proto (service turn.v1.Turnd). The generated code is committed, and CI regenerates it and fails on a diff.

Transport

A plain grpc.Server is served over a WebSocket at /grpc (grpc-transports/websocket), which is what a browser can speak, including the bidirectional stream.

The WebSocket upgrade enforces the exact origin allowlist (--allowed-origin; scheme and port included). A client with no Origin header is a native client.

Tokens

A token travels as authorization: Bearer … metadata, never in a URL.

HTTP, for browser navigations

Only browser navigations stay HTTP:

HTTP
GET /login?origin=<allowed origin>starts the OIDC login (code + PKCE) in a popup; an origin not in --allowed-origin is a 400, never a redirect
GET /callbackpage that postMessages {type:"turnd-session",token,expires} (or {type:"turnd-error",error}) to window.opener, target origin = the allowlisted one
GET /healthzok

RPCs

RPCtokenreturns
Credentialssession, or issuer access tokenIceServers{ice_servers[{urls,username,credential}], ttl}
CreateRoomsession or access token{room, peer:"host", token, expires}; the room ID is 128 random bits
JoinRoom{room,name}none: the room ID{peer, host, token, expires, pending:true}; the guest is pending
Admit{room,peer} / Deny{room,peer}host tokenadmit a pending guest / refuse it (or remove an admitted one): its token is dead
RoomCredentials{room}an admitted peer’s tokenIceServers expiring with the room, charged to the host
CloseRoom{room}host tokenends the room
Room(stream Envelope) returns (stream Envelope)peer token + x-turn-room metadatathe room’s one stream: events down, messages up; ending it is leaving

What the room RPCs mean is in Rooms and admission.

Status codes

A message that breaks the protocol (too large, a spoofed from, a bad kind, a pending sender, guest to guest) ends the sender’s stream with a status: RESOURCE_EXHAUSTED, PERMISSION_DENIED, INVALID_ARGUMENT. Other refusals:

statuswhen
UNAUTHENTICATEDno or dead token
NOT_FOUND
ALREADY_EXISTSa second stream for one peer
FAILED_PRECONDITIONalready admitted
UNAVAILABLEserver full

The credential scheme

draft-uberti-behave-turn-rest-00.

The Go client

For the browser and native: github.com/go-turn/turn/rendezvous/client. Create, Join(name) (blocks until admitted, ErrDenied otherwise), Admit, Deny, Send, Recv, Credentials, Close.

It is a real grpc-go client dialed over the browser’s WebSocket through syscall/js. It adds about 16 MB to a wasm binary (3.5 MB more gzipped), almost all of it grpc. go-crdt/collab’s js/wasm build does not link grpc, so a page that does not otherwise ship it should load this client in a separate wasm, fetched when a collaboration starts.