Documentation ¶
Index ¶
- Constants
- Variables
- type Candidates
- type Config
- type Datachannel
- type DownTrack
- func (d *DownTrack) Bind(t webrtc.TrackLocalContext) (webrtc.RTPCodecParameters, error)
- func (d *DownTrack) Close()
- func (d *DownTrack) Codec() webrtc.RTPCodecCapability
- func (d *DownTrack) ID() string
- func (d *DownTrack) Kind() webrtc.RTPCodecType
- func (d *DownTrack) Mute(val bool)
- func (d *DownTrack) OnBind(fn func())
- func (d *DownTrack) OnCloseHandler(fn func())
- func (d *DownTrack) StreamID() string
- func (d *DownTrack) SwitchSpatialLayer(targetLayer int)
- func (d *DownTrack) Unbind(_ webrtc.TrackLocalContext) error
- func (d *DownTrack) WriteRTP(p rtp.Packet) error
- type DownTrackType
- type ICEServerConfig
- type MessageProcessor
- type Middlewares
- type NACK
- type Peer
- func (p *Peer) Answer(sdp webrtc.SessionDescription) (*webrtc.SessionDescription, error)
- func (p *Peer) Close() error
- func (p *Peer) Join(sid string, sdp webrtc.SessionDescription) (*webrtc.SessionDescription, error)
- func (p *Peer) Publisher() *Publisher
- func (p *Peer) Session() *Session
- func (p *Peer) SetRemoteDescription(sdp webrtc.SessionDescription) error
- func (p *Peer) Subscriber() *Subscriber
- func (p *Peer) Trickle(candidate webrtc.ICECandidateInit, target int) error
- type ProcessArgs
- type ProcessFunc
- type Publisher
- func (p *Publisher) AddICECandidate(candidate webrtc.ICECandidateInit) error
- func (p *Publisher) Answer(offer webrtc.SessionDescription) (webrtc.SessionDescription, error)
- func (p *Publisher) Close()
- func (p *Publisher) GetRouter() Router
- func (p *Publisher) OnICECandidate(f func(c *webrtc.ICECandidate))
- func (p *Publisher) OnICEConnectionStateChange(f func(connectionState webrtc.ICEConnectionState))
- func (p *Publisher) SignalingState() webrtc.SignalingState
- type Receiver
- type Router
- type RouterConfig
- type SFU
- type Session
- func (s *Session) AddDatachannel(owner string, dc *webrtc.DataChannel)
- func (s *Session) AddPeer(peer *Peer)
- func (s *Session) OnClose(f func())
- func (s *Session) Peers() map[string]*Peer
- func (s *Session) Publish(router Router, r Receiver)
- func (s *Session) RemovePeer(pid string)
- func (s *Session) Subscribe(peer *Peer)
- type SessionProvider
- type SimulcastConfig
- type Subscriber
- func (s *Subscriber) AddDataChannel(label string) (*webrtc.DataChannel, error)
- func (s *Subscriber) AddDatachannel(peer *Peer, dc *Datachannel) error
- func (s *Subscriber) AddDownTrack(streamID string, downTrack *DownTrack)
- func (s *Subscriber) AddICECandidate(candidate webrtc.ICECandidateInit) error
- func (s *Subscriber) Close() error
- func (s *Subscriber) CreateOffer() (webrtc.SessionDescription, error)
- func (s *Subscriber) GetDownTracks(streamID string) []*DownTrack
- func (s *Subscriber) OnICECandidate(f func(c *webrtc.ICECandidate))
- func (s *Subscriber) OnNegotiationNeeded(f func())
- func (s *Subscriber) RemoveDownTrack(streamID string, downTrack *DownTrack)
- func (s *Subscriber) SetRemoteDescription(desc webrtc.SessionDescription) error
- type TransportWideCC
- type TurnAuth
- type TurnConfig
- type VP8Helper
- type WebRTCConfig
- type WebRTCReceiver
- func (w *WebRTCReceiver) AddDownTrack(track *DownTrack, bestQualityFirst bool)
- func (w *WebRTCReceiver) AddUpTrack(track *webrtc.TrackRemote, buff *buffer.Buffer)
- func (w *WebRTCReceiver) Codec() webrtc.RTPCodecParameters
- func (w *WebRTCReceiver) DeleteDownTrack(layer int, id string)
- func (w *WebRTCReceiver) Kind() webrtc.RTPCodecType
- func (w *WebRTCReceiver) OnCloseHandler(fn func())
- func (w *WebRTCReceiver) RetransmitPackets(track *DownTrack, packets []uint16, snOffset uint16) error
- func (w *WebRTCReceiver) SSRC(layer int) uint32
- func (w *WebRTCReceiver) SendRTCP(p []rtcp.Packet)
- func (w *WebRTCReceiver) SetRTCPCh(ch chan []rtcp.Packet)
- func (w *WebRTCReceiver) StreamID() string
- func (w *WebRTCReceiver) SubDownTrack(track *DownTrack, layer int) error
- func (w *WebRTCReceiver) TrackID() string
- type WebRTCTransportConfig
Constants ¶
const APIChannelLabel = "ion-sfu"
Variables ¶
var ( // ErrTransportExists join is called after a peerconnection is established ErrTransportExists = errors.New("rtc transport already exists for this connection") // ErrNoTransportEstablished cannot signal before join ErrNoTransportEstablished = errors.New("no rtc transport exists for this Peer") // ErrOfferIgnored if offer received in unstable state ErrOfferIgnored = errors.New("offered ignored") )
Functions ¶
This section is empty.
Types ¶
type Candidates ¶
type Config ¶
type Config struct { SFU struct { Ballast int64 `mapstructure:"ballast"` WithStats bool `mapstructure:"withstats"` } `mapstructure:"sfu"` WebRTC WebRTCConfig `mapstructure:"webrtc"` Log log.Config `mapstructure:"log"` Router RouterConfig `mapstructure:"router"` Turn TurnConfig `mapstructure:"turn"` }
Config for base SFU
type Datachannel ¶
type Datachannel struct {
// contains filtered or unexported fields
}
Datachannel is a wrapper to define middlewares executed on defined label. The datachannels created will be negotiated on join to all peers that joins the SFU.
func (*Datachannel) OnMessage ¶
func (dc *Datachannel) OnMessage(fn func(ctx context.Context, args ProcessArgs, out []*webrtc.DataChannel))
OnMessage sets the message callback for the datachannel, the event is fired after all the middlewares have processed the message.
func (*Datachannel) Use ¶
func (dc *Datachannel) Use(middlewares ...func(MessageProcessor) MessageProcessor)
Use adds the middlewares to the current Datachannel. The middlewares are going to be executed before the OnMessage event fires.
type DownTrack ¶
type DownTrack struct {
// contains filtered or unexported fields
}
DownTrack implements TrackLocal, is the track used to write packets to SFU Subscriber, the track handle the packets for simple, simulcast and SVC Publisher.
func NewDownTrack ¶
NewDownTrack returns a DownTrack.
func (*DownTrack) Bind ¶
Bind is called by the PeerConnection after negotiation is complete This asserts that the code requested is supported by the remote peer. If so it setups all the state (SSRC and PayloadType) to have a call
func (*DownTrack) Codec ¶
func (d *DownTrack) Codec() webrtc.RTPCodecCapability
Codec returns current track codec capability
func (*DownTrack) ID ¶
ID is the unique identifier for this Track. This should be unique for the stream, but doesn't have to globally unique. A common example would be 'audio' or 'video' and StreamID would be 'desktop' or 'webcam'
func (*DownTrack) Kind ¶
func (d *DownTrack) Kind() webrtc.RTPCodecType
Kind controls if this TrackLocal is audio or video
func (*DownTrack) OnCloseHandler ¶
func (d *DownTrack) OnCloseHandler(fn func())
OnCloseHandler method to be called on remote tracked removed
func (*DownTrack) SwitchSpatialLayer ¶
type DownTrackType ¶
type DownTrackType int
DownTrackType determines the type of a track
const ( SimpleDownTrack DownTrackType = iota + 1 SimulcastDownTrack SVCDownTrack )
type ICEServerConfig ¶
type ICEServerConfig struct { URLs []string `mapstructure:"urls"` Username string `mapstructure:"username"` Credential string `mapstructure:"credential"` }
ICEServerConfig defines parameters for ice servers
type MessageProcessor ¶
type MessageProcessor interface {
Process(ctx context.Context, args ProcessArgs)
}
type Middlewares ¶
type Middlewares []func(MessageProcessor) MessageProcessor
func (Middlewares) Process ¶
func (mws Middlewares) Process(h MessageProcessor) MessageProcessor
func (Middlewares) ProcessFunc ¶
func (mws Middlewares) ProcessFunc(h MessageProcessor) MessageProcessor
type Peer ¶
type Peer struct { sync.Mutex OnOffer func(*webrtc.SessionDescription) OnIceCandidate func(*webrtc.ICECandidateInit, int) OnICEConnectionStateChange func(webrtc.ICEConnectionState) // contains filtered or unexported fields }
Peer represents a pair peer connection
func NewPeer ¶
func NewPeer(provider SessionProvider) *Peer
NewPeer creates a new Peer for signaling with the given SFU
func (*Peer) SetRemoteDescription ¶
SetRemoteDescription when receiving an answer from remote
func (*Peer) Subscriber ¶
func (p *Peer) Subscriber() *Subscriber
type ProcessArgs ¶
type ProcessArgs struct { Peer *Peer Message webrtc.DataChannelMessage DataChannel *webrtc.DataChannel }
type ProcessFunc ¶
type ProcessFunc func(ctx context.Context, args ProcessArgs)
func (ProcessFunc) Process ¶
func (p ProcessFunc) Process(ctx context.Context, args ProcessArgs)
type Publisher ¶
type Publisher struct {
// contains filtered or unexported fields
}
func NewPublisher ¶
func NewPublisher(session *Session, id string, cfg WebRTCTransportConfig) (*Publisher, error)
NewPublisher creates a new Publisher
func (*Publisher) AddICECandidate ¶
AddICECandidate to peer connection
func (*Publisher) OnICECandidate ¶
func (p *Publisher) OnICECandidate(f func(c *webrtc.ICECandidate))
OnICECandidate handler
func (*Publisher) OnICEConnectionStateChange ¶
func (p *Publisher) OnICEConnectionStateChange(f func(connectionState webrtc.ICEConnectionState))
func (*Publisher) SignalingState ¶
func (p *Publisher) SignalingState() webrtc.SignalingState
type Receiver ¶
type Receiver interface { TrackID() string StreamID() string Codec() webrtc.RTPCodecParameters Kind() webrtc.RTPCodecType SSRC(layer int) uint32 AddUpTrack(track *webrtc.TrackRemote, buffer *buffer.Buffer) AddDownTrack(track *DownTrack, bestQualityFirst bool) SubDownTrack(track *DownTrack, layer int) error RetransmitPackets(track *DownTrack, packets []uint16, snOffset uint16) error DeleteDownTrack(layer int, id string) OnCloseHandler(fn func()) SendRTCP(p []rtcp.Packet) SetRTCPCh(ch chan []rtcp.Packet) }
Receiver defines a interface for a track receivers
func NewWebRTCReceiver ¶
func NewWebRTCReceiver(receiver *webrtc.RTPReceiver, track *webrtc.TrackRemote, pid string) Receiver
NewWebRTCReceiver creates a new webrtc track receivers
type Router ¶
type Router interface { ID() string AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.TrackRemote) (Receiver, bool) AddDownTracks(s *Subscriber, r Receiver) error Stop() }
Router defines a track rtp/rtcp router
type RouterConfig ¶
type RouterConfig struct { WithStats bool `mapstructure:"withstats"` MaxBandwidth uint64 `mapstructure:"maxbandwidth"` MaxBufferTime int `mapstructure:"maxbuffertime"` Simulcast SimulcastConfig `mapstructure:"simulcast"` }
RouterConfig defines router configurations
type SFU ¶
SFU represents an sfu instance
func (*SFU) GetSession ¶
func (s *SFU) GetSession(sid string) (*Session, WebRTCTransportConfig)
func (*SFU) NewDatachannel ¶
func (s *SFU) NewDatachannel(label string) *Datachannel
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents a set of peers. Transports inside a session are automatically subscribed to each other.
func NewSession ¶
func NewSession(id string, dcs []*Datachannel) *Session
NewSession creates a new session
func (*Session) AddDatachannel ¶
func (*Session) OnClose ¶
func (s *Session) OnClose(f func())
OnClose is called when the session is closed
func (*Session) Publish ¶
Publish will add a Sender to all peers in current Session from given Receiver
func (*Session) RemovePeer ¶
RemovePeer removes a transport from the session
type SessionProvider ¶
type SessionProvider interface {
GetSession(sid string) (*Session, WebRTCTransportConfig)
}
SessionProvider provides the session to the sfu.Peer{} This allows the sfu.SFU{} implementation to be customized / wrapped by another package
type SimulcastConfig ¶
type Subscriber ¶
func NewSubscriber ¶
func NewSubscriber(id string, cfg WebRTCTransportConfig) (*Subscriber, error)
NewSubscriber creates a new Subscriber
func (*Subscriber) AddDataChannel ¶
func (s *Subscriber) AddDataChannel(label string) (*webrtc.DataChannel, error)
func (*Subscriber) AddDatachannel ¶
func (s *Subscriber) AddDatachannel(peer *Peer, dc *Datachannel) error
func (*Subscriber) AddDownTrack ¶
func (s *Subscriber) AddDownTrack(streamID string, downTrack *DownTrack)
func (*Subscriber) AddICECandidate ¶
func (s *Subscriber) AddICECandidate(candidate webrtc.ICECandidateInit) error
AddICECandidate to peer connection
func (*Subscriber) CreateOffer ¶
func (s *Subscriber) CreateOffer() (webrtc.SessionDescription, error)
func (*Subscriber) GetDownTracks ¶
func (s *Subscriber) GetDownTracks(streamID string) []*DownTrack
func (*Subscriber) OnICECandidate ¶
func (s *Subscriber) OnICECandidate(f func(c *webrtc.ICECandidate))
OnICECandidate handler
func (*Subscriber) OnNegotiationNeeded ¶
func (s *Subscriber) OnNegotiationNeeded(f func())
func (*Subscriber) RemoveDownTrack ¶
func (s *Subscriber) RemoveDownTrack(streamID string, downTrack *DownTrack)
func (*Subscriber) SetRemoteDescription ¶
func (s *Subscriber) SetRemoteDescription(desc webrtc.SessionDescription) error
SetRemoteDescription sets the SessionDescription of the remote peer
type TransportWideCC ¶
type TurnConfig ¶
type TurnConfig struct { Enabled bool `mapstructure:"enabled"` Realm string `mapstructure:"realm"` Address string `mapstructure:"address"` Cert string `mapstructure:"cert"` Key string `mapstructure:"key"` Auth TurnAuth `mapstructure:"auth"` }
WebRTCConfig defines parameters for ice
type VP8Helper ¶
type VP8Helper struct { TemporalSupported bool // Optional Header PictureID uint16 /* 8 or 16 bits, picture ID */ TL0PICIDX uint8 /* 8 bits temporal level zero index */ // Optional Header If either of the T or K bits are set to 1, // the TID/Y/KEYIDX extension field MUST be present. TID uint8 /* 2 bits temporal layer idx*/ // IsKeyFrame is a helper to detect if current packet is a keyframe IsKeyFrame bool // contains filtered or unexported fields }
VP8Helper is a helper to get temporal data from VP8 packet header
VP8Helper Payload Descriptor 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ |X|R|N|S|R| PID | (REQUIRED) |X|R|N|S|R| PID | (REQUIRED) +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ X: |I|L|T|K| RSV | (OPTIONAL) X: |I|L|T|K| RSV | (OPTIONAL) +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ I: |M| PictureID | (OPTIONAL) I: |M| PictureID | (OPTIONAL) +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ L: | TL0PICIDX | (OPTIONAL) | PictureID | +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ T/K:|TID|Y| KEYIDX | (OPTIONAL) L: | TL0PICIDX | (OPTIONAL) +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ T/K:|TID|Y| KEYIDX | (OPTIONAL) +-+-+-+-+-+-+-+-+
type WebRTCConfig ¶
type WebRTCConfig struct { ICEPortRange []uint16 `mapstructure:"portrange"` ICEServers []ICEServerConfig `mapstructure:"iceserver"` Candidates Candidates `mapstructure:"candidates"` SDPSemantics string `mapstructure:"sdpsemantics"` MDNS bool `mapstructure:"mdns"` }
WebRTCConfig defines parameters for ice
type WebRTCReceiver ¶
WebRTCReceiver receives a video track
func (*WebRTCReceiver) AddDownTrack ¶
func (w *WebRTCReceiver) AddDownTrack(track *DownTrack, bestQualityFirst bool)
func (*WebRTCReceiver) AddUpTrack ¶
func (w *WebRTCReceiver) AddUpTrack(track *webrtc.TrackRemote, buff *buffer.Buffer)
func (*WebRTCReceiver) Codec ¶
func (w *WebRTCReceiver) Codec() webrtc.RTPCodecParameters
func (*WebRTCReceiver) DeleteDownTrack ¶
func (w *WebRTCReceiver) DeleteDownTrack(layer int, id string)
DeleteDownTrack removes a DownTrack from a Receiver
func (*WebRTCReceiver) Kind ¶
func (w *WebRTCReceiver) Kind() webrtc.RTPCodecType
func (*WebRTCReceiver) OnCloseHandler ¶
func (w *WebRTCReceiver) OnCloseHandler(fn func())
OnCloseHandler method to be called on remote tracked removed
func (*WebRTCReceiver) RetransmitPackets ¶
func (w *WebRTCReceiver) RetransmitPackets(track *DownTrack, packets []uint16, snOffset uint16) error
func (*WebRTCReceiver) SSRC ¶
func (w *WebRTCReceiver) SSRC(layer int) uint32
func (*WebRTCReceiver) SendRTCP ¶
func (w *WebRTCReceiver) SendRTCP(p []rtcp.Packet)
func (*WebRTCReceiver) SetRTCPCh ¶
func (w *WebRTCReceiver) SetRTCPCh(ch chan []rtcp.Packet)
func (*WebRTCReceiver) StreamID ¶
func (w *WebRTCReceiver) StreamID() string
func (*WebRTCReceiver) SubDownTrack ¶
func (w *WebRTCReceiver) SubDownTrack(track *DownTrack, layer int) error
func (*WebRTCReceiver) TrackID ¶
func (w *WebRTCReceiver) TrackID() string
type WebRTCTransportConfig ¶
type WebRTCTransportConfig struct {
// contains filtered or unexported fields
}
WebRTCTransportConfig represents configuration options
func NewWebRTCTransportConfig ¶
func NewWebRTCTransportConfig(c Config) WebRTCTransportConfig
NewWebRTCTransportConfig parses our settings and returns a usable WebRTCTransportConfig for creating PeerConnections