Documentation
¶
Overview ¶
Package rtc wraps Pion: one Engine per process (codec + ICE settings), one Peer per browser connection. It reproduces the SmallWebRTCConnection contract: non-trickle answers (ICE gathering completes before the answer is returned), an opaque pc_id, renegotiation on re-offer, and a "closed" event when the connection ends for any reason.
Index ¶
- Constants
- func NewPeerID() string
- type Engine
- type EngineConfig
- type Peer
- func (p *Peer) Close()
- func (p *Peer) Connected() bool
- func (p *Peer) Done() <-chan struct{}
- func (p *Peer) Renegotiate(offerSDP, offerType string) (*webrtc.SessionDescription, error)
- func (p *Peer) Stats() (received, concealed, fec, dropped uint64)
- func (p *Peer) WriteOpus(payload []byte, timestamp uint32, marker bool) error
- type PeerHandler
Constants ¶
const FrameSamples = 960
FrameSamples is a 20 ms Opus frame at 48 kHz.
const OpusClockRate = 48000
OpusClockRate is fixed by RFC 7587.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine builds peers.
func NewEngine ¶
func NewEngine(cfg EngineConfig) (*Engine, error)
NewEngine registers Opus (48 kHz, 2 ch as the SDP requires; we send mono packets, which Opus/browsers handle) and the default RTCP interceptors.
func (*Engine) NewPeer ¶
func (e *Engine) NewPeer(id string, offerSDP, offerType string, h PeerHandler) (*Peer, *webrtc.SessionDescription, error)
NewPeer creates a peer connection, applies the browser's offer and returns the complete (non-trickle) answer.
type EngineConfig ¶
type EngineConfig struct {
ICEServers []config.ICEServer
UDPPortMin int
UDPPortMax int
NAT1To1IPs []string
Logger *slog.Logger
}
EngineConfig configures the shared API.
type Peer ¶
type Peer struct {
ID string
// contains filtered or unexported fields
}
Peer is one browser connection.
func (*Peer) Close ¶
func (p *Peer) Close()
Close tears the connection down; OnClosed fires (once) as a result.
func (*Peer) Renegotiate ¶
func (p *Peer) Renegotiate(offerSDP, offerType string) (*webrtc.SessionDescription, error)
Renegotiate applies a new offer on the existing connection (ICE restart is handled by Pion when the remote ufrag/pwd change).
type PeerHandler ¶
type PeerHandler interface {
OnAudio(pcm []int16)
OnConnected()
OnClosed()
}
PeerHandler receives connection events. OnAudio runs on the peer's reader goroutine with 48 kHz mono PCM for each decoded (or concealed) frame; the slice is only valid for the duration of the call.