peer

package
v0.0.0-...-60d7611 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package peer owns the PeerConnection and the offer/answer exchange. It sends descriptions and candidates through a Signaler, so the same code can negotiate over the signaling server or, later, over the data channel.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Codecs       *mediadevices.CodecSelector
	Signaler     Signaler
	ChannelLabel string

	OnTrack       func(*webrtc.TrackRemote)
	OnDataChannel func(*webrtc.DataChannel) // both the one created here and the one received
	// OnSendersReady runs once the descriptions have started the RTP senders.
	OnSendersReady func()
	// OnEnded runs when the connection closes or fails, possibly more than once.
	OnEnded func()
}

Config wires the connection to the rest of the client. The callbacks run on pion goroutines, except OnSendersReady, which runs inside Handle.

type Peer

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

Peer is one side of the call.

func New

func New(cfg Config) (*Peer, error)

New builds the PeerConnection with the given codecs and hooks up the callbacks. Nothing is sent until Handle gets a peer_joined or an offer.

func (*Peer) Close

func (p *Peer) Close() error

Close closes the peer connection.

func (*Peer) Conn

func (p *Peer) Conn() *webrtc.PeerConnection

Conn returns the underlying connection, for adding tracks and transceivers before the first offer.

func (*Peer) Handle

func (p *Peer) Handle(env messages.Envelope) error

Handle takes the negotiation messages: peer_joined, sdp and ice.

func (*Peer) RTT

func (p *Peer) RTT() (rtt time.Duration, ok bool)

RTT is the latest round trip ICE measured on the path in use. ok is false until a path exists.

func (*Peer) State

func (p *Peer) State() webrtc.PeerConnectionState

State reports the state of the peer connection.

type Signaler

type Signaler interface {
	Send(msgType string, payload any) error
	Closed() bool
}

Signaler carries descriptions and candidates to the other peer.

Jump to

Keyboard shortcuts

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