Documentation
¶
Overview ¶
Package webrtc terminates 1v1 WebRTC AI voice calls over HTTP SDP signaling.
Browser ── POST /offer (SDP) ──► Server ── dialog WS ──► Dialog App
◄── SRTP/Opus (TTS) ──── ◄── tts.speak ─── ── SRTP/Opus (mic) ────► ── asr.* ────────►
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildAPI ¶
func BuildAPI(cfg EngineConfig) (*pionwebrtc.API, error)
BuildAPI constructs a *pionwebrtc.API with our codec + interceptor configuration baked in. The returned API is goroutine-safe and intended to be reused across every PeerConnection in the process.
func ParseICEServers ¶
func ParseICEServers(spec string) ([]pionwebrtc.ICEServer, error)
ParseICEServers turns a comma-separated env-var spec into a slice of ICEServer entries. Format per entry:
scheme://host:port[?username=U&credential=C]
where scheme is one of stun, turn, turns. Credentials only apply to turn:/turns:. Whitespace around entries is trimmed.
Types ¶
type EngineConfig ¶
type EngineConfig struct {
// ICEServers is the STUN / TURN server list passed to every peer.
// At minimum supply a public STUN server (e.g.
// stun:stun.l.google.com:19302); add a TURN server for clients
// behind symmetric NATs.
ICEServers []pionwebrtc.ICEServer
// PublicIPs lists addresses reachable from the public internet that
// should be advertised as ICE host candidates. Required when the
// process runs in a container / behind a 1:1 NAT — pion otherwise
// only sees the private bind address. Empty = no NAT 1:1.
PublicIPs []string
// UDPMux, when set, multiplexes all ICE UDP traffic onto a single
// listening socket. Recommended in production: only one UDP port has
// to be opened on the firewall regardless of concurrent calls.
// nil = pion ephemerally allocates per call.
UDPMux ice.UDPMux
// SinglePort, if >0 and UDPMux is nil, makes pion bind one fixed UDP
// port for ICE instead of an ephemeral range. Easier to firewall.
SinglePort int
}
EngineConfig configures the per-process pion API used by every call.
type OfferRequest ¶
type OfferRequest struct {
SDP string `json:"sdp"`
Type string `json:"type"`
Payload json.RawMessage `json:"payload,omitempty"`
ApiKey string `json:"apiKey,omitempty"`
ApiSecret string `json:"apiSecret,omitempty"`
AgentId string `json:"agentId,omitempty"`
}
OfferRequest is the JSON body for POST /webrtc/v1/offer.
type SDPMessage ¶
type SDPMessage struct {
SDP string `json:"sdp"`
Type string `json:"type"`
CallID string `json:"call_id,omitempty"`
}
SDPMessage is the wire shape of offer/answer payloads.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the HTTP signaling entry point.
func NewServer ¶
func NewServer(cfg ServerConfig) (*Server, error)
NewServer validates cfg and builds the shared pion API.
func (*Server) HandleHangup ¶
func (s *Server) HandleHangup(w http.ResponseWriter, r *http.Request)
HandleHangup terminates a call by ID.
func (*Server) HandleOffer ¶
func (s *Server) HandleOffer(w http.ResponseWriter, r *http.Request)
HandleOffer completes SDP negotiation for one browser call.
type ServerConfig ¶
type ServerConfig struct {
SessionFactory transport.SessionFactory
DialogWSURL string
Engine EngineConfig
ICEServers []pionwebrtc.ICEServer
CallIDPrefix string
AllowedOrigins []string
DenoiserFactory func() asr.Denoiser
ConfigureClient func(*gateway.ClientConfig)
OnSessionStart func(ctx context.Context, callID, peerInfo string)
OnSessionEnd func(ctx context.Context, callID, reason string)
}
ServerConfig wires the WebRTC adapter to dialog.Session.