Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyToSettingEngine(se *webrtc.SettingEngine, config ICEConfig) error
- func BuildTURNURLs(host string, port int, protocols ...TURNProtocol) []string
- func CanAttemptICERestart(state webrtc.ICEConnectionState) bool
- func CreateIPFilter(allowedCIDRs []string) (func(net.IP) bool, error)
- func CreateInterfaceFilter(allowedInterfaces []string) func(string) bool
- func DefaultCandidatePriorities() map[CandidateType]uint32
- func DetectNetworkChange(ctx context.Context) <-chan struct{}
- func HasFeedback(feedback []RTCPFeedback, target RTCPFeedback) bool
- func ICERestartWithBackoff(ctx context.Context, pc *webrtc.PeerConnection, maxAttempts int, ...) (*webrtc.SessionDescription, error)
- func IPPriorityFilter(preferIPv4 bool) func(net.IP) bool
- func IPv4Priority() uint32
- func IPv6Priority() uint32
- func IsICELiteCompatible(sdp string) bool
- func IsSVCCodec(name VideoCodecName) bool
- func NeedsICERestart(state webrtc.ICEConnectionState) bool
- func NewMediaEngineWithConfig(config CodecConfig) (*webrtc.MediaEngine, error)
- func NewMediaEngineWithDefaults() (*webrtc.MediaEngine, error)
- func RegisterCodecs(m *webrtc.MediaEngine, config CodecConfig) error
- func RegisterHeaderExtensions(m *webrtc.MediaEngine, config HeaderExtensionConfig) error
- func RequiredAudioExtensions() []string
- func RequiredVideoExtensions() []string
- func ToWebRTCFeedbackSlice(feedback []RTCPFeedback) []webrtc.RTCPFeedback
- func ValidateCodecConfig(config CodecConfig) error
- func ValidateHeaderExtensionConfig(config HeaderExtensionConfig) error
- func ValidateICEConfig(config ICEConfig) error
- type AudioCodecConfig
- type AudioCodecName
- type CandidatePriority
- type CandidateType
- type CodecConfig
- func (c *CodecConfig) AddAudioCodec(ac AudioCodecConfig)
- func (c *CodecConfig) AddVideoCodec(vc VideoCodecConfig)
- func (c CodecConfig) Copy() CodecConfig
- func (c CodecConfig) GetAudioCodecByName(name AudioCodecName) *AudioCodecConfig
- func (c CodecConfig) GetAudioCodecNames() []AudioCodecName
- func (c CodecConfig) GetVideoCodecByName(name VideoCodecName) *VideoCodecConfig
- func (c CodecConfig) GetVideoCodecNames() []VideoCodecName
- func (c CodecConfig) HasAudioCodec(name AudioCodecName) bool
- func (c CodecConfig) HasVideoCodec(name VideoCodecName) bool
- func (c *CodecConfig) RemoveAudioCodec(name AudioCodecName)
- func (c *CodecConfig) RemoveVideoCodec(name VideoCodecName)
- func (c *CodecConfig) SetAudioCodecPriority(name AudioCodecName, priority int)
- func (c *CodecConfig) SetVideoCodecPriority(name VideoCodecName, priority int)
- func (c *CodecConfig) SortByPriority()
- type CodecInfo
- type ConnectionStateHandler
- type DataChannelHandler
- type EventHandler
- type ExtensionDirection
- type ExtensionID
- type H264Profile
- type H264ProfileConfig
- type HeaderExtension
- type HeaderExtensionConfig
- func (c *HeaderExtensionConfig) AddAudioExtension(ext HeaderExtension)
- func (c *HeaderExtensionConfig) AddVideoExtension(ext HeaderExtension)
- func (c HeaderExtensionConfig) Copy() HeaderExtensionConfig
- func (c HeaderExtensionConfig) GetAudioExtension(uri string) *HeaderExtension
- func (c HeaderExtensionConfig) GetAudioExtensionURIs() []string
- func (c HeaderExtensionConfig) GetVideoExtension(uri string) *HeaderExtension
- func (c HeaderExtensionConfig) GetVideoExtensionURIs() []string
- func (c HeaderExtensionConfig) HasAudioExtension(uri string) bool
- func (c HeaderExtensionConfig) HasRequiredAudioExtensions() bool
- func (c HeaderExtensionConfig) HasRequiredVideoExtensions() bool
- func (c HeaderExtensionConfig) HasVideoExtension(uri string) bool
- func (c *HeaderExtensionConfig) RemoveAudioExtension(uri string)
- func (c *HeaderExtensionConfig) RemoveVideoExtension(uri string)
- type ICECandidateErrorHandler
- type ICECandidateHandler
- type ICEConfig
- type ICEConnectionStateHandler
- type ICERestartConfig
- type ICERestartEvent
- type ICERestartHandler
- type ICERestartManager
- func (m *ICERestartManager) Close()
- func (m *ICERestartManager) GetLastRestartTime() time.Time
- func (m *ICERestartManager) GetTotalRestartAttempts() int32
- func (m *ICERestartManager) HandleICEConnectionStateChange(state webrtc.ICEConnectionState)
- func (m *ICERestartManager) IsRestartInProgress() bool
- func (m *ICERestartManager) OnRestartCompleted(fn func(result ICERestartResult))
- func (m *ICERestartManager) OnRestartStarted(fn func(reason string))
- func (m *ICERestartManager) Reset()
- func (m *ICERestartManager) SetOfferHandler(handler ICERestartHandler)
- func (m *ICERestartManager) SetPeerConnection(pc *webrtc.PeerConnection)
- func (m *ICERestartManager) TriggerRestart(ctx context.Context, reason string) ICERestartResult
- type ICERestartResult
- type ICEServerConfig
- type ICEServersConfig
- type NegotiationNeededHandler
- type NetworkType
- type OpusFMTPParams
- type Peer
- func (p *Peer) AddICECandidate(candidate webrtc.ICECandidateInit) error
- func (p *Peer) AddTrack(track webrtc.TrackLocal) (*webrtc.RTPSender, error)
- func (p *Peer) AddTransceiverFromKind(kind webrtc.RTPCodecType, init ...webrtc.RTPTransceiverInit) (*webrtc.RTPTransceiver, error)
- func (p *Peer) Close() error
- func (p *Peer) CloseWithContext(ctx context.Context) error
- func (p *Peer) ConnectionState() webrtc.PeerConnectionState
- func (p *Peer) CreateAnswer() (webrtc.SessionDescription, error)
- func (p *Peer) CreateOffer() (webrtc.SessionDescription, error)
- func (p *Peer) CreatedAt() time.Time
- func (p *Peer) Duration() time.Duration
- func (p *Peer) GetReceivers() []*webrtc.RTPReceiver
- func (p *Peer) GetSenders() []*webrtc.RTPSender
- func (p *Peer) GetTransceivers() []*webrtc.RTPTransceiver
- func (p *Peer) HandleAnswer(ctx context.Context, sdp string) error
- func (p *Peer) HandleCandidate(ctx context.Context, candidate string, sdpMid string, sdpMLineIndex *int) error
- func (p *Peer) HandleOffer(ctx context.Context, sdp string) (string, error)
- func (p *Peer) ICEConnectionState() webrtc.ICEConnectionState
- func (p *Peer) ID() string
- func (p *Peer) LocalDescription() *webrtc.SessionDescription
- func (p *Peer) OnConnectionStateChange(handler ConnectionStateHandler)
- func (p *Peer) OnDataChannel(handler DataChannelHandler)
- func (p *Peer) OnICECandidate(handler ICECandidateHandler)
- func (p *Peer) OnICECandidateError(handler ICECandidateErrorHandler)
- func (p *Peer) OnICEConnectionStateChange(handler ICEConnectionStateHandler)
- func (p *Peer) OnNegotiationNeeded(handler NegotiationNeededHandler)
- func (p *Peer) OnTrack(handler TrackHandler)
- func (p *Peer) PeerConnection() *webrtc.PeerConnection
- func (p *Peer) RemoteDescription() *webrtc.SessionDescription
- func (p *Peer) RemoveTrack(sender *webrtc.RTPSender) error
- func (p *Peer) RestartICE() error
- func (p *Peer) SCTP() *webrtc.SCTPTransport
- func (p *Peer) SetRemoteDescription(sdp webrtc.SessionDescription) error
- func (p *Peer) SignalingState() webrtc.SignalingState
- func (p *Peer) State() PeerState
- type PeerConfig
- type PeerState
- type PortRange
- type RTCPFeedback
- func AddFeedback(feedback []RTCPFeedback, target RTCPFeedback) []RTCPFeedback
- func DefaultAudioRTCPFeedback() []RTCPFeedback
- func DefaultVideoRTCPFeedback() []RTCPFeedback
- func EnsureRequiredAudioFeedback(feedback []RTCPFeedback) []RTCPFeedback
- func EnsureRequiredVideoFeedback(feedback []RTCPFeedback) []RTCPFeedback
- func RTCPFeedbackFromWebRTC(f webrtc.RTCPFeedback) RTCPFeedback
- func RemoveFeedback(feedback []RTCPFeedback, target RTCPFeedback) []RTCPFeedback
- func RequiredAudioFeedback() []RTCPFeedback
- func RequiredVideoFeedback() []RTCPFeedback
- func ValidateAudioFeedback(feedback []RTCPFeedback) []RTCPFeedback
- func ValidateVideoFeedback(feedback []RTCPFeedback) []RTCPFeedback
- type RTCPFeedbackConfig
- type RTCPFeedbackParam
- type RTCPFeedbackType
- type SDPConfig
- type SDPProcessor
- func (p *SDPProcessor) AddAttribute(sdpStr string, key string, value string) (string, error)
- func (p *SDPProcessor) EnsureUnifiedPlan(sd *sdp.SessionDescription) error
- func (p *SDPProcessor) ExtractCodecs(sdpStr string) ([]CodecInfo, error)
- func (p *SDPProcessor) ExtractMIDs(sdpStr string) ([]string, error)
- func (p *SDPProcessor) ExtractSSRCs(sdpStr string) ([]uint32, error)
- func (p *SDPProcessor) ExtractSimulcastLayers(sdpStr string) ([]SimulcastLayer, error)
- func (p *SDPProcessor) GetBundleGroup(sdpStr string) ([]string, error)
- func (p *SDPProcessor) GetFingerprint(sdpStr string) (algorithm string, fingerprint string, err error)
- func (p *SDPProcessor) GetICECredentials(sdpStr string) (ufrag string, pwd string, err error)
- func (p *SDPProcessor) IsSimulcastEnabled(sdpStr string) (bool, error)
- func (p *SDPProcessor) ModifySDP(sdpStr string, modifier func(*sdp.SessionDescription) error) (string, error)
- func (p *SDPProcessor) NormalizeForSafari(sdpStr string) (string, error)
- func (p *SDPProcessor) ParseSDP(sdpStr string) (*sdp.SessionDescription, error)
- func (p *SDPProcessor) RemoveCodec(sdpStr string, codecName string) (string, error)
- func (p *SDPProcessor) SetCodecPriority(sdpStr string, mediaType string, priorities []string) (string, error)
- func (p *SDPProcessor) ValidateAnswer(answer webrtc.SessionDescription) error
- func (p *SDPProcessor) ValidateOffer(offer webrtc.SessionDescription) error
- type SVCCodecConfig
- type Service
- func (s *Service) Close() error
- func (s *Service) GetPeer(participantID string) *Peer
- func (s *Service) HandleAnswer(ctx context.Context, participantID string, sdp string) error
- func (s *Service) HandleCandidate(ctx context.Context, participantID string, candidate string, sdpMid string, ...) error
- func (s *Service) HandleOffer(ctx context.Context, participantID string, sdp string) (string, error)
- func (s *Service) RemovePeer(participantID string) error
- type SimulcastLayer
- type TURNConfig
- type TURNCredentialService
- type TURNCredentials
- type TURNProtocol
- type TrackHandler
- type VideoCodecConfig
- type VideoCodecName
Constants ¶
const ( // ExtensionURIMID is the URI for the MID (Media ID) extension. // Used to identify media sections in Unified Plan SDP. // See RFC 8843 (BUNDLE) and RFC 8851 (RID-based Simulcast). ExtensionURIMID = "urn:ietf:params:rtp-hdrext:sdes:mid" // ExtensionURIRID is the URI for the RID (Restriction ID) extension. // Used to identify simulcast layers. // See RFC 8851 (RTP Stream Identifier). ExtensionURIRID = "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id" // ExtensionURIRepairedRID is the URI for the repaired RID extension. // Used to identify repaired streams in RTX (retransmission). ExtensionURIRepairedRID = "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id" // ExtensionURITransportCC is the URI for transport-wide congestion control. // Used for TWCC (Transport-Wide Congestion Control). // See draft-holmer-rmcat-transport-wide-cc-extensions. ExtensionURITransportCC = "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01" // ExtensionURIAbsSendTime is the URI for absolute send time extension. // Used for measuring one-way delay and congestion control. ExtensionURIAbsSendTime = "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time" // ExtensionURIAudioLevel is the URI for audio level indication. // Used for voice activity detection and audio mixing. ExtensionURIAudioLevel = "urn:ietf:params:rtp-hdrext:ssrc-audio-level" // ExtensionURIVideoOrientation is the URI for video orientation. // Used for coordinating video rotation between sender and receiver. ExtensionURIVideoOrientation = "urn:3gpp:video-orientation" )
RTP Header Extension URIs per requirements.md (section 2.4.2) and design.md (section 3.6.2).
const ( DefaultUDPPortMin = 10000 DefaultUDPPortMax = 20000 )
Default port range per requirements.md (section 2.7.6).
const ( // DefaultConnectionTimeout is the default timeout for establishing a connection. DefaultConnectionTimeout = 30 * time.Second // DefaultDisconnectedTimeout is the time to wait before declaring disconnection. DefaultDisconnectedTimeout = 5 * time.Second // DefaultFailedTimeout is the time to wait before declaring failure. DefaultFailedTimeout = 25 * time.Second // DefaultKeepaliveInterval is the interval for sending keepalive packets. DefaultKeepaliveInterval = 2 * time.Second )
Default timeout values per requirements.md (section 2.7.3).
const ( // ICERestartReasonNetworkChange indicates network change detected. ICERestartReasonNetworkChange = "network_change" // ICERestartReasonConnectionFailed indicates ICE connection failed. ICERestartReasonConnectionFailed = "connection_failed" // ICERestartReasonExplicit indicates explicit restart request. ICERestartReasonExplicit = "explicit" // ICERestartReasonDisconnected indicates ICE disconnected state. ICERestartReasonDisconnected = "disconnected" )
ICE restart trigger reasons.
const ( // DefaultICERestartTimeout is the default timeout for ICE restart. DefaultICERestartTimeout = 30 * time.Second // DefaultDisconnectedThreshold is the time to wait before triggering restart on disconnect. DefaultDisconnectedThreshold = 5 * time.Second // DefaultMaxRestartAttempts is the maximum number of restart attempts. DefaultMaxRestartAttempts = 3 // DefaultRestartBackoff is the backoff duration between restart attempts. DefaultRestartBackoff = 2 * time.Second )
Default ICE restart configuration values.
const ( // DefaultCredentialTTL is the default validity period for TURN credentials (24 hours). DefaultCredentialTTL = 24 * time.Hour // DefaultRotationInterval is the default interval for credential rotation (12 hours). DefaultRotationInterval = 12 * time.Hour )
Default TURN credential parameters per requirements.md (section 2.7.2) and design.md (section 6.6).
Variables ¶
var ( // ErrUnknownVideoCodec is returned when an unknown video codec is specified. ErrUnknownVideoCodec = errors.New("unknown video codec") // ErrUnknownAudioCodec is returned when an unknown audio codec is specified. ErrUnknownAudioCodec = errors.New("unknown audio codec") // ErrH264NoProfiles is returned when H.264 codec has no profiles configured. ErrH264NoProfiles = errors.New("H.264 codec requires at least one profile") // ErrNoVideoCodecs is returned when no video codecs are configured. ErrNoVideoCodecs = errors.New("at least one video codec is required") // ErrNoAudioCodecs is returned when no audio codecs are configured. ErrNoAudioCodecs = errors.New("at least one audio codec is required") )
var ( // ErrDuplicateExtensionID is returned when duplicate extension IDs are found. ErrDuplicateExtensionID = errors.New("duplicate extension ID") // ErrInvalidExtensionID is returned when the extension ID is out of valid range. // Per RFC 8285, one-byte header extension IDs must be 1-14 (0 and 15 are reserved). ErrInvalidExtensionID = errors.New("extension ID must be between 1 and 14") // ErrEmptyExtensionURI is returned when the extension URI is empty. ErrEmptyExtensionURI = errors.New("extension URI cannot be empty") // ErrDuplicateExtensionURI is returned when duplicate extension URIs are found within a media type. ErrDuplicateExtensionURI = errors.New("duplicate extension URI") )
var ( // ErrInvalidPortRange is returned when the port range is invalid. ErrInvalidPortRange = errors.New("invalid port range: min must be less than max") // ErrPortRangeTooSmall is returned when the port range is too small. ErrPortRangeTooSmall = errors.New("port range too small: must have at least 100 ports") // ErrInvalidIP is returned when an IP address is invalid. ErrInvalidIP = errors.New("invalid IP address") // ErrNoPublicIP is returned when ICE Lite requires a public IP but none is configured. ErrNoPublicIP = errors.New("ICE Lite mode requires at least one public IP address") )
var ( // ErrICERestartInProgress is returned when an ICE restart is already in progress. ErrICERestartInProgress = errors.New("ICE restart already in progress") // ErrICERestartTimeout is returned when ICE restart times out. ErrICERestartTimeout = errors.New("ICE restart timeout") // ErrICERestartFailed is returned when ICE restart fails. ErrICERestartFailed = errors.New("ICE restart failed") // ErrNoOfferHandler is returned when no offer handler is set. ErrNoOfferHandler = errors.New("no offer handler set for ICE restart") )
var ( // ErrPeerClosed is returned when the peer is closed. ErrPeerClosed = errors.New("peer is closed") // ErrNoPeerConnection is returned when there is no peer connection. ErrNoPeerConnection = errors.New("no peer connection") // ErrInvalidSDP is returned when the SDP is invalid. ErrInvalidSDP = errors.New("invalid SDP") // ErrNilMediaEngine is returned when the media engine is nil. ErrNilMediaEngine = errors.New("media engine is nil") )
var ( // FeedbackNACK represents "a=rtcp-fb:* nack" for packet retransmission. FeedbackNACK = RTCPFeedback{Type: RTCPFeedbackTypeNACK, Parameter: RTCPFeedbackParamNone} // FeedbackNACKPLI represents "a=rtcp-fb:* nack pli" for Picture Loss Indication. FeedbackNACKPLI = RTCPFeedback{Type: RTCPFeedbackTypeNACK, Parameter: RTCPFeedbackParamPLI} // FeedbackCCMFIR represents "a=rtcp-fb:* ccm fir" for Full Intra Request. FeedbackCCMFIR = RTCPFeedback{Type: RTCPFeedbackTypeCCM, Parameter: RTCPFeedbackParamFIR} // FeedbackGoogREMB represents "a=rtcp-fb:* goog-remb" for bandwidth estimation. FeedbackGoogREMB = RTCPFeedback{Type: RTCPFeedbackTypeGoogREMB, Parameter: RTCPFeedbackParamNone} // FeedbackTransportCC represents "a=rtcp-fb:* transport-cc" for congestion control. FeedbackTransportCC = RTCPFeedback{Type: RTCPFeedbackTypeTransportCC, Parameter: RTCPFeedbackParamNone} )
Pre-defined RTCP feedback configurations matching design spec (section 3.6.3)
var ( // ErrInvalidSDPFormat is returned when the SDP format is invalid. ErrInvalidSDPFormat = errors.New("invalid SDP format") // ErrUnsupportedSDPSemantics is returned when Plan B semantics are detected. ErrUnsupportedSDPSemantics = errors.New("Plan B semantics not supported, use Unified Plan") // ErrMissingBundle is returned when BUNDLE is not present. ErrMissingBundle = errors.New("BUNDLE is required") // ErrMissingRTCPMux is returned when rtcp-mux is not present. ErrMissingRTCPMux = errors.New("rtcp-mux is required") )
var ( // ErrEmptySecret is returned when the TURN secret is empty. ErrEmptySecret = errors.New("TURN secret cannot be empty") // ErrInvalidTTL is returned when the TTL is invalid. ErrInvalidTTL = errors.New("TURN credential TTL must be positive") // ErrEmptyUsername is returned when the username is empty. ErrEmptyUsername = errors.New("username cannot be empty") // ErrEmptyTURNURLs is returned when no TURN URLs are provided. ErrEmptyTURNURLs = errors.New("TURN URLs cannot be empty") )
Functions ¶
func ApplyToSettingEngine ¶
func ApplyToSettingEngine(se *webrtc.SettingEngine, config ICEConfig) error
ApplyToSettingEngine applies the ICE configuration to a pion SettingEngine. This configures the low-level ICE behavior.
func BuildTURNURLs ¶
func BuildTURNURLs(host string, port int, protocols ...TURNProtocol) []string
BuildTURNURLs constructs TURN URLs with the specified protocols. Example: BuildTURNURLs("turn.example.com", 3478, TURNProtocolUDP, TURNProtocolTCP) Returns: ["turn:turn.example.com:3478?transport=udp", "turn:turn.example.com:3478?transport=tcp"]
func CanAttemptICERestart ¶
func CanAttemptICERestart(state webrtc.ICEConnectionState) bool
CanAttemptICERestart checks if an ICE restart can be attempted based on the current connection state.
func CreateIPFilter ¶
CreateIPFilter creates an IP filter from allowed CIDRs. If allowedCIDRs is empty, all IPs are allowed.
func CreateInterfaceFilter ¶
CreateInterfaceFilter creates an interface filter from a list of allowed interfaces. If allowedInterfaces is empty, all interfaces are allowed.
func DefaultCandidatePriorities ¶
func DefaultCandidatePriorities() map[CandidateType]uint32
DefaultCandidatePriorities returns the default candidate type preferences. Per requirements.md (section 2.7.3): host > srflx > relay
func DetectNetworkChange ¶
DetectNetworkChange is a placeholder for network change detection. In a real implementation, this would monitor network interfaces. Returns a channel that signals when a network change is detected.
func HasFeedback ¶
func HasFeedback(feedback []RTCPFeedback, target RTCPFeedback) bool
HasFeedback checks if the given feedback is present in the slice. This compares both Type and Parameter for exact match.
func ICERestartWithBackoff ¶
func ICERestartWithBackoff( ctx context.Context, pc *webrtc.PeerConnection, maxAttempts int, initialBackoff time.Duration, ) (*webrtc.SessionDescription, error)
ICERestartWithBackoff performs an ICE restart with exponential backoff. This is a convenience function for simple use cases.
func IPPriorityFilter ¶
IPPriorityFilter creates an IP filter that prioritizes IPv4. This can be used with ICEConfig.IPFilter.
func IPv4Priority ¶
func IPv4Priority() uint32
IPv4Priority returns a higher local preference for IPv4 addresses. Per requirements.md (section 2.7.6): IPv4 is prioritized over IPv6.
func IPv6Priority ¶
func IPv6Priority() uint32
IPv6Priority returns a lower local preference for IPv6 addresses. Per requirements.md (section 2.7.6): IPv4 is prioritized over IPv6.
func IsICELiteCompatible ¶
IsICELiteCompatible checks if a remote SDP indicates ICE Lite support. This is useful for debugging connectivity issues.
func IsSVCCodec ¶
func IsSVCCodec(name VideoCodecName) bool
IsSVCCodec returns true if the given codec name supports SVC.
func NeedsICERestart ¶
func NeedsICERestart(state webrtc.ICEConnectionState) bool
NeedsICERestart checks if the given ICE connection state indicates that an ICE restart might be needed.
func NewMediaEngineWithConfig ¶
func NewMediaEngineWithConfig(config CodecConfig) (*webrtc.MediaEngine, error)
NewMediaEngineWithConfig creates a new MediaEngine with the given codec configuration.
func NewMediaEngineWithDefaults ¶
func NewMediaEngineWithDefaults() (*webrtc.MediaEngine, error)
NewMediaEngineWithDefaults creates a new MediaEngine with default codec configuration.
func RegisterCodecs ¶
func RegisterCodecs(m *webrtc.MediaEngine, config CodecConfig) error
RegisterCodecs registers all configured codecs to the MediaEngine. This sets up the video and audio codecs with their RTCP feedback mechanisms.
Important: This function registers codecs with explicit payload types to avoid conflicts. Audio payload types start at 111, video at 96.
The function validates the configuration before registration and returns an error if any codec is invalid or misconfigured.
Codecs are registered in priority order (lower priority value = higher precedence). The input config is not mutated; a sorted copy is used internally.
func RegisterHeaderExtensions ¶
func RegisterHeaderExtensions(m *webrtc.MediaEngine, config HeaderExtensionConfig) error
RegisterHeaderExtensions registers all header extensions from the config to the MediaEngine. This must be called before creating PeerConnections.
The function registers extensions for both video and audio codecs. Extension IDs in the config are used for validation purposes only.
Note: pion/webrtc negotiates actual extension IDs during SDP exchange. The IDs specified in HeaderExtension.ID are not directly used by pion; instead, they serve as preferred hints and for configuration validation. The actual negotiated IDs can be retrieved after SDP exchange using MediaEngine.GetHeaderExtensionID().
Note: pion/webrtc requires specifying allowed directions explicitly. For SendRecv, both Sendonly and Recvonly must be provided.
func RequiredAudioExtensions ¶
func RequiredAudioExtensions() []string
RequiredAudioExtensions returns the list of required audio extension URIs per spec.
func RequiredVideoExtensions ¶
func RequiredVideoExtensions() []string
RequiredVideoExtensions returns the list of required video extension URIs per spec.
func ToWebRTCFeedbackSlice ¶
func ToWebRTCFeedbackSlice(feedback []RTCPFeedback) []webrtc.RTCPFeedback
ToWebRTCFeedbackSlice converts a slice of RTCPFeedback to webrtc.RTCPFeedback slice.
func ValidateCodecConfig ¶
func ValidateCodecConfig(config CodecConfig) error
ValidateCodecConfig validates the codec configuration. Returns an error if the configuration is invalid.
func ValidateHeaderExtensionConfig ¶
func ValidateHeaderExtensionConfig(config HeaderExtensionConfig) error
ValidateHeaderExtensionConfig validates the header extension configuration. Returns an error if the configuration is invalid.
Validation rules: - Extension IDs must be 1-14 (per RFC 8285, 0 and 15 are reserved for one-byte headers) - Extension IDs must be unique within each media type - Extension URIs must not be empty - Extension URIs must be unique within each media type
func ValidateICEConfig ¶
ValidateICEConfig validates the ICE configuration. Returns an error if the configuration is invalid.
Types ¶
type AudioCodecConfig ¶
type AudioCodecConfig struct {
// Name is the codec name.
Name AudioCodecName
// Priority is the codec priority (lower is higher priority).
Priority int
// MimeType is the MIME type of the codec.
MimeType string
// ClockRate is the clock rate in Hz.
ClockRate uint32
// Channels is the number of audio channels.
Channels uint16
// RTCPFeedback is the list of RTCP feedback mechanisms.
RTCPFeedback []RTCPFeedback
// FMTPParams contains codec-specific parameters.
FMTPParams OpusFMTPParams
}
AudioCodecConfig holds configuration for an audio codec.
func (AudioCodecConfig) Copy ¶
func (ac AudioCodecConfig) Copy() AudioCodecConfig
Copy creates a copy of the AudioCodecConfig.
type AudioCodecName ¶
type AudioCodecName string
AudioCodecName represents supported audio codec names.
const ( // CodecOpus is the Opus audio codec. CodecOpus AudioCodecName = "opus" // CodecG711PCMU is the G.711 µ-law audio codec. CodecG711PCMU AudioCodecName = "PCMU" // CodecG711PCMA is the G.711 A-law audio codec. CodecG711PCMA AudioCodecName = "PCMA" )
type CandidatePriority ¶
type CandidatePriority struct {
// TypePreference is the preference based on candidate type (0-126).
TypePreference uint32
// LocalPreference is the preference based on local factors (0-65535).
LocalPreference uint32
// ComponentID is the component ID (1 for RTP, 2 for RTCP).
ComponentID uint32
}
CandidatePriority represents ICE candidate priority calculation. Per requirements.md (section 2.7.3): host > srflx > relay
func (CandidatePriority) Calculate ¶
func (p CandidatePriority) Calculate() uint32
Calculate calculates the ICE candidate priority per RFC 5245. Priority = (2^24 * type_preference) + (2^8 * local_preference) + (256 - component_id)
type CandidateType ¶
type CandidateType int
CandidateType represents an ICE candidate type.
const ( // CandidateTypeHost represents a host candidate. CandidateTypeHost CandidateType = iota // CandidateTypeSrflx represents a server reflexive candidate. CandidateTypeSrflx // CandidateTypePrflx represents a peer reflexive candidate. CandidateTypePrflx // CandidateTypeRelay represents a relay candidate (TURN). CandidateTypeRelay )
func (CandidateType) String ¶
func (c CandidateType) String() string
String returns the string representation of CandidateType.
type CodecConfig ¶
type CodecConfig struct {
// VideoCodecs is the list of video codecs in priority order.
VideoCodecs []VideoCodecConfig
// AudioCodecs is the list of audio codecs in priority order.
AudioCodecs []AudioCodecConfig
}
CodecConfig holds the complete codec configuration.
func DefaultCodecConfig ¶
func DefaultCodecConfig() CodecConfig
DefaultCodecConfig returns the default codec configuration per spec. Per requirements.md (section 2.6) and design.md (section 3.6.4): Video codecs priority: VP8 > H.264 > VP9 Audio codecs: Opus (required), G.711 (optional for legacy)
func DefaultCodecConfigWithG711 ¶
func DefaultCodecConfigWithG711() CodecConfig
DefaultCodecConfigWithG711 returns the default codec configuration with G.711 support. G.711 is optional and provided for legacy compatibility.
func DefaultCodecConfigWithSVC ¶
func DefaultCodecConfigWithSVC(scalabilityMode string) CodecConfig
DefaultCodecConfigWithSVC returns the default codec configuration with SVC enabled for VP9/AV1. Per design.md section 4.1: SVC is optional for VP9/AV1 codecs.
func (*CodecConfig) AddAudioCodec ¶
func (c *CodecConfig) AddAudioCodec(ac AudioCodecConfig)
AddAudioCodec adds an audio codec to the configuration. The codec is inserted according to its priority.
func (*CodecConfig) AddVideoCodec ¶
func (c *CodecConfig) AddVideoCodec(vc VideoCodecConfig)
AddVideoCodec adds a video codec to the configuration. The codec is inserted according to its priority.
func (CodecConfig) Copy ¶
func (c CodecConfig) Copy() CodecConfig
Copy creates a deep copy of the CodecConfig. This is useful when you need to modify the config without affecting the original.
func (CodecConfig) GetAudioCodecByName ¶
func (c CodecConfig) GetAudioCodecByName(name AudioCodecName) *AudioCodecConfig
GetAudioCodecByName returns the audio codec configuration by name.
func (CodecConfig) GetAudioCodecNames ¶
func (c CodecConfig) GetAudioCodecNames() []AudioCodecName
GetAudioCodecNames returns the list of audio codec names from the configuration.
func (CodecConfig) GetVideoCodecByName ¶
func (c CodecConfig) GetVideoCodecByName(name VideoCodecName) *VideoCodecConfig
GetVideoCodecByName returns the video codec configuration by name.
func (CodecConfig) GetVideoCodecNames ¶
func (c CodecConfig) GetVideoCodecNames() []VideoCodecName
GetVideoCodecNames returns the list of video codec names from the configuration.
func (CodecConfig) HasAudioCodec ¶
func (c CodecConfig) HasAudioCodec(name AudioCodecName) bool
HasAudioCodec checks if the configuration contains a specific audio codec.
func (CodecConfig) HasVideoCodec ¶
func (c CodecConfig) HasVideoCodec(name VideoCodecName) bool
HasVideoCodec checks if the configuration contains a specific video codec.
func (*CodecConfig) RemoveAudioCodec ¶
func (c *CodecConfig) RemoveAudioCodec(name AudioCodecName)
RemoveAudioCodec removes an audio codec from the configuration by name.
func (*CodecConfig) RemoveVideoCodec ¶
func (c *CodecConfig) RemoveVideoCodec(name VideoCodecName)
RemoveVideoCodec removes a video codec from the configuration by name.
func (*CodecConfig) SetAudioCodecPriority ¶
func (c *CodecConfig) SetAudioCodecPriority(name AudioCodecName, priority int)
SetAudioCodecPriority updates the priority of an audio codec. Lower priority values mean higher priority.
func (*CodecConfig) SetVideoCodecPriority ¶
func (c *CodecConfig) SetVideoCodecPriority(name VideoCodecName, priority int)
SetVideoCodecPriority updates the priority of a video codec. Lower priority values mean higher priority.
func (*CodecConfig) SortByPriority ¶
func (c *CodecConfig) SortByPriority()
SortByPriority sorts both video and audio codecs by their priority. This ensures registration order matches priority values.
type CodecInfo ¶
type CodecInfo struct {
PayloadType string
MediaType string
Name string
ClockRate int
FMTPParams string
}
CodecInfo contains information about a codec in the SDP.
type ConnectionStateHandler ¶
type ConnectionStateHandler func(state webrtc.PeerConnectionState)
ConnectionStateHandler is called when the connection state changes.
type DataChannelHandler ¶
type DataChannelHandler func(dc *webrtc.DataChannel)
DataChannelHandler is called when a new data channel is opened.
type EventHandler ¶
type EventHandler interface {
// OnICEConnectionStateChange is called when the ICE connection state changes.
OnICEConnectionStateChange(participantID string, state pion.ICEConnectionState)
// OnPeerConnectionStateChange is called when the peer connection state changes.
OnPeerConnectionStateChange(participantID string, state pion.PeerConnectionState)
// OnICECandidate is called when a new ICE candidate is available (for trickle ICE).
OnICECandidate(participantID string, candidate pion.ICECandidateInit)
// OnTrack is called when a new track is received from the peer.
OnTrack(participantID string, track *pion.TrackRemote, receiver *pion.RTPReceiver)
// OnNegotiationNeeded is called when renegotiation is needed.
OnNegotiationNeeded(participantID string)
}
EventHandler handles WebRTC events and state changes. This interface is implemented by the signaling layer to send notifications to clients.
type ExtensionDirection ¶
type ExtensionDirection int
ExtensionDirection specifies when a header extension is used.
const ( // ExtensionDirectionSendRecv indicates the extension is used in both directions. ExtensionDirectionSendRecv ExtensionDirection = iota // ExtensionDirectionSendOnly indicates the extension is used only for sending. ExtensionDirectionSendOnly // ExtensionDirectionRecvOnly indicates the extension is used only for receiving. ExtensionDirectionRecvOnly )
type ExtensionID ¶
type ExtensionID int
ExtensionID represents a header extension ID (1-15 for one-byte form).
const ( // ExtensionIDMID is the default ID for MID extension. ExtensionIDMID ExtensionID = 1 // ExtensionIDRID is the default ID for RID extension. ExtensionIDRID ExtensionID = 2 // ExtensionIDRepairedRID is the default ID for repaired RID extension. ExtensionIDRepairedRID ExtensionID = 3 // ExtensionIDAbsSendTime is the default ID for abs-send-time extension. ExtensionIDAbsSendTime ExtensionID = 4 // ExtensionIDTransportCC is the default ID for transport-cc extension. ExtensionIDTransportCC ExtensionID = 5 // ExtensionIDAudioLevel is the default ID for audio level extension. ExtensionIDAudioLevel ExtensionID = 6 // ExtensionIDVideoOrientation is the default ID for video orientation. ExtensionIDVideoOrientation ExtensionID = 7 )
Standard extension IDs. Note: These IDs can be negotiated during SDP exchange, but we define preferred defaults that align with common implementations.
type H264Profile ¶
type H264Profile string
H264Profile represents H.264 profile levels.
const ( // H264ProfileHighLevel50 is High Profile Level 5.0 (640032). // Suitable for high quality (1080p30), desktop use. H264ProfileHighLevel50 H264Profile = "640032" // H264ProfileConstrainedBaselineLevel31 is Constrained Baseline Level 3.1 (42e01f). // Safari/mobile compatible, suitable for low-spec devices. H264ProfileConstrainedBaselineLevel31 H264Profile = "42e01f" )
type H264ProfileConfig ¶
type H264ProfileConfig struct {
// ProfileLevelID is the profile-level-id (e.g., "640032", "42e01f").
ProfileLevelID H264Profile
// PacketizationMode is the packetization mode (1 for non-interleaved).
PacketizationMode int
// LevelAsymmetryAllowed indicates if level asymmetry is allowed.
LevelAsymmetryAllowed int
}
H264ProfileConfig holds H.264 specific profile configuration.
func DefaultH264BaselineProfile ¶
func DefaultH264BaselineProfile() H264ProfileConfig
DefaultH264BaselineProfile returns the default H.264 Constrained Baseline Profile. Per design spec (section 3.6.4): - profile-level-id=42e01f (Constrained Baseline Level 3.1) - packetization-mode=1 (non-interleaved) - level-asymmetry-allowed=1
func DefaultH264HighProfile ¶
func DefaultH264HighProfile() H264ProfileConfig
DefaultH264HighProfile returns the default H.264 High Profile configuration. Per design spec (section 3.6.4): - profile-level-id=640032 (High Profile Level 5.0) - packetization-mode=1 (non-interleaved) - level-asymmetry-allowed=1
func (H264ProfileConfig) BuildFMTPLine ¶
func (p H264ProfileConfig) BuildFMTPLine() string
BuildFMTPLine builds the fmtp line for H.264 profile. Returns string like: "profile-level-id=640032;packetization-mode=1;level-asymmetry-allowed=1"
type HeaderExtension ¶
type HeaderExtension struct {
// ID is the preferred extension ID (1-15 for one-byte form).
// Note: This ID is used for configuration validation only.
// pion/webrtc negotiates actual IDs during SDP exchange.
// The actual negotiated ID may differ from this preferred value.
ID ExtensionID
// URI is the extension URI that identifies the extension type.
// This is the primary identifier used by pion/webrtc for registration.
URI string
// Direction specifies when this extension is used.
Direction ExtensionDirection
}
HeaderExtension represents an RTP header extension configuration.
type HeaderExtensionConfig ¶
type HeaderExtensionConfig struct {
// VideoExtensions are the extensions to register for video.
VideoExtensions []HeaderExtension
// AudioExtensions are the extensions to register for audio.
AudioExtensions []HeaderExtension
}
HeaderExtensionConfig contains the configuration for RTP header extensions.
func DefaultHeaderExtensionConfig ¶
func DefaultHeaderExtensionConfig() HeaderExtensionConfig
DefaultHeaderExtensionConfig returns the default header extension configuration. Per requirements.md (section 2.4.2) and design.md (section 3.6.2): Required extensions: mid, rid, transport-wide-cc, abs-send-time
func MinimalHeaderExtensionConfig ¶
func MinimalHeaderExtensionConfig() HeaderExtensionConfig
MinimalHeaderExtensionConfig returns a minimal header extension configuration. This includes only the strictly required extensions per spec.
func (*HeaderExtensionConfig) AddAudioExtension ¶
func (c *HeaderExtensionConfig) AddAudioExtension(ext HeaderExtension)
AddAudioExtension adds an audio extension to the configuration.
func (*HeaderExtensionConfig) AddVideoExtension ¶
func (c *HeaderExtensionConfig) AddVideoExtension(ext HeaderExtension)
AddVideoExtension adds a video extension to the configuration.
func (HeaderExtensionConfig) Copy ¶
func (c HeaderExtensionConfig) Copy() HeaderExtensionConfig
Copy creates a deep copy of the HeaderExtensionConfig.
func (HeaderExtensionConfig) GetAudioExtension ¶
func (c HeaderExtensionConfig) GetAudioExtension(uri string) *HeaderExtension
GetAudioExtension returns the audio extension with the given URI, or nil if not found.
func (HeaderExtensionConfig) GetAudioExtensionURIs ¶
func (c HeaderExtensionConfig) GetAudioExtensionURIs() []string
GetAudioExtensionURIs returns all audio extension URIs.
func (HeaderExtensionConfig) GetVideoExtension ¶
func (c HeaderExtensionConfig) GetVideoExtension(uri string) *HeaderExtension
GetVideoExtension returns the video extension with the given URI, or nil if not found.
func (HeaderExtensionConfig) GetVideoExtensionURIs ¶
func (c HeaderExtensionConfig) GetVideoExtensionURIs() []string
GetVideoExtensionURIs returns all video extension URIs.
func (HeaderExtensionConfig) HasAudioExtension ¶
func (c HeaderExtensionConfig) HasAudioExtension(uri string) bool
HasAudioExtension checks if an audio extension with the given URI exists.
func (HeaderExtensionConfig) HasRequiredAudioExtensions ¶
func (c HeaderExtensionConfig) HasRequiredAudioExtensions() bool
HasRequiredAudioExtensions checks if all required audio extensions are present.
func (HeaderExtensionConfig) HasRequiredVideoExtensions ¶
func (c HeaderExtensionConfig) HasRequiredVideoExtensions() bool
HasRequiredVideoExtensions checks if all required video extensions are present.
func (HeaderExtensionConfig) HasVideoExtension ¶
func (c HeaderExtensionConfig) HasVideoExtension(uri string) bool
HasVideoExtension checks if a video extension with the given URI exists.
func (*HeaderExtensionConfig) RemoveAudioExtension ¶
func (c *HeaderExtensionConfig) RemoveAudioExtension(uri string)
RemoveAudioExtension removes an audio extension by URI.
func (*HeaderExtensionConfig) RemoveVideoExtension ¶
func (c *HeaderExtensionConfig) RemoveVideoExtension(uri string)
RemoveVideoExtension removes a video extension by URI.
type ICECandidateErrorHandler ¶
type ICECandidateErrorHandler func(candidate *webrtc.ICECandidateInit, err error)
ICECandidateErrorHandler is called when adding an ICE candidate fails.
type ICECandidateHandler ¶
type ICECandidateHandler func(candidate *webrtc.ICECandidate)
ICECandidateHandler is called when a new ICE candidate is available.
type ICEConfig ¶
type ICEConfig struct {
// Lite enables ICE Lite mode (controlled role, simplified candidate gathering).
// Per requirements.md (section 2.7.4), SFU operates as ICE Lite server.
// Default: true
Lite bool
// NAT1To1IPs are the public IP addresses for NAT 1:1 mapping.
// Per requirements.md (section 2.7.5), required for ICE Lite mode.
// These IPs are announced as host candidates to clients.
NAT1To1IPs []string
// InterfaceFilter is a function to filter network interfaces.
// If nil, all interfaces are used.
InterfaceFilter func(interfaceName string) bool
// IPFilter is a function to filter IP addresses.
// If nil, all IPs are used.
IPFilter func(ip net.IP) bool
// UDPPortRange specifies the UDP port range for ICE.
// Per requirements.md (section 2.7.6), default is 10000-20000.
UDPPortRange PortRange
// NetworkTypes specifies which network types to use.
// Per requirements.md (section 2.7.6), IPv4 is prioritized over IPv6.
// Default: UDP4, UDP6 (IPv4 first for priority)
NetworkTypes []NetworkType
// DisableIPv6 disables IPv6 support entirely.
// Default: false (dual-stack enabled per requirements.md section 2.7.6)
DisableIPv6 bool
// PreferIPv4 prioritizes IPv4 over IPv6 in candidate ordering.
// Per requirements.md (section 2.7.6), IPv4 is prioritized.
// Default: true
// Note: IPv4 priority is achieved by ordering NetworkTypes (UDP4 before UDP6)
// and through local preference values (see IPv4Priority/IPv6Priority).
// pion uses interface order for candidate priority.
PreferIPv4 bool
// ConnectionTimeout is the timeout for establishing ICE connections.
// Per requirements.md (section 2.7.3), default is 30 seconds.
// Note: This is used at a higher level (e.g., PeerConnection lifecycle)
// as pion's SettingEngine does not directly support connection timeout.
ConnectionTimeout time.Duration
// DisconnectedTimeout is the time to wait before declaring disconnected state.
DisconnectedTimeout time.Duration
// FailedTimeout is the time to wait before declaring failed state.
FailedTimeout time.Duration
// KeepaliveInterval is the interval for sending keepalive STUN binding requests.
KeepaliveInterval time.Duration
// CandidateTypes specifies which candidate types to gather.
// Per requirements.md (section 2.7.4), ICE Lite only generates host candidates.
// Default: [host] (srflx and relay not used in ICE Lite)
// Note: In ICE Lite mode, pion automatically restricts to host candidates.
// This field is provided for configuration reference and documentation.
CandidateTypes []CandidateType
// UDPMux is an optional UDP mux for sharing a single port across connections.
// Useful for reducing the number of open ports in production.
UDPMux ice.UDPMux
}
ICEConfig contains ICE-related configuration for the SFU. Per requirements.md (section 2.7), the SFU operates in ICE Lite mode.
func DefaultICEConfig ¶
func DefaultICEConfig() ICEConfig
DefaultICEConfig returns the default ICE configuration for the SFU. Per requirements.md (section 2.7): - ICE Lite mode enabled - UDP port range 10000-20000 - IPv4/IPv6 dual-stack with IPv4 priority - 30 second connection timeout - Host candidates only (ICE Lite)
func ICELiteConfig ¶
ICELiteConfig returns an ICE configuration optimized for ICE Lite mode. This is the recommended configuration for SFU servers.
func (ICEConfig) WithIPv6Disabled ¶
WithIPv6Disabled returns a copy of the config with IPv6 disabled.
func (ICEConfig) WithNAT1To1IPs ¶
WithNAT1To1IPs returns a copy of the config with NAT 1:1 IPs set.
func (ICEConfig) WithPortRange ¶
WithPortRange returns a copy of the config with the port range set.
type ICEConnectionStateHandler ¶
type ICEConnectionStateHandler func(state webrtc.ICEConnectionState)
ICEConnectionStateHandler is called when the ICE connection state changes.
type ICERestartConfig ¶
type ICERestartConfig struct {
// Timeout for ICE restart completion.
// Default: 30 seconds
Timeout time.Duration
// DisconnectedThreshold is the time to wait before triggering restart on disconnect.
// Default: 5 seconds
DisconnectedThreshold time.Duration
// MaxAttempts is the maximum number of restart attempts before giving up.
// Default: 3
MaxAttempts int
// Backoff is the duration to wait between restart attempts.
// Default: 2 seconds
Backoff time.Duration
// AutoRestartOnDisconnect enables automatic ICE restart when connection disconnects.
// Default: true
AutoRestartOnDisconnect bool
// AutoRestartOnFailed enables automatic ICE restart when connection fails.
// Default: true
AutoRestartOnFailed bool
}
ICERestartConfig contains configuration for ICE restart behavior.
func DefaultICERestartConfig ¶
func DefaultICERestartConfig() ICERestartConfig
DefaultICERestartConfig returns the default ICE restart configuration.
type ICERestartEvent ¶
type ICERestartEvent struct {
// Timestamp of the event.
Timestamp time.Time
// Reason for the restart.
Reason string
// Success indicates if restart was successful.
Success bool
// Attempts is the number of attempts made.
Attempts int
// Duration of the restart operation.
Duration time.Duration
// Error message if failed.
ErrorMessage string
}
ICERestartEvent represents an ICE restart event for logging/metrics.
type ICERestartHandler ¶
type ICERestartHandler func(ctx context.Context, offer webrtc.SessionDescription) error
ICERestartHandler handles the SDP offer generated during ICE restart. The handler should send the offer to the remote peer and set the answer.
type ICERestartManager ¶
type ICERestartManager struct {
// contains filtered or unexported fields
}
ICERestartManager manages ICE restart operations for a peer connection.
func NewICERestartManager ¶
func NewICERestartManager(config ICERestartConfig) *ICERestartManager
NewICERestartManager creates a new ICE restart manager.
func (*ICERestartManager) Close ¶
func (m *ICERestartManager) Close()
Close cleans up the restart manager.
func (*ICERestartManager) GetLastRestartTime ¶
func (m *ICERestartManager) GetLastRestartTime() time.Time
GetLastRestartTime returns the time of the last restart attempt.
func (*ICERestartManager) GetTotalRestartAttempts ¶
func (m *ICERestartManager) GetTotalRestartAttempts() int32
GetTotalRestartAttempts returns the total number of restart attempts made.
func (*ICERestartManager) HandleICEConnectionStateChange ¶
func (m *ICERestartManager) HandleICEConnectionStateChange(state webrtc.ICEConnectionState)
HandleICEConnectionStateChange should be called when ICE connection state changes. This enables automatic restart based on configuration.
func (*ICERestartManager) IsRestartInProgress ¶
func (m *ICERestartManager) IsRestartInProgress() bool
IsRestartInProgress returns true if an ICE restart is currently in progress.
func (*ICERestartManager) OnRestartCompleted ¶
func (m *ICERestartManager) OnRestartCompleted(fn func(result ICERestartResult))
OnRestartCompleted sets a callback for when restart completes.
func (*ICERestartManager) OnRestartStarted ¶
func (m *ICERestartManager) OnRestartStarted(fn func(reason string))
OnRestartStarted sets a callback for when restart begins.
func (*ICERestartManager) Reset ¶
func (m *ICERestartManager) Reset()
Reset resets the restart manager state.
func (*ICERestartManager) SetOfferHandler ¶
func (m *ICERestartManager) SetOfferHandler(handler ICERestartHandler)
SetOfferHandler sets the handler for sending restart offers.
func (*ICERestartManager) SetPeerConnection ¶
func (m *ICERestartManager) SetPeerConnection(pc *webrtc.PeerConnection)
SetPeerConnection sets the peer connection to manage.
func (*ICERestartManager) TriggerRestart ¶
func (m *ICERestartManager) TriggerRestart(ctx context.Context, reason string) ICERestartResult
TriggerRestart initiates an ICE restart with the given reason.
type ICERestartResult ¶
type ICERestartResult struct {
// Success indicates if the restart offer was created and handler completed successfully.
// Note: This does not guarantee ICE connectivity recovery - monitor ICE state for that.
Success bool
// Reason is the trigger reason for the restart.
Reason string
// Attempts is the number of attempts made.
Attempts int
// Duration is the total duration of the restart operation.
Duration time.Duration
// Error is the error if restart failed.
Error error
// Offer is the new SDP offer generated for the restart.
Offer *webrtc.SessionDescription
}
ICERestartResult contains the result of an ICE restart operation. Note: Success indicates the restart offer was created and the handler completed successfully. It does NOT guarantee ICE connectivity has been restored. The caller should monitor ICE connection state changes to confirm recovery.
func (ICERestartResult) ToEvent ¶
func (r ICERestartResult) ToEvent() ICERestartEvent
ToEvent converts ICERestartResult to ICERestartEvent.
type ICEServerConfig ¶
type ICEServerConfig struct {
// URLs are the server URLs (e.g., "stun:stun.example.com:3478").
URLs []string
// Username is the username for TURN authentication.
Username string
// Credential is the credential for TURN authentication.
Credential string
// CredentialType is the type of credential (password or oauth).
CredentialType webrtc.ICECredentialType
}
ICEServerConfig represents an ICE server configuration (STUN/TURN).
func MergeTURNCredentials ¶
func MergeTURNCredentials(stunServers []ICEServerConfig, turnCreds *TURNCredentials) []ICEServerConfig
MergeTURNCredentials combines TURN credentials with existing ICE servers. This is useful when adding TURN credentials to a list of STUN servers.
func (ICEServerConfig) ToWebRTCICEServer ¶
func (c ICEServerConfig) ToWebRTCICEServer() webrtc.ICEServer
ToWebRTCICEServer converts ICEServerConfig to webrtc.ICEServer.
type ICEServersConfig ¶
type ICEServersConfig struct {
// Servers is the list of ICE servers in priority order.
Servers []ICEServerConfig
}
ICEServersConfig contains multiple ICE server configurations. Per requirements.md (section 2.7.1), supports fallback across multiple servers.
func DefaultSTUNServers ¶
func DefaultSTUNServers() ICEServersConfig
DefaultSTUNServers returns a list of default public STUN servers. These can be used for testing or as fallback servers.
func (ICEServersConfig) ToWebRTCICEServers ¶
func (c ICEServersConfig) ToWebRTCICEServers() []webrtc.ICEServer
ToWebRTCICEServers converts to a slice of webrtc.ICEServer.
type NegotiationNeededHandler ¶
type NegotiationNeededHandler func()
NegotiationNeededHandler is called when negotiation is needed.
type NetworkType ¶
type NetworkType int
NetworkType represents the type of network to use.
const ( // NetworkTypeUDP4 uses UDP over IPv4. NetworkTypeUDP4 NetworkType = iota // NetworkTypeUDP6 uses UDP over IPv6. NetworkTypeUDP6 // NetworkTypeTCP4 uses TCP over IPv4. NetworkTypeTCP4 // NetworkTypeTCP6 uses TCP over IPv6. NetworkTypeTCP6 )
func (NetworkType) String ¶
func (n NetworkType) String() string
String returns the string representation of NetworkType.
type OpusFMTPParams ¶
type OpusFMTPParams struct {
// MinPTime is the minimum packetization time in ms.
MinPTime int
// UseInbandFEC enables in-band forward error correction.
UseInbandFEC int
// Stereo enables stereo support.
Stereo int
}
OpusFMTPParams holds Opus codec FMTP parameters.
func DefaultOpusFMTP ¶
func DefaultOpusFMTP() OpusFMTPParams
DefaultOpusFMTP returns the default Opus FMTP parameters per spec. Per design spec (section 3.6.4): - minptime=10: minimum packetization time - useinbandfec=1: enable in-band FEC - stereo=1: enable stereo
func (OpusFMTPParams) BuildFMTPLine ¶
func (p OpusFMTPParams) BuildFMTPLine() string
BuildFMTPLine builds the fmtp line for Opus codec. Returns string like: "minptime=10;useinbandfec=1;stereo=1"
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer wraps a pion/webrtc PeerConnection with additional functionality.
func NewPeer ¶
func NewPeer(id string, config PeerConfig, mediaEngine *webrtc.MediaEngine) (*Peer, error)
NewPeer creates a new Peer with the given configuration.
func (*Peer) AddICECandidate ¶
func (p *Peer) AddICECandidate(candidate webrtc.ICECandidateInit) error
AddICECandidate adds an ICE candidate.
func (*Peer) AddTransceiverFromKind ¶
func (p *Peer) AddTransceiverFromKind(kind webrtc.RTPCodecType, init ...webrtc.RTPTransceiverInit) (*webrtc.RTPTransceiver, error)
AddTransceiverFromKind adds a transceiver for the given kind.
func (*Peer) Close ¶
Close closes the peer connection. This method is idempotent and safe to call multiple times concurrently.
func (*Peer) CloseWithContext ¶
CloseWithContext closes the peer connection with a context.
func (*Peer) ConnectionState ¶
func (p *Peer) ConnectionState() webrtc.PeerConnectionState
ConnectionState returns the connection state.
func (*Peer) CreateAnswer ¶
func (p *Peer) CreateAnswer() (webrtc.SessionDescription, error)
CreateAnswer creates an SDP answer and waits for ICE gathering to complete.
func (*Peer) CreateOffer ¶
func (p *Peer) CreateOffer() (webrtc.SessionDescription, error)
CreateOffer creates an SDP offer and waits for ICE gathering to complete.
func (*Peer) GetReceivers ¶
func (p *Peer) GetReceivers() []*webrtc.RTPReceiver
GetReceivers returns all RTP receivers.
func (*Peer) GetSenders ¶
GetSenders returns all RTP senders.
func (*Peer) GetTransceivers ¶
func (p *Peer) GetTransceivers() []*webrtc.RTPTransceiver
GetTransceivers returns all transceivers.
func (*Peer) HandleAnswer ¶
HandleAnswer processes an SDP answer. This is a high-level method that wraps SetRemoteDescription for answers.
func (*Peer) HandleCandidate ¶
func (p *Peer) HandleCandidate(ctx context.Context, candidate string, sdpMid string, sdpMLineIndex *int) error
HandleCandidate processes an ICE candidate. This is a high-level method that constructs an ICECandidateInit and calls AddICECandidate.
func (*Peer) HandleOffer ¶
HandleOffer processes an SDP offer and returns an SDP answer. This is a high-level method that combines SetRemoteDescription and CreateAnswer.
func (*Peer) ICEConnectionState ¶
func (p *Peer) ICEConnectionState() webrtc.ICEConnectionState
ICEConnectionState returns the ICE connection state.
func (*Peer) LocalDescription ¶
func (p *Peer) LocalDescription() *webrtc.SessionDescription
LocalDescription returns the local description.
func (*Peer) OnConnectionStateChange ¶
func (p *Peer) OnConnectionStateChange(handler ConnectionStateHandler)
OnConnectionStateChange sets the handler for connection state changes.
func (*Peer) OnDataChannel ¶
func (p *Peer) OnDataChannel(handler DataChannelHandler)
OnDataChannel sets the handler for data channels.
func (*Peer) OnICECandidate ¶
func (p *Peer) OnICECandidate(handler ICECandidateHandler)
OnICECandidate sets the handler for ICE candidates.
func (*Peer) OnICECandidateError ¶
func (p *Peer) OnICECandidateError(handler ICECandidateErrorHandler)
OnICECandidateError sets the handler for ICE candidate errors. This is called when adding a pending ICE candidate fails during SetRemoteDescription.
func (*Peer) OnICEConnectionStateChange ¶
func (p *Peer) OnICEConnectionStateChange(handler ICEConnectionStateHandler)
OnICEConnectionStateChange sets the handler for ICE connection state changes.
func (*Peer) OnNegotiationNeeded ¶
func (p *Peer) OnNegotiationNeeded(handler NegotiationNeededHandler)
OnNegotiationNeeded sets the handler for negotiation needed events.
func (*Peer) OnTrack ¶
func (p *Peer) OnTrack(handler TrackHandler)
OnTrack sets the handler for new tracks.
func (*Peer) PeerConnection ¶
func (p *Peer) PeerConnection() *webrtc.PeerConnection
PeerConnection returns the underlying pion PeerConnection.
func (*Peer) RemoteDescription ¶
func (p *Peer) RemoteDescription() *webrtc.SessionDescription
RemoteDescription returns the remote description.
func (*Peer) RemoveTrack ¶
RemoveTrack removes a track from the peer connection.
func (*Peer) SetRemoteDescription ¶
func (p *Peer) SetRemoteDescription(sdp webrtc.SessionDescription) error
SetRemoteDescription sets the remote description.
func (*Peer) SignalingState ¶
func (p *Peer) SignalingState() webrtc.SignalingState
SignalingState returns the signaling state.
type PeerConfig ¶
type PeerConfig struct {
// ICEServers is the list of ICE servers to use.
ICEServers []webrtc.ICEServer
// ICELite enables ICE Lite mode.
ICELite bool
// UDPMux is the UDP mux to use for ICE.
UDPMux ice.UDPMux
// NAT1To1IPs are the IPs to use for NAT 1:1 mapping.
NAT1To1IPs []string
// ConnectionTimeout is the timeout for establishing a connection.
// Note: Currently stored for reference; actual timeout enforcement
// is implemented in higher-level connection management.
ConnectionTimeout time.Duration
}
PeerConfig contains configuration for creating a Peer.
func DefaultPeerConfig ¶
func DefaultPeerConfig() PeerConfig
DefaultPeerConfig returns a default PeerConfig.
type PeerState ¶
type PeerState int32
PeerState represents the state of a peer connection.
const ( // PeerStateNew indicates the peer connection is new. PeerStateNew PeerState = iota // PeerStateConnecting indicates the peer connection is connecting. PeerStateConnecting // PeerStateConnected indicates the peer connection is connected. PeerStateConnected // PeerStateDisconnected indicates the peer connection is disconnected. PeerStateDisconnected // PeerStateFailed indicates the peer connection has failed. PeerStateFailed // PeerStateClosed indicates the peer connection is closed. PeerStateClosed )
type RTCPFeedback ¶
type RTCPFeedback struct {
// Type is the RTCP feedback type (e.g., "nack", "ccm", "goog-remb").
Type RTCPFeedbackType
// Parameter is the optional parameter (e.g., "pli" for nack, "fir" for ccm).
Parameter RTCPFeedbackParam
}
RTCPFeedback represents an RTCP feedback mechanism configuration. This structure aligns with pion/webrtc's RTCPFeedback representation.
func AddFeedback ¶
func AddFeedback(feedback []RTCPFeedback, target RTCPFeedback) []RTCPFeedback
AddFeedback adds a feedback to the slice if it doesn't exist. This compares both Type and Parameter for deduplication.
func DefaultAudioRTCPFeedback ¶
func DefaultAudioRTCPFeedback() []RTCPFeedback
DefaultAudioRTCPFeedback returns the default RTCP feedback mechanisms for audio. Per design spec (section 3.6.3): - transport-cc: TWCC congestion control (for audio and video)
func DefaultVideoRTCPFeedback ¶
func DefaultVideoRTCPFeedback() []RTCPFeedback
DefaultVideoRTCPFeedback returns the default RTCP feedback mechanisms for video. Per design spec (section 3.6.3): - nack: Packet retransmission request - nack pli: Picture Loss Indication - ccm fir: Full Intra Request - goog-remb: REMB bandwidth estimation - transport-cc: TWCC congestion control
func EnsureRequiredAudioFeedback ¶
func EnsureRequiredAudioFeedback(feedback []RTCPFeedback) []RTCPFeedback
EnsureRequiredAudioFeedback ensures all required audio RTCP feedback mechanisms are present. Returns the updated feedback slice with any missing required mechanisms added.
func EnsureRequiredVideoFeedback ¶
func EnsureRequiredVideoFeedback(feedback []RTCPFeedback) []RTCPFeedback
EnsureRequiredVideoFeedback ensures all required video RTCP feedback mechanisms are present. Returns the updated feedback slice with any missing required mechanisms added.
func RTCPFeedbackFromWebRTC ¶
func RTCPFeedbackFromWebRTC(f webrtc.RTCPFeedback) RTCPFeedback
RTCPFeedbackFromWebRTC converts webrtc.RTCPFeedback to RTCPFeedback.
func RemoveFeedback ¶
func RemoveFeedback(feedback []RTCPFeedback, target RTCPFeedback) []RTCPFeedback
RemoveFeedback removes a feedback from the slice. This compares both Type and Parameter for exact match.
func RequiredAudioFeedback ¶
func RequiredAudioFeedback() []RTCPFeedback
RequiredAudioFeedback returns all required RTCP feedback for audio codecs.
func RequiredVideoFeedback ¶
func RequiredVideoFeedback() []RTCPFeedback
RequiredVideoFeedback returns all required RTCP feedback for video codecs.
func ValidateAudioFeedback ¶
func ValidateAudioFeedback(feedback []RTCPFeedback) []RTCPFeedback
ValidateAudioFeedback validates that all required audio RTCP feedback mechanisms are present. Returns missing feedback if any are not present.
func ValidateVideoFeedback ¶
func ValidateVideoFeedback(feedback []RTCPFeedback) []RTCPFeedback
ValidateVideoFeedback validates that all required video RTCP feedback mechanisms are present. Returns missing feedback if any are not present.
func (RTCPFeedback) Equals ¶
func (f RTCPFeedback) Equals(other RTCPFeedback) bool
Equals checks if two RTCPFeedback are equal (same Type and Parameter).
func (RTCPFeedback) SDPFeedbackString ¶
func (f RTCPFeedback) SDPFeedbackString() string
SDPFeedbackString returns the SDP representation of the feedback (e.g., "nack pli"). This is useful for logging and debugging.
func (RTCPFeedback) ToWebRTCFeedback ¶
func (f RTCPFeedback) ToWebRTCFeedback() webrtc.RTCPFeedback
ToWebRTCFeedback converts RTCPFeedback to webrtc.RTCPFeedback.
type RTCPFeedbackConfig ¶
type RTCPFeedbackConfig struct {
// VideoFeedback is the list of RTCP feedback mechanisms for video.
VideoFeedback []RTCPFeedback
// AudioFeedback is the list of RTCP feedback mechanisms for audio.
AudioFeedback []RTCPFeedback
}
RTCPFeedbackConfig holds configuration for RTCP feedback mechanisms.
func DefaultRTCPFeedbackConfig ¶
func DefaultRTCPFeedbackConfig() RTCPFeedbackConfig
DefaultRTCPFeedbackConfig returns the default RTCP feedback configuration.
type RTCPFeedbackParam ¶
type RTCPFeedbackParam string
RTCPFeedbackParam represents the parameter for RTCP feedback. These match pion/webrtc's Parameter field values.
const ( // RTCPFeedbackParamNone represents no parameter (empty string). RTCPFeedbackParamNone RTCPFeedbackParam = "" // RTCPFeedbackParamPLI is the PLI (Picture Loss Indication) parameter. RTCPFeedbackParamPLI RTCPFeedbackParam = "pli" // RTCPFeedbackParamFIR is the FIR (Full Intra Request) parameter. RTCPFeedbackParamFIR RTCPFeedbackParam = "fir" )
type RTCPFeedbackType ¶
type RTCPFeedbackType string
RTCPFeedbackType represents the type of RTCP feedback. These match pion/webrtc's Type field values.
const ( // RTCPFeedbackTypeNACK is the NACK feedback type. RTCPFeedbackTypeNACK RTCPFeedbackType = "nack" // RTCPFeedbackTypeCCM is the CCM (Codec Control Messages) feedback type. RTCPFeedbackTypeCCM RTCPFeedbackType = "ccm" // RTCPFeedbackTypeGoogREMB is the goog-remb feedback type for bandwidth estimation. RTCPFeedbackTypeGoogREMB RTCPFeedbackType = "goog-remb" // RTCPFeedbackTypeTransportCC is the transport-cc feedback type for congestion control. RTCPFeedbackTypeTransportCC RTCPFeedbackType = "transport-cc" )
type SDPConfig ¶
type SDPConfig struct {
// EnableSafariCompat enables Safari compatibility mode.
EnableSafariCompat bool
}
SDPConfig contains configuration for SDP processing.
func DefaultSDPConfig ¶
func DefaultSDPConfig() SDPConfig
DefaultSDPConfig returns a default SDPConfig.
type SDPProcessor ¶
type SDPProcessor struct {
// contains filtered or unexported fields
}
SDPProcessor handles SDP parsing, generation, and normalization.
func NewSDPProcessor ¶
func NewSDPProcessor(config SDPConfig) *SDPProcessor
NewSDPProcessor creates a new SDPProcessor with the given configuration.
func (*SDPProcessor) AddAttribute ¶
AddAttribute adds an attribute to the SDP at session level.
func (*SDPProcessor) EnsureUnifiedPlan ¶
func (p *SDPProcessor) EnsureUnifiedPlan(sd *sdp.SessionDescription) error
EnsureUnifiedPlan ensures the SDP uses Unified Plan semantics. This is an alias for enforceUnifiedPlan for external callers.
func (*SDPProcessor) ExtractCodecs ¶
func (p *SDPProcessor) ExtractCodecs(sdpStr string) ([]CodecInfo, error)
ExtractCodecs extracts codec information from the SDP.
func (*SDPProcessor) ExtractMIDs ¶
func (p *SDPProcessor) ExtractMIDs(sdpStr string) ([]string, error)
ExtractMIDs extracts all MID values from the SDP.
func (*SDPProcessor) ExtractSSRCs ¶
func (p *SDPProcessor) ExtractSSRCs(sdpStr string) ([]uint32, error)
ExtractSSRCs extracts all SSRCs from the SDP.
func (*SDPProcessor) ExtractSimulcastLayers ¶
func (p *SDPProcessor) ExtractSimulcastLayers(sdpStr string) ([]SimulcastLayer, error)
ExtractSimulcastLayers extracts simulcast layer information from the SDP.
func (*SDPProcessor) GetBundleGroup ¶
func (p *SDPProcessor) GetBundleGroup(sdpStr string) ([]string, error)
GetBundleGroup extracts the BUNDLE group MIDs from the SDP.
func (*SDPProcessor) GetFingerprint ¶
func (p *SDPProcessor) GetFingerprint(sdpStr string) (algorithm string, fingerprint string, err error)
GetFingerprint extracts the DTLS fingerprint from the SDP.
func (*SDPProcessor) GetICECredentials ¶
func (p *SDPProcessor) GetICECredentials(sdpStr string) (ufrag string, pwd string, err error)
GetICECredentials extracts ICE credentials from the SDP.
func (*SDPProcessor) IsSimulcastEnabled ¶
func (p *SDPProcessor) IsSimulcastEnabled(sdpStr string) (bool, error)
IsSimulcastEnabled checks if simulcast is enabled in the SDP.
func (*SDPProcessor) ModifySDP ¶
func (p *SDPProcessor) ModifySDP(sdpStr string, modifier func(*sdp.SessionDescription) error) (string, error)
ModifySDP allows modification of an SDP using a callback function.
func (*SDPProcessor) NormalizeForSafari ¶
func (p *SDPProcessor) NormalizeForSafari(sdpStr string) (string, error)
NormalizeForSafari normalizes an SDP for Safari compatibility.
func (*SDPProcessor) ParseSDP ¶
func (p *SDPProcessor) ParseSDP(sdpStr string) (*sdp.SessionDescription, error)
ParseSDP parses an SDP string into a SessionDescription.
func (*SDPProcessor) RemoveCodec ¶
func (p *SDPProcessor) RemoveCodec(sdpStr string, codecName string) (string, error)
RemoveCodec removes a codec from the SDP by name.
func (*SDPProcessor) SetCodecPriority ¶
func (p *SDPProcessor) SetCodecPriority(sdpStr string, mediaType string, priorities []string) (string, error)
SetCodecPriority reorders codecs in the SDP by priority.
func (*SDPProcessor) ValidateAnswer ¶
func (p *SDPProcessor) ValidateAnswer(answer webrtc.SessionDescription) error
ValidateAnswer validates an SDP answer for required features.
func (*SDPProcessor) ValidateOffer ¶
func (p *SDPProcessor) ValidateOffer(offer webrtc.SessionDescription) error
ValidateOffer validates an SDP offer for required features.
type SVCCodecConfig ¶
type SVCCodecConfig struct {
// Enabled indicates if SVC is enabled for this codec.
Enabled bool
// ScalabilityMode is the scalability mode string (e.g., "L3T3").
// L<n>T<m> means n spatial layers and m temporal layers.
ScalabilityMode string
}
SVCCodecConfig holds SVC-specific configuration for VP9/AV1 codecs.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages WebRTC peer connections for all participants. This is the main coordination layer between signaling and WebRTC.
func NewService ¶
func NewService(config PeerConfig, mediaEngine *pion.MediaEngine, events EventHandler) *Service
NewService creates a new WebRTC service.
func (*Service) GetPeer ¶
GetPeer returns the peer for the given participant ID. Returns nil if no peer exists.
func (*Service) HandleAnswer ¶
HandleAnswer processes an SDP answer from a client.
func (*Service) HandleCandidate ¶
func (s *Service) HandleCandidate(ctx context.Context, participantID string, candidate string, sdpMid string, sdpMLineIndex *int) error
HandleCandidate processes an ICE candidate from a client.
func (*Service) HandleOffer ¶
func (s *Service) HandleOffer(ctx context.Context, participantID string, sdp string) (string, error)
HandleOffer processes an SDP offer from a client and returns an SDP answer. This method creates a new peer connection if one doesn't exist (lazy creation).
func (*Service) RemovePeer ¶
RemovePeer removes and closes the peer for the given participant ID.
type SimulcastLayer ¶
SimulcastLayer represents a simulcast layer in the SDP.
type TURNConfig ¶
type TURNConfig struct {
// URLs are the TURN server URLs.
// Supports multiple URLs for fallback per requirements.md (section 2.7.1).
URLs []string
// Secret is the shared secret for HMAC-SHA1 credential generation.
// This must be kept secure and synchronized with the TURN server.
Secret string
// CredentialTTL is the validity period for credentials.
// Per requirements.md (section 2.7.2), default is 24 hours.
CredentialTTL time.Duration
// RotationInterval is the interval for credential rotation.
// Per requirements.md (section 2.7.2), default is 12 hours.
RotationInterval time.Duration
}
TURNConfig contains TURN server configuration.
func DefaultTURNConfig ¶
func DefaultTURNConfig() TURNConfig
DefaultTURNConfig returns the default TURN configuration.
func (*TURNConfig) Validate ¶
func (c *TURNConfig) Validate() error
Validate validates the TURN configuration.
type TURNCredentialService ¶
type TURNCredentialService interface {
// GenerateCredentials creates new TURN credentials for a participant.
// The credentials are valid for the configured TTL (default 24 hours).
GenerateCredentials(participantID string) (*TURNCredentials, error)
// RefreshCredentials generates new credentials before expiry.
// This should be called periodically (default every 12 hours).
RefreshCredentials(participantID string) (*TURNCredentials, error)
}
TURNCredentialService generates time-limited TURN credentials. Per requirements.md (section 2.7.2), this implements Long-term credentials (RFC 5389).
func NewTURNCredentialService ¶
func NewTURNCredentialService(config TURNConfig) (TURNCredentialService, error)
NewTURNCredentialService creates a new TURN credential service. Per requirements.md (section 2.7.2), this implements Long-term credentials (RFC 5389).
type TURNCredentials ¶
type TURNCredentials struct {
// URLs are the TURN server URLs (e.g., "turn:turn.example.com:3478").
URLs []string
// Username is the time-limited username in the format "timestamp:username".
// The timestamp is the Unix timestamp of expiration time.
Username string
// Credential is the HMAC-SHA1 signature of the username, base64-encoded.
// Calculated as base64(HMAC-SHA1(secret, username)).
Credential string
// CreatedAt is the time when the credentials were created.
CreatedAt time.Time
// ExpiresAt is the expiration time of the credentials.
ExpiresAt time.Time
}
TURNCredentials represents time-limited TURN credentials. Per requirements.md (section 2.7.2), credentials use TURN REST API method (RFC 5389 Long-term authentication mechanism with HMAC-SHA1 dynamic credential generation).
func (*TURNCredentials) IsExpired ¶
func (c *TURNCredentials) IsExpired() bool
IsExpired checks if the credentials have expired.
func (*TURNCredentials) NeedsRotation ¶
func (c *TURNCredentials) NeedsRotation(rotationInterval time.Duration) bool
NeedsRotation checks if the credentials should be rotated. Per requirements.md (section 2.7.2), credentials should be rotated every 12 hours. This checks if the elapsed time since creation has exceeded the rotation interval.
func (*TURNCredentials) TimeToExpiry ¶
func (c *TURNCredentials) TimeToExpiry() time.Duration
TimeToExpiry returns the duration until expiration. Returns 0 if already expired.
type TURNProtocol ¶
type TURNProtocol string
TURNProtocol represents the TURN transport protocol. Per requirements.md (section 2.7.2), supports UDP, TCP, and TLS.
const ( // TURNProtocolUDP uses UDP transport (standard TURN port 3478). TURNProtocolUDP TURNProtocol = "udp" // TURNProtocolTCP uses TCP transport (standard TURN port 3478). TURNProtocolTCP TURNProtocol = "tcp" // TURNProtocolTLS uses TLS over TCP (standard port 443 for firewall traversal). TURNProtocolTLS TURNProtocol = "tls" )
type TrackHandler ¶
type TrackHandler func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver)
TrackHandler is called when a new track is received.
type VideoCodecConfig ¶
type VideoCodecConfig struct {
// Name is the codec name.
Name VideoCodecName
// Priority is the codec priority (lower is higher priority).
Priority int
// MimeType is the MIME type of the codec.
MimeType string
// ClockRate is the clock rate in Hz.
ClockRate uint32
// RTCPFeedback is the list of RTCP feedback mechanisms.
RTCPFeedback []RTCPFeedback
// Profiles contains H.264 specific profile configurations.
// Only used when Name is CodecH264.
Profiles []H264ProfileConfig
// SVCConfig contains SVC-specific configuration for VP9/AV1.
// Only used when Name is CodecVP9 or CodecAV1.
SVCConfig *SVCCodecConfig
}
VideoCodecConfig holds configuration for a video codec.
func (VideoCodecConfig) Copy ¶
func (vc VideoCodecConfig) Copy() VideoCodecConfig
Copy creates a copy of the VideoCodecConfig.
type VideoCodecName ¶
type VideoCodecName string
VideoCodecName represents supported video codec names.
const ( // CodecVP8 is the VP8 video codec. CodecVP8 VideoCodecName = "VP8" // CodecVP9 is the VP9 video codec. // VP9 supports SVC (Scalable Video Coding) with spatial and temporal layers. CodecVP9 VideoCodecName = "VP9" // CodecH264 is the H.264 video codec. CodecH264 VideoCodecName = "H264" // CodecAV1 is the AV1 video codec. // AV1 supports SVC (Scalable Video Coding) with spatial and temporal layers. CodecAV1 VideoCodecName = "AV1" )