Documentation
¶
Overview ¶
Package rendezvous is a signalling relay for WebRTC peers, as a gRPC service (turn.v1.Turnd, proto/turn/v1/turnd.proto). A logged-in host opens a room (CreateRoom) and shares its 128-bit random ID; a guest knocks with it (JoinRoom) and is PENDING until the host admits it. The room is ONE bidirectional stream (Room): events down, messages up, routed host to guest and guest to host. An admitted peer can get TURN credentials that expire with the room, charged to the host's subject.
A leaked room link therefore lets a stranger knock, not enter: a pending guest can receive and nothing else, it cannot send and it cannot spend the host's TURN quota.
Every resource is bounded (see Limits) and every refusal is tested as a gRPC status code. 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 that status, which for a guest is leaving and for the host closes the room. A message that fails for what the OTHER peer is (gone, queue full) leaves the stream open and comes back as a sys.error event, "<Code>: <reason>".
Index ¶
- Constants
- type Config
- type Limits
- type Server
- func (s *Server) Admit(ctx context.Context, req *turnv1.DecideRequest) (*turnv1.Ack, error)
- func (s *Server) CloseRoom(ctx context.Context, req *turnv1.RoomRef) (*turnv1.Ack, error)
- func (s *Server) CreateRoom(ctx context.Context, _ *turnv1.CreateRoomRequest) (*turnv1.CreateRoomResponse, error)
- func (s *Server) Credentials(ctx context.Context, _ *turnv1.CredentialsRequest) (*turnv1.IceServers, error)
- func (s *Server) Deny(ctx context.Context, req *turnv1.DecideRequest) (*turnv1.Ack, error)
- func (s *Server) JoinRoom(_ context.Context, req *turnv1.JoinRoomRequest) (*turnv1.JoinRoomResponse, error)
- func (s *Server) MaxRecvMsgSize() int
- func (s *Server) Register(gs grpc.ServiceRegistrar)
- func (s *Server) Room(stream grpc.BidiStreamingServer[turnv1.Envelope, turnv1.Envelope]) error
- func (s *Server) RoomCredentials(ctx context.Context, req *turnv1.RoomRef) (*turnv1.IceServers, error)
- func (s *Server) Rooms() int
- func (s *Server) Run(ctx context.Context, every time.Duration)
- func (s *Server) Sweep()
Constants ¶
const HostID = "host"
HostID is the peer ID of a room's host.
const MaxNameLen = 64
MaxNameLen bounds a guest's display name, in characters.
const RoomMetadata = "x-turn-room"
RoomMetadata is the metadata key naming the room on the Room stream.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Auth returns the subject of a session or access token (host operations).
Auth func(ctx context.Context, token string) (subject string, err error)
// Keyring signs the TURN credentials.
Keyring *creds.Keyring
// STUN and TURN are the URLs advertised in credential responses.
STUN, TURN []string
Limits Limits
// CredTTL is the lifetime of host credentials (default 1 hour); a guest's
// never outlive the room.
CredTTL time.Duration
Now func() time.Time
}
Config configures New.
type Limits ¶
type Limits struct {
// MaxMessageBytes bounds a message body (default 16 KiB). The handshake blob
// of the playground is an SDP description with its ICE candidates, a few KiB.
MaxMessageBytes int
// MaxQueue bounds the events waiting for one peer (default 64).
MaxQueue int
// MaxGuests bounds the guests ever ADMITTED to one room (default 8).
MaxGuests int
// MaxPending bounds the guests waiting for the host's decision in one room
// (default 8); PendingTTL is how long one may wait (default 2 minutes).
MaxPending int
PendingTTL time.Duration
// MaxRoomsPerSubject bounds the live rooms of one subject (default 4).
MaxRoomsPerSubject int
// MaxRooms bounds the live rooms of the server (default 1024).
MaxRooms int
// RoomTTL is a room's whole life (default 1 hour).
RoomTTL time.Duration
// MaxCredsPerRoom bounds the credential requests of one room (default 64).
MaxCredsPerRoom int
}
Limits bounds what a client can make the server hold. Zero fields take the default shown.
type Server ¶
type Server struct {
turnv1.UnimplementedTurndServer
// contains filtered or unexported fields
}
Server is the rendezvous. Build it with New and Server.Register it.
func (*Server) CreateRoom ¶
func (s *Server) CreateRoom(ctx context.Context, _ *turnv1.CreateRoomRequest) (*turnv1.CreateRoomResponse, error)
CreateRoom implements turn.v1.Turnd.
func (*Server) Credentials ¶
func (s *Server) Credentials(ctx context.Context, _ *turnv1.CredentialsRequest) (*turnv1.IceServers, error)
Credentials implements turn.v1.Turnd.
func (*Server) Deny ¶
Deny implements turn.v1.Turnd: it refuses a waiting guest, or removes an admitted one. Its token is dead.
func (*Server) JoinRoom ¶
func (s *Server) JoinRoom(_ context.Context, req *turnv1.JoinRoomRequest) (*turnv1.JoinRoomResponse, error)
JoinRoom implements turn.v1.Turnd.
func (*Server) MaxRecvMsgSize ¶
MaxRecvMsgSize is the gRPC receive bound that fits a message at its limit.
func (*Server) Register ¶
func (s *Server) Register(gs grpc.ServiceRegistrar)
Register adds the service to a gRPC server. Give that server grpc.MaxRecvMsgSize of at least Server.MaxRecvMsgSize.
func (*Server) RoomCredentials ¶
func (s *Server) RoomCredentials(ctx context.Context, req *turnv1.RoomRef) (*turnv1.IceServers, error)
RoomCredentials implements turn.v1.Turnd.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client is the rendezvous client: a real grpc-go client of turn.v1.Turnd, dialed over a WebSocket (github.com/grpc-transports/websocket), which in a browser (GOOS=js) is the browser's WebSocket through syscall/js.
|
Package client is the rendezvous client: a real grpc-go client of turn.v1.Turnd, dialed over a WebSocket (github.com/grpc-transports/websocket), which in a browser (GOOS=js) is the browser's WebSocket through syscall/js. |