Class RTCPeerConnection
Represents a WebRTC RTCPeerConnection.
Inherited Members
Namespace: SIPSorcery.Net
Assembly: SIPSorcery.dll
Syntax
public class RTCPeerConnection : RTPSession, IMediaSession, IDisposable, IRTCPeerConnection
Remarks
Interface is defined in https://www.w3.org/TR/webrtc/#interface-definition. The Session Description offer/answer mechanisms are detailed in https://tools.ietf.org/html/rfc8829 "JavaScript Session Establishment Protocol (JSEP)".
Constructors
| Improve this Doc View SourceRTCPeerConnection()
Constructor to create a new RTC peer connection instance.
Declaration
public RTCPeerConnection()
RTCPeerConnection(RTCConfiguration, Int32, PortRange, Boolean)
Constructor to create a new RTC peer connection instance.
Declaration
public RTCPeerConnection(RTCConfiguration configuration, int bindPort = 0, PortRange portRange = null, bool videoAsPrimary = false)
Parameters
| Type | Name | Description |
|---|---|---|
| RTCConfiguration | configuration | Optional. |
| System.Int32 | bindPort | |
| PortRange | portRange | |
| System.Boolean | videoAsPrimary |
Fields
| Improve this Doc View Source_cancellationSource
Declaration
protected CancellationTokenSource _cancellationSource
Field Value
| Type | Description |
|---|---|
| System.Threading.CancellationTokenSource |
_renegotiationLock
Declaration
protected object _renegotiationLock
Field Value
| Type | Description |
|---|---|
| System.Object |
_requireRenegotiation
Declaration
protected volatile bool _requireRenegotiation
Field Value
| Type | Description |
|---|---|
| System.Boolean |
Properties
| Improve this Doc View SourcecanTrickleIceCandidates
Declaration
public bool canTrickleIceCandidates { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
connectionState
Declaration
public RTCPeerConnectionState connectionState { get; }
Property Value
| Type | Description |
|---|---|
| RTCPeerConnectionState |
currentLocalDescription
Declaration
public RTCSessionDescription currentLocalDescription { get; }
Property Value
| Type | Description |
|---|---|
| RTCSessionDescription |
currentRemoteDescription
Declaration
public RTCSessionDescription currentRemoteDescription { get; }
Property Value
| Type | Description |
|---|---|
| RTCSessionDescription |
DataChannels
Declaration
public IReadOnlyCollection<RTCDataChannel> DataChannels { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IReadOnlyCollection<RTCDataChannel> |
DtlsCertificateFingerprint
The fingerprint of the certificate being used to negotiate the DTLS handshake with the remote peer.
Declaration
public RTCDtlsFingerprint DtlsCertificateFingerprint { get; }
Property Value
| Type | Description |
|---|---|
| RTCDtlsFingerprint |
DtlsCertificateSignatureAlgorithm
Declaration
public string DtlsCertificateSignatureAlgorithm { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
iceConnectionState
Declaration
public RTCIceConnectionState iceConnectionState { get; }
Property Value
| Type | Description |
|---|---|
| RTCIceConnectionState |
iceGatheringState
Declaration
public RTCIceGatheringState iceGatheringState { get; }
Property Value
| Type | Description |
|---|---|
| RTCIceGatheringState |
IceRole
The ICE role the peer is acting in.
Declaration
public IceRolesEnum IceRole { get; set; }
Property Value
| Type | Description |
|---|---|
| IceRolesEnum |
IsDtlsNegotiationComplete
Declaration
public bool IsDtlsNegotiationComplete { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
localDescription
Declaration
public RTCSessionDescription localDescription { get; }
Property Value
| Type | Description |
|---|---|
| RTCSessionDescription |
LocalSdpSessionID
Declaration
public string LocalSdpSessionID { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
pendingLocalDescription
Declaration
public RTCSessionDescription pendingLocalDescription { get; }
Property Value
| Type | Description |
|---|---|
| RTCSessionDescription |
pendingRemoteDescription
Declaration
public RTCSessionDescription pendingRemoteDescription { get; }
Property Value
| Type | Description |
|---|---|
| RTCSessionDescription |
remoteDescription
Declaration
public RTCSessionDescription remoteDescription { get; }
Property Value
| Type | Description |
|---|---|
| RTCSessionDescription |
RemotePeerDtlsFingerprint
The DTLS fingerprint supplied by the remote peer in their SDP. Needs to be checked that the certificate supplied during the DTLS handshake matches.
Declaration
public RTCDtlsFingerprint RemotePeerDtlsFingerprint { get; }
Property Value
| Type | Description |
|---|---|
| RTCDtlsFingerprint |
RequireRenegotiation
Declaration
public override bool RequireRenegotiation { get; protected set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Overrides
| Improve this Doc View Sourcesctp
The SCTP transport over which SCTP data is sent and received.
Declaration
public RTCSctpTransport sctp { get; }
Property Value
| Type | Description |
|---|---|
| RTCSctpTransport |
Remarks
WebRTC API definition: https://www.w3.org/TR/webrtc/#attributes-15
SdpSessionID
Declaration
public string SdpSessionID { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
SessionID
Declaration
public string SessionID { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
signalingState
Declaration
public RTCSignalingState signalingState { get; }
Property Value
| Type | Description |
|---|---|
| RTCSignalingState |
Methods
| Improve this Doc View SourceaddIceCandidate(RTCIceCandidateInit)
Used to add remote ICE candidates to the peer connection's checklist.
Declaration
public void addIceCandidate(RTCIceCandidateInit candidateInit)
Parameters
| Type | Name | Description |
|---|---|---|
| RTCIceCandidateInit | candidateInit | The remote ICE candidate to add. |
addLocalIceCandidate(RTCIceCandidate)
Used to add a local ICE candidate. These are for candidates that the application may want to provide in addition to the ones that will be automatically determined. An example is when a machine is behind a 1:1 NAT and the application wants a host candidate with the public IP address to be included.
Declaration
public void addLocalIceCandidate(RTCIceCandidate candidate)
Parameters
| Type | Name | Description |
|---|---|---|
| RTCIceCandidate | candidate | The ICE candidate to add. |
Examples
var natCandidate = new RTCIceCandidate(RTCIceProtocol.udp, natAddress, natPort, RTCIceCandidateType.host); pc.addLocalIceCandidate(natCandidate);
| Improve this Doc View SourceCancelOnNegotiationNeededTask()
Cancel current Negotiation Event Call to prevent running thread to call OnNegotiationNeeded
Declaration
protected virtual void CancelOnNegotiationNeededTask()
close()
Closes the connection with the default reason.
Declaration
public void close()
Close(String)
Close the session including the underlying RTP session and channels.
Declaration
public override void Close(string reason)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | reason | An optional descriptive reason for the closure. |
Overrides
| Improve this Doc View SourcecreateAnswer(RTCAnswerOptions)
Creates an answer to an SDP offer from a remote peer.
Declaration
public RTCSessionDescriptionInit createAnswer(RTCAnswerOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| RTCAnswerOptions | options | Optional. If supplied the options will be used to apply additional controls over the generated answer SDP. |
Returns
| Type | Description |
|---|---|
| RTCSessionDescriptionInit |
Remarks
As specified in https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-createanswer and https://tools.ietf.org/html/rfc3264#section-6.1.
CreateAnswer(IPAddress)
Convenience overload to suit SIP/VoIP callers. TODO: Consolidate with createAnswer.
Declaration
public override SDP CreateAnswer(IPAddress connectionAddress)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Net.IPAddress | connectionAddress | Not used. |
Returns
| Type | Description |
|---|---|
| SDP | An SDP payload to answer an offer from the remote party. |
Overrides
| Improve this Doc View SourcecreateDataChannel(String, RTCDataChannelInit)
Adds a new data channel to the peer connection.
Declaration
public async Task<RTCDataChannel> createDataChannel(string label, RTCDataChannelInit init = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | label | The label used to identify the data channel. |
| RTCDataChannelInit | init |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<RTCDataChannel> | The data channel created. |
Remarks
WebRTC API definition: https://www.w3.org/TR/webrtc/#methods-11
createOffer(RTCOfferOptions)
Generates the SDP for an offer that can be made to a remote peer.
Declaration
public RTCSessionDescriptionInit createOffer(RTCOfferOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| RTCOfferOptions | options | Optional. If supplied the options will be sued to apply additional controls over the generated offer SDP. |
Returns
| Type | Description |
|---|---|
| RTCSessionDescriptionInit |
Remarks
As specified in https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-createoffer.
CreateOffer(IPAddress)
Convenience overload to suit SIP/VoIP callers. TODO: Consolidate with createAnswer.
Declaration
public override SDP CreateOffer(IPAddress connectionAddress)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Net.IPAddress | connectionAddress | Not used. |
Returns
| Type | Description |
|---|---|
| SDP | An SDP payload to answer an offer from the remote party. |
Overrides
| Improve this Doc View SourceCreateRtpChannel()
Creates a new RTP ICE channel (which manages the UDP socket sending and receiving RTP packets) for use with this session.
Declaration
protected override RTPChannel CreateRtpChannel()
Returns
| Type | Description |
|---|---|
| RTPChannel | A new RTPChannel instance. |
Overrides
| Improve this Doc View SourceDispose()
Close the session if the instance is out of scope.
Declaration
public override void Dispose()
Overrides
| Improve this Doc View SourceDispose(Boolean)
Close the session if the instance is out of scope.
Declaration
protected override void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | disposing |
Overrides
| Improve this Doc View SourcegetConfiguration()
Gets the initial optional configuration settings this peer connection was created with.
Declaration
public RTCConfiguration getConfiguration()
Returns
| Type | Description |
|---|---|
| RTCConfiguration | If available the initial configuration options. |
GetRtpChannel()
Gets the RTP channel being used to send and receive data on this peer connection. Unlike the base RTP session peer connections only ever use a single RTP channel. Audio and video (and RTCP) are all multiplexed on the same channel.
Declaration
public RtpIceChannel GetRtpChannel()
Returns
| Type | Description |
|---|---|
| RtpIceChannel |
restartIce()
Restarts the ICE session gathering and connection checks.
Declaration
public void restartIce()
setConfiguration(RTCConfiguration)
Not implemented. Configuration options cannot currently be changed once the peer connection has been initialised.
Declaration
public void setConfiguration(RTCConfiguration configuration = null)
Parameters
| Type | Name | Description |
|---|---|---|
| RTCConfiguration | configuration |
setLocalDescription(RTCSessionDescriptionInit)
Sets the local SDP.
Declaration
public Task setLocalDescription(RTCSessionDescriptionInit init)
Parameters
| Type | Name | Description |
|---|---|---|
| RTCSessionDescriptionInit | init | Optional. The session description to set as local description. If not supplied then an offer or answer will be created as required. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task |
Remarks
As specified in https://www.w3.org/TR/webrtc/#dom-peerconnection-setlocaldescription.
SetRemoteCredentials(String, String)
For standard use this method should not need to be called. The remote peer's ICE user and password will be set when from the SDP. This method is provided for diagnostics purposes.
Declaration
public void SetRemoteCredentials(string remoteIceUser, string remoteIcePassword)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | remoteIceUser | The remote peer's ICE user value. |
| System.String | remoteIcePassword | The remote peer's ICE password value. |
setRemoteDescription(RTCSessionDescriptionInit)
Updates the session after receiving the remote SDP.
Declaration
public SetDescriptionResultEnum setRemoteDescription(RTCSessionDescriptionInit init)
Parameters
| Type | Name | Description |
|---|---|---|
| RTCSessionDescriptionInit | init | The answer/offer SDP from the remote party. |
Returns
| Type | Description |
|---|---|
| SetDescriptionResultEnum |
SetRemoteDescription(SdpType, SDP)
This set remote description overload is a convenience method for SIP/VoIP callers instead of WebRTC callers. The method signature better matches what the SIP user agent is expecting. TODO: Using two very similar overloads could cause confusion. Possibly consolidate.
Declaration
public override SetDescriptionResultEnum SetRemoteDescription(SdpType sdpType, SDP sessionDescription)
Parameters
| Type | Name | Description |
|---|---|---|
| SdpType | sdpType | Whether the remote SDP is an offer or answer. |
| SDP | sessionDescription | The SDP from the remote party. |
Returns
| Type | Description |
|---|---|
| SetDescriptionResultEnum | The result of attempting to set the remote description. |
Overrides
| Improve this Doc View SourceStartOnNegotiationNeededTask()
These internal function is used to call Renegotiation Event with delay as the user should call addTrack/removeTrack in sequence so we need a small delay to prevent multiple renegotiation calls
Declaration
protected virtual Task StartOnNegotiationNeededTask()
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | Current Executing Task |
Events
| Improve this Doc View Sourceonconnectionstatechange
The state of the peer connection. A state of connected means the ICE checks have succeeded and the DTLS handshake has completed. Once in the connected state it's suitable for media packets can be exchanged.
Declaration
public event Action<RTCPeerConnectionState> onconnectionstatechange
Event Type
| Type | Description |
|---|---|
| System.Action<RTCPeerConnectionState> |
ondatachannel
Fires when a new data channel is created by the remote peer.
Declaration
public event Action<RTCDataChannel> ondatachannel
Event Type
| Type | Description |
|---|---|
| System.Action<RTCDataChannel> |
onicecandidate
A new ICE candidate is available for the Peer Connection.
Declaration
public event Action<RTCIceCandidate> onicecandidate
Event Type
| Type | Description |
|---|---|
| System.Action<RTCIceCandidate> |
onicecandidateerror
A failure occurred when gathering ICE candidates.
Declaration
public event Action<RTCIceCandidate, string> onicecandidateerror
Event Type
| Type | Description |
|---|---|
| System.Action<RTCIceCandidate, System.String> |
oniceconnectionstatechange
This Peer Connection's ICE connection state has changed.
Declaration
public event Action<RTCIceConnectionState> oniceconnectionstatechange
Event Type
| Type | Description |
|---|---|
| System.Action<RTCIceConnectionState> |
onicegatheringstatechange
This Peer Connection's ICE gathering state has changed.
Declaration
public event Action<RTCIceGatheringState> onicegatheringstatechange
Event Type
| Type | Description |
|---|---|
| System.Action<RTCIceGatheringState> |
onnegotiationneeded
Informs the application that session negotiation needs to be done (i.e. a createOffer call followed by setLocalDescription).
Declaration
public event Action onnegotiationneeded
Event Type
| Type | Description |
|---|---|
| System.Action |
onsignalingstatechange
The signaling state has changed. This state change is the result of either setLocalDescription or setRemoteDescription being invoked.
Declaration
public event Action onsignalingstatechange
Event Type
| Type | Description |
|---|---|
| System.Action |