Help us shape the future of Go! Take the 2026 Go Developer Survey

internal

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildRecvOfferSDP

func BuildRecvOfferSDP(transport TransportOptions, consumers []ConsumerData, sdpVersion int) string

BuildRecvOfferSDP constructs a fake SDP offer with one media section per consumer. Used to feed mediasoup's consumer tracks into pion's recv PC.

func BuildSendAnswerSDP

func BuildSendAnswerSDP(offerSDP string, transport TransportOptions) string

BuildSendAnswerSDP constructs a fake SDP answer from mediasoup's transport parameters to pair with pion's SDP offer for a send transport.

The answer uses mediasoup's ICE/DTLS credentials and candidates while mirroring the offer's codec negotiation. This tricks pion into establishing an ICE/DTLS connection directly to mediasoup.

func ExtractSSRC

func ExtractSSRC(sdp string) uint32

ExtractSSRC extracts the first a=ssrc value from an SDP.

func NegotiateRecvSDP

func NegotiateRecvSDP(pc *webrtc.PeerConnection, offerSDP string) (string, error)

NegotiateRecvSDP sets the given offer SDP as remote description, creates an answer forcing DTLS client role, and returns the answer SDP.

func StartRecvPC

func StartRecvPC(l *log.Logger, clientIP string, vp9PT uint8, impairment *pionutil.ImpairmentBinding) (*webrtc.PeerConnection, error)

StartRecvPC creates a PeerConnection for receiving tracks. It forces the DTLS answering role to client (active) to work with mediasoup ICE Lite.

func StartSendPC

func StartSendPC(l *log.Logger, clientIP string, vp9PT uint8, initialBitrateBps int, impairment *pionutil.ImpairmentBinding) (
	*webrtc.PeerConnection, *webrtc.TrackLocalStaticRTP, func() int, string, error,
)

StartSendPC creates a PeerConnection with a VP9 send track and GCC bandwidth estimation. Returns the PC, RTP track, bandwidth getter, and the offer SDP.

func StartSendPCSimple

func StartSendPCSimple(l *log.Logger, clientIP string, vp9PT uint8, impairment *pionutil.ImpairmentBinding) (
	*webrtc.PeerConnection, *webrtc.TrackLocalStaticSample, string, error,
)

StartSendPCSimple creates a PeerConnection with a VP9 sample track (no SVC/GCC).

Types

type ConsumerData

type ConsumerData struct {
	PeerID         string         `json:"peerId"`
	ProducerID     string         `json:"producerId"`
	ID             string         `json:"consumerId"`
	Kind           string         `json:"kind"`
	RtpParameters  RtpParameters  `json:"rtpParameters"`
	Type           string         `json:"type"`
	ProducerPaused bool           `json:"producerPaused"`
	AppData        map[string]any `json:"appData,omitempty"`
}

ConsumerData is the payload of a "newConsumer" server request.

type DtlsFingerprint

type DtlsFingerprint struct {
	Algorithm string `json:"algorithm"`
	Value     string `json:"value"`
}

DtlsFingerprint is a single DTLS certificate fingerprint.

func ExtractDtlsFingerprint

func ExtractDtlsFingerprint(sdp string) DtlsFingerprint

ExtractDtlsFingerprint extracts the first DTLS fingerprint from an SDP.

type DtlsParameters

type DtlsParameters struct {
	Fingerprints []DtlsFingerprint `json:"fingerprints"`
	Role         string            `json:"role"`
}

DtlsParameters contains the DTLS fingerprints and role for a transport.

type IceCandidate

type IceCandidate struct {
	Foundation string `json:"foundation"`
	Priority   uint32 `json:"priority"`
	Address    string `json:"address,omitempty"` // mediasoup v3.13+
	IP         string `json:"ip,omitempty"`      // older mediasoup
	Protocol   string `json:"protocol"`
	Port       uint16 `json:"port"`
	Type       string `json:"type"`
}

IceCandidate is a single ICE candidate from a transport.

func (IceCandidate) Addr

func (c IceCandidate) Addr() string

Addr returns the candidate's IP address, preferring the newer "address" field.

type IceParameters

type IceParameters struct {
	UsernameFragment string `json:"usernameFragment"`
	Password         string `json:"password"`
	IceLite          bool   `json:"iceLite"`
}

IceParameters contains the ICE credentials for a transport.

type JoinResult

type JoinResult struct {
	Peers []PeerInfo `json:"peers"`
}

JoinResult is returned by the "join" request.

type NotificationHandler

type NotificationHandler func(method string, data json.RawMessage)

NotificationHandler handles server-initiated notifications.

type PeerInfo

type PeerInfo struct {
	ID          string `json:"peerId"`
	DisplayName string `json:"displayName"`
}

PeerInfo describes one peer in a room.

type ProduceResult

type ProduceResult struct {
	ID string `json:"producerId"`
}

ProduceResult is returned by the "produce" request.

type Protoo

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

Protoo is a protoo-protocol WebSocket client.

func NewProtoo

func NewProtoo(
	ctx context.Context,
	wsURL string,
	l *log.Logger,
	onReq RequestHandler,
	onNotify NotificationHandler,
) (*Protoo, error)

NewProtoo connects to the given protoo WebSocket URL and starts the read loop.

func (*Protoo) Close

func (p *Protoo) Close()

Close gracefully shuts down the connection.

func (*Protoo) Notify

func (p *Protoo) Notify(method string, data any) error

Notify sends a protoo notification (fire-and-forget).

func (*Protoo) Request

func (p *Protoo) Request(method string, data any) (json.RawMessage, error)

Request sends a protoo request and waits for the response.

type RequestHandler

type RequestHandler func(method string, data json.RawMessage) (any, error)

RequestHandler handles server-initiated requests. Returns response data or error.

type RtcpFeedback

type RtcpFeedback struct {
	Type      string `json:"type"`
	Parameter string `json:"parameter,omitempty"`
}

RtcpFeedback describes a single RTCP feedback mechanism.

type RtcpParameters

type RtcpParameters struct {
	CNAME       string `json:"cname,omitempty"`
	ReducedSize bool   `json:"reducedSize,omitempty"`
	Mux         bool   `json:"mux,omitempty"`
}

RtcpParameters describes RTCP behaviour for a producer/consumer.

type RtpCapabilities

type RtpCapabilities struct {
	Codecs           []RtpCodecCapability `json:"codecs"`
	HeaderExtensions []RtpHeaderExtension `json:"headerExtensions"`
}

RtpCapabilities describes the router's (or device's) supported codecs and header extensions.

type RtpCodecCapability

type RtpCodecCapability struct {
	Kind                 string         `json:"kind"`
	MimeType             string         `json:"mimeType"`
	PreferredPayloadType int            `json:"preferredPayloadType"`
	ClockRate            int            `json:"clockRate"`
	Channels             int            `json:"channels,omitempty"`
	Parameters           map[string]any `json:"parameters,omitempty"`
	RtcpFeedback         []RtcpFeedback `json:"rtcpFeedback,omitempty"`
}

RtpCodecCapability is a codec entry in router/device capabilities.

type RtpCodecParameters

type RtpCodecParameters struct {
	MimeType     string         `json:"mimeType"`
	PayloadType  int            `json:"payloadType"`
	ClockRate    int            `json:"clockRate"`
	Channels     int            `json:"channels,omitempty"`
	Parameters   map[string]any `json:"parameters,omitempty"`
	RtcpFeedback []RtcpFeedback `json:"rtcpFeedback,omitempty"`
}

RtpCodecParameters is a codec in producer/consumer RTP parameters.

type RtpEncoding

type RtpEncoding struct {
	SSRC            *uint32     `json:"ssrc,omitempty"`
	RTX             *RtxMapping `json:"rtx,omitempty"`
	Rid             string      `json:"rid,omitempty"`
	ScalabilityMode string      `json:"scalabilityMode,omitempty"`
	Dtx             bool        `json:"dtx,omitempty"`
}

RtpEncoding describes one encoding layer (single or SVC).

type RtpHeaderExtParam

type RtpHeaderExtParam struct {
	URI        string `json:"uri"`
	ID         int    `json:"id"`
	Encrypt    bool   `json:"encrypt,omitempty"`
	Parameters any    `json:"parameters,omitempty"`
}

RtpHeaderExtParam is a header extension in producer/consumer RTP parameters.

type RtpHeaderExtension

type RtpHeaderExtension struct {
	Kind             string `json:"kind"`
	URI              string `json:"uri"`
	PreferredID      int    `json:"preferredId"`
	PreferredEncrypt bool   `json:"preferredEncrypt"`
	Direction        string `json:"direction,omitempty"`
}

RtpHeaderExtension is a header extension in router/device capabilities.

type RtpParameters

type RtpParameters struct {
	Codecs           []RtpCodecParameters `json:"codecs"`
	HeaderExtensions []RtpHeaderExtParam  `json:"headerExtensions,omitempty"`
	Encodings        []RtpEncoding        `json:"encodings"`
	Rtcp             *RtcpParameters      `json:"rtcp,omitempty"`
	Mid              string               `json:"mid,omitempty"`
}

RtpParameters describe how RTP is sent/received for a producer or consumer.

func ExtractRtpParameters

func ExtractRtpParameters(offerSDP string, routerCaps RtpCapabilities) RtpParameters

ExtractRtpParameters builds mediasoup RtpParameters from pion's offer SDP.

type RtxMapping

type RtxMapping struct {
	SSRC uint32 `json:"ssrc"`
}

RtxMapping holds the RTX SSRC paired with a media encoding.

type TransportOptions

type TransportOptions struct {
	ID             string         `json:"transportId"`
	IceParameters  IceParameters  `json:"iceParameters"`
	IceCandidates  []IceCandidate `json:"iceCandidates"`
	DtlsParameters DtlsParameters `json:"dtlsParameters"`
}

TransportOptions are returned by createWebRtcTransport.

Jump to

Keyboard shortcuts

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