session

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoLocalDescription = errors.New("local description nil after ICE gathering")

ErrNoLocalDescription is returned when ICE gathering completes with no local description.

View Source
var ErrOnFramesAlreadyRunning = errors.New("OnFrames already running on this channel")

ErrOnFramesAlreadyRunning is returned by Channel.OnFrames when called more than once on the same Channel.

Functions

This section is empty.

Types

type Channel added in v0.2.0

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

Channel is a framed wrapper over a pion DataChannel.

func (*Channel) Close added in v0.2.0

func (c *Channel) Close() error

Close closes the underlying DataChannel.

func (*Channel) Closed added in v0.2.0

func (c *Channel) Closed() <-chan struct{}

Closed returns a channel closed when the underlying DataChannel closes.

func (*Channel) Flush added in v0.2.0

func (c *Channel) Flush(
	timeout time.Duration,
	now func() time.Time,
)

Flush waits up to timeout for the outgoing buffer to drain

func (*Channel) Label added in v0.2.0

func (c *Channel) Label() string

Label returns the underlying DataChannel's label.

func (*Channel) OnFrames added in v0.2.0

func (c *Channel) OnFrames(
	ctx context.Context,
	handler protocol.FrameHandler,
	bufSize int,
) error

OnFrames runs the receive loop, dispatching every incoming frame to handler via protocol.Dispatch.

func (*Channel) Open added in v0.2.0

func (c *Channel) Open() <-chan struct{}

Open returns a channel closed when the underlying DataChannel opens.

func (*Channel) SendAbort added in v0.2.0

func (c *Channel) SendAbort(reason string) error

SendAbort sends an ABORT frame carrying a free-form reason string.

func (*Channel) SendAddPeerAnswer added in v0.2.0

func (c *Channel) SendAddPeerAnswer(peerID uint8, sdp string) error

SendAddPeerAnswer sends an ADD_PEER_ANSWER frame with peerID and the answer SDP.

func (*Channel) SendAddPeerOffer added in v0.2.0

func (c *Channel) SendAddPeerOffer(peerID uint8, sdp string) error

SendAddPeerOffer sends an ADD_PEER_OFFER frame with peerID and the offer SDP.

func (*Channel) SendData added in v0.2.0

func (c *Channel) SendData(
	ctx context.Context,
	offset uint64,
	payload []byte,
) error

SendData encodes payload as a DATA frame, sends it, then waits for the outgoing buffer to drain below bufferThreshold before returning.

func (*Channel) SendEOF added in v0.2.0

func (c *Channel) SendEOF() error

SendEOF sends a one-byte EOF frame.

func (*Channel) SendMetadata added in v0.2.0

func (c *Channel) SendMetadata(meta protocol.Metadata) error

SendMetadata encodes meta and sends it as a METADATA frame.

func (*Channel) SendTransferComplete added in v0.2.0

func (c *Channel) SendTransferComplete() error

SendTransferComplete sends a one-byte TRANSFER_COMPLETE frame.

type Config added in v0.2.0

type Config struct {
	// STUNServers are the full ICE STUN URLs ("stun:host:port"). A nil
	// or empty slice disables STUN entirely — the session will produce
	// only host (and mDNS) candidates. Passed through to webrtc.ICEServer.URLs.
	STUNServers []string

	// LoopbackOnly pins ICE to loopback-only interfaces and drops STUN,
	// so the session produces only host candidates on lo0. Intended for
	// the in-process benchmark (just bench) — deterministic path, no
	// network interface required.
	LoopbackOnly bool

	// DisableMDNS suppresses mDNS candidate gathering. When false (the
	// zero value), the session advertises a `.local` hostname for its
	// host candidates instead of a raw LAN IP, matching browser
	// behavior. Ignored under LoopbackOnly.
	DisableMDNS bool

	// ICELite enables pion's ICE-Lite mode, which skips the connectivity-
	// check loop.
	//
	// Test-only: it's only safe when both peers are ICE-lite
	// on a guaranteed-routable path (e.g. loopback in-process).
	//
	// Production transfers must leave this false.
	ICELite bool
}

Config describes the networking knobs for a PeerConnection-backed Session. A zero value is valid: no STUN, no loopback pinning, mDNS gathering on. The CLI layer is responsible for providing a default STUN server when one is wanted.

type Session

type Session struct {
	Done         chan struct{}
	NetworkStats *stats.Stats
	// contains filtered or unexported fields
}

Session wraps a pion PeerConnection with lifecycle state.

func New

func New(cfg Config) Session

New creates a sender-side Session from cfg.

func NewReceiver added in v0.2.0

func NewReceiver(cfg Config) Session

NewReceiver creates a Session with pion's DetachDataChannels enabled. Callers must invoke DataChannel.Detach() in OnOpen and drive their own Read loop — OnMessage never fires once detach is on.

func (*Session) AcceptAnswer added in v0.2.0

func (s *Session) AcceptAnswer(encodedAnswer string) error

AcceptAnswer sets the remote answer on a PeerConnection whose offer was already sent.

func (*Session) AcceptOffer added in v0.2.0

func (s *Session) AcceptOffer(encodedOffer string) (string, error)

AcceptOffer sets the remote offer, creates an answer, and waits for ICE gathering.

func (*Session) Close added in v0.2.0

func (s *Session) Close() error

Close releases the PeerConnection. Safe before CreateConnection and idempotent.

func (*Session) CreateChannel added in v0.2.0

func (s *Session) CreateChannel(label string) (*Channel, error)

CreateChannel creates an outgoing DataChannel wrapped as a *Channel.

func (*Session) CreateConnection

func (s *Session) CreateConnection(
	onConnectionStateChange func(connectionState webrtc.ICEConnectionState),
) error

CreateConnection prepares a WebRTC connection.

func (*Session) IsICELite added in v0.2.0

func (s *Session) IsICELite() bool

IsICELite reports whether the session was configured with ICELite.

func (*Session) IsLoopbackOnly added in v0.2.0

func (s *Session) IsLoopbackOnly() bool

IsLoopbackOnly reports whether the session was configured with LoopbackOnly.

func (*Session) MakeOffer added in v0.2.0

func (s *Session) MakeOffer() (string, error)

MakeOffer creates the offer, sets it locally, and waits for ICE gathering.

func (*Session) OnChannel added in v0.2.0

func (s *Session) OnChannel(handler func(*Channel))

OnChannel registers a handler invoked for every incoming DataChannel.

Jump to

Keyboard shortcuts

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