sfu

package
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package sfu forwards RTP between participants with pion/webrtc. The server is the only offerer; clients only answer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine owns the pion settings and the shared UDP socket.

func NewEngine

func NewEngine(cfg EngineConfig, log *slog.Logger) (*Engine, error)

func (*Engine) Close

func (e *Engine) Close() error

func (*Engine) NewPeer

func (e *Engine) NewPeer(id string, sig media.Signaler, h media.Handlers) (*Peer, error)

func (*Engine) Port

func (e *Engine) Port() int

Port is the bound UDP port (useful when 0 was requested).

func (*Engine) TCPPort

func (e *Engine) TCPPort() int

TCPPort is the ICE-TCP port, or 0 when ICE-TCP is off.

type EngineConfig

type EngineConfig struct {
	UDPPort int
	// TCP adds a passive ICE-TCP candidate on TCPPort, for clients whose UDP path to the
	// server is blocked or unreliable. Browsers prefer UDP and fall back to it on their own.
	TCP             bool
	TCPPort         int
	AdvertiseIP     string
	IncludeLoopback bool // tests only
}

EngineConfig selects the UDP port and the single advertised host address.

type Peer

type Peer struct {
	// contains filtered or unexported fields
}

Peer is one participant's connection to the SFU.

func (*Peer) AddICECandidate

func (p *Peer) AddICECandidate(c media.Candidate) error

AddICECandidate adds a candidate the client sent.

func (*Peer) Close

func (p *Peer) Close() error

func (*Peer) HandleAnswer

func (p *Peer) HandleAnswer(sdp string) error

HandleAnswer applies the client's answer to the outstanding offer.

func (*Peer) ID

func (p *Peer) ID() string

func (*Peer) Negotiate

func (p *Peer) Negotiate()

Negotiate sends an offer now, or marks the peer dirty when one is outstanding.

func (*Peer) Publishes added in v0.4.2

func (p *Peer) Publishes(kind media.Kind) bool

Publishes reports whether this peer's track of kind has arrived.

func (*Peer) RequestKeyframe

func (p *Peer) RequestKeyframe(kind media.Kind)

RequestKeyframe asks this peer's browser for a keyframe on its published track.

func (*Peer) Sample

func (p *Peer) Sample() (s quality.Sample, ok bool)

Sample measures this participant's connection from the peer connection statistics. Uplink loss covers the time since the previous call. ok is false until there is anything to measure.

func (*Peer) Subscribe

func (p *Peer) Subscribe(src media.Source, kind media.Kind) error

Subscribe attaches from's track of the given kind to this peer and renegotiates.

func (*Peer) Track

func (p *Peer) Track(kind media.Kind) *webrtc.TrackLocalStaticRTP

func (*Peer) Transport

func (p *Peer) Transport() string

Transport names the protocol of the selected ICE candidate pair ("udp" or "tcp"), or "" before the connection is up.

func (*Peer) Unsubscribe

func (p *Peer) Unsubscribe(from media.Source, kind media.Kind) error

Unsubscribe detaches from's track; a no-op when not subscribed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址