Overview
ThePeerConnection represents a WebRTC connection that establishes peer-to-peer communications with another PeerConnection instance in a browser, or to another endpoint implementing the required protocols.
Source:
peerconnection.go:33-98Type Definition
Constructors
NewPeerConnection
Creates a PeerConnection with the default codecs and interceptors.Source:
peerconnection.go:100-109Configuration for the new PeerConnection
The newly created PeerConnection
Error if creation fails, nil otherwise
If you wish to customize the set of available codecs and/or the set of active interceptors, create an API with a custom MediaEngine and/or interceptor.Registry, then call
api.NewPeerConnection() instead.Offer/Answer Methods
CreateOffer
Starts the PeerConnection and generates the local description.Source:
peerconnection.go:665-797Optional offer options (e.g., ICERestart)
The generated SDP offer
Error if offer creation fails
CreateAnswer
Starts the PeerConnection and generates the local description in response to an offer.Source:
peerconnection.go:893-965Optional answer options
The generated SDP answer
Error if answer creation fails, or if no remote description is set
SetLocalDescription
Sets the SessionDescription of the local peer.Source:
peerconnection.go:1087-1146The local session description to set
Error if the description is invalid or connection is closed
According to JSEP 5.4, if
desc.SDP is empty, the last created offer or answer will be used based on desc.Type.SetRemoteDescription
Sets the SessionDescription of the remote peer.Source:
peerconnection.go:1160-1369The remote session description to set
Error if the description is invalid or connection is closed
Session Description Accessors
LocalDescription
Returns PendingLocalDescription if it is not null, otherwise returns CurrentLocalDescription.Source:
peerconnection.go:1148-1158The current local description, or nil
RemoteDescription
Returns pendingRemoteDescription if it is not null, otherwise returns currentRemoteDescription.Source:
peerconnection.go:2056-2069The current remote description, or nil
CurrentLocalDescription
Represents the local description that was successfully negotiated the last time the PeerConnection transitioned into the stable state.Source:
peerconnection.go:2606-2619PendingLocalDescription
Represents a local description that is in the process of being negotiated. Returns nil if the PeerConnection is in the stable state.Source:
peerconnection.go:2621-2634CurrentRemoteDescription
Represents the last remote description that was successfully negotiated.Source:
peerconnection.go:2636-2645PendingRemoteDescription
Represents a remote description that is in the process of being negotiated.Source:
peerconnection.go:2647-2657ICE Methods
AddICECandidate
Accepts an ICE candidate string and adds it to the existing set of candidates.Source:
peerconnection.go:2071-2116The ICE candidate to add
Error if no remote description is set or candidate is invalid
OnICECandidate
Sets an event handler which is invoked when a new ICE candidate is found.Source:
peerconnection.go:456-464Handler called with each new ICE candidate (nil when gathering is finished)
ICE candidate gathering only begins when SetLocalDescription or SetRemoteDescription is called. The handler will be called with a nil pointer when gathering is finished.
OnICEGatheringStateChange
Sets an event handler which is invoked when the ICE candidate gathering state has changed.Source:
peerconnection.go:466-480Handler called when gathering state changes
OnICEConnectionStateChange
Sets an event handler which is called when an ICE connection state is changed.Source:
peerconnection.go:505-509Handler called when ICE connection state changes
Media Methods
AddTrack
Adds a Track to the PeerConnection.Source:
peerconnection.go:2181-2219The local track to add
The RTPSender for the added track
Error if the connection is closed or track cannot be added
RemoveTrack
Removes a Track from the PeerConnection.Source:
peerconnection.go:2221-2247The RTPSender to remove
Error if the connection is closed or sender not found
OnTrack
Sets an event handler which is called when remote track arrives from a remote peer.Source:
peerconnection.go:482-488Handler called for each incoming remote track
AddTransceiverFromKind
Creates a new RTPTransceiver and adds it to the set of transceivers.Source:
peerconnection.go:2284-2329The kind of media (Audio or Video)
Optional initialization parameters
The created transceiver
Error if creation fails
AddTransceiverFromTrack
Creates a new RTPTransceiver (SendRecv or SendOnly) and adds it to the set of transceivers.Source:
peerconnection.go:2331-2355The local track for the transceiver
Optional initialization parameters
The created transceiver
Error if creation fails
GetSenders
Returns the RTPSender that are currently attached to this PeerConnection.Source:
peerconnection.go:2145-2157Array of RTPSenders
GetReceivers
Returns the RTPReceivers that are currently attached to this PeerConnection.Source:
peerconnection.go:2159-2171Array of RTPReceivers
GetTransceivers
Returns the RTPTransceivers that are currently attached to this PeerConnection.Source:
peerconnection.go:2173-2179Array of RTPTransceivers
Data Channel Methods
CreateDataChannel
Creates a new DataChannel object with the given label and optional DataChannelInit.Source:
peerconnection.go:2357-2442Label for the data channel
Optional configuration for the data channel
The created data channel
Error if creation fails or connection is closed
OnDataChannel
Sets an event handler which is invoked when a data channel message arrives from a remote peer.Source:
peerconnection.go:298-304Handler called for each incoming data channel
State Accessors
SignalingState
Returns the signaling state of the PeerConnection instance.Source:
peerconnection.go:2668-2672Current signaling state
ICEGatheringState
Returns the ICE gathering state of the PeerConnection instance.Source:
peerconnection.go:2674-2689Current ICE gathering state
ICEConnectionState
Returns the ICE connection state of the PeerConnection instance.Source:
peerconnection.go:2135-2143Current ICE connection state
ConnectionState
Returns the connection state of the PeerConnection instance.Source:
peerconnection.go:2691-2699Current peer connection state
CanTrickleICECandidates
Reports whether the remote endpoint indicated support for receiving trickled ICE candidates.Source:
peerconnection.go:2659-2666Trickle ICE capability (Unknown, Supported, or Unsupported)
Event Handlers
OnSignalingStateChange
Sets an event handler which is invoked when the peer connection’s signaling state changes.Source:
peerconnection.go:279-285Handler called when signaling state changes
OnConnectionStateChange
Sets an event handler which is called when the PeerConnectionState has changed.Source:
peerconnection.go:519-523Handler called when connection state changes
OnNegotiationNeeded
Sets an event handler which is invoked when a change has occurred which requires session negotiation.Source:
peerconnection.go:306-310Handler called when negotiation is needed
Configuration Methods
GetConfiguration
Returns a Configuration object representing the current configuration of this PeerConnection.Source:
peerconnection.go:632-639Copy of the current configuration
The returned object is a copy and direct mutation on it will not take effect until SetConfiguration has been called.
SetConfiguration
Updates the configuration of this PeerConnection object.Source:
peerconnection.go:533-630New configuration to apply
Error if configuration is invalid or cannot be modified
Statistics
GetStats
Returns data providing statistics about the overall connection.Source:
peerconnection.go:2701-2765Statistics report for the connection
Lifecycle Methods
Close
Ends the PeerConnection.Source:
peerconnection.go:2461-2464Any errors encountered during closure (may be nil)
GracefulClose
Ends the PeerConnection and waits for any goroutines it started to complete.Source:
peerconnection.go:2466-2471Any errors encountered during closure (may be nil)
RTCP Methods
WriteRTCP
Sends a user provided RTCP packet to the connected peer.Source:
peerconnection.go:2449-2455RTCP packets to send
Error if sending fails
If no peer is connected the packet is discarded. It also runs any configured interceptors.
Additional Methods
SCTP
Returns the SCTPTransport for this PeerConnection.Source:
peerconnection.go:3101-3108The SCTP transport, or nil if SCTP has not been negotiated
ID
Returns the unique identifier for this PeerConnection.Source:
peerconnection.go:641-646Unique identifier string
See Also
- Configuration - Connection configuration
- SessionDescription - SDP management
- API - API configuration