Show / Hide Table of Contents

Class RTCPeerConnection

Represents a WebRTC RTCPeerConnection.

Inheritance
System.Object
RTPSession
RTCPeerConnection
Implements
IMediaSession
System.IDisposable
IRTCPeerConnection
Inherited Members
RTPSession.RTP_MAX_PAYLOAD
RTPSession.SRTP_MAX_PREFIX_LENGTH
RTPSession.DEFAULT_AUDIO_CLOCK_RATE
RTPSession.RTP_EVENT_DEFAULT_SAMPLE_PERIOD_MS
RTPSession.DEFAULT_MEDIA_TYPE
RTPSession.DEFAULT_DTMF_EVENT_PAYLOAD_ID
RTPSession.RTP_MEDIA_PROFILE
RTPSession.RTP_SECUREMEDIA_PROFILE
RTPSession.SDP_SESSIONID_LENGTH
RTPSession.DTMF_EVENT_DURATION
RTPSession.DTMF_EVENT_PAYLOAD_ID
RTPSession.RTCP_RR_NOSTREAM_SSRC
RTPSession.logger
RTPSession.rtpSessionConfig
RTPSession.m_primaryStream
RTPSession.MultiplexRtpChannel
RTPSession.audioRemoteSDPSsrcAttributes
RTPSession.videoRemoteSDPSsrcAttributes
RTPSession.PrimaryStream
RTPSession.AudioStream
RTPSession.VideoStream
RTPSession.AudioLocalTrack
RTPSession.AudioRemoteTrack
RTPSession.AudioRtcpSession
RTPSession.AudioDestinationEndPoint
RTPSession.AudioControlDestinationEndPoint
RTPSession.VideoLocalTrack
RTPSession.VideoRemoteTrack
RTPSession.VideoRtcpSession
RTPSession.VideoDestinationEndPoint
RTPSession.VideoControlDestinationEndPoint
RTPSession.AudioStreamList
RTPSession.VideoStreamList
RTPSession.RemoteDescription
RTPSession.IsSecureContextReady()
RTPSession.SrtpCryptoSuites
RTPSession.MaxReconstructedVideoFrameSize
RTPSession.IsClosed
RTPSession.IsStarted
RTPSession.HasAudio
RTPSession.HasVideo
RTPSession.AcceptRtpFromAny
RTPSession.RtpBindAddress
RTPSession.OnAudioFormatsNegotiated
RTPSession.OnAudioFormatsNegotiatedByIndex
RTPSession.OnVideoFormatsNegotiated
RTPSession.OnVideoFormatsNegotiatedByIndex
RTPSession.OnVideoFrameReceived
RTPSession.OnVideoFrameReceivedByIndex
RTPSession.OnRtpPacketReceived
RTPSession.OnRtpPacketReceivedByIndex
RTPSession.OnRtpHeaderReceived
RTPSession.OnRtpHeaderReceivedByIndex
RTPSession.OnRtpEvent
RTPSession.OnRtpEventByIndex
RTPSession.OnRtpClosed
RTPSession.OnRtcpBye
RTPSession.OnTimeout
RTPSession.OnTimeoutByIndex
RTPSession.OnReceiveReport
RTPSession.OnReceiveReportByIndex
RTPSession.OnSendReport
RTPSession.OnSendReportByIndex
RTPSession.OnStarted
RTPSession.OnClosed
RTPSession.ResetRemoteSDPSsrcAttributes()
RTPSession.AddRemoteSDPSsrcAttributes(SDPMediaTypesEnum, List<SDPSsrcAttribute>)
RTPSession.LogRemoteSDPSsrcAttributes()
RTPSession.GetOrCreateAudioStream(Int32)
RTPSession.GetOrCreateVideoStream(Int32)
RTPSession.SetMediaStreamStatus(SDPMediaTypesEnum, MediaStreamStatusEnum)
RTPSession.addSingleTrack(Boolean)
RTPSession.addTrack(MediaStreamTrack)
RTPSession.removeTrack(MediaStreamTrack)
RTPSession.SetGlobalDestination(IPEndPoint, IPEndPoint)
RTPSession.SetGlobalSecurityContext(ProtectRtpPacket, ProtectRtpPacket, ProtectRtpPacket, ProtectRtpPacket)
RTPSession.GetNextAudioStreamByLocalTrack()
RTPSession.GetNextVideoStreamByLocalTrack()
RTPSession.GetMediaStreams()
RTPSession.Start()
RTPSession.SendAudio(UInt32, Byte[])
RTPSession.SendVideo(UInt32, Byte[])
RTPSession.SendDtmf(Byte, CancellationToken)
RTPSession.SendDtmfEvent(RTPEvent, CancellationToken, Int32, Int32)
RTPSession.OnReceive(Int32, IPEndPoint, Byte[])
RTPSession.SendRtpRaw(SDPMediaTypesEnum, Byte[], UInt32, Int32, Int32, UInt16)
RTPSession.SendRtpRaw(SDPMediaTypesEnum, Byte[], UInt32, Int32, Int32)
RTPSession.SendRtcpRaw(SDPMediaTypesEnum, Byte[])
RTPSession.SetDestination(SDPMediaTypesEnum, IPEndPoint, IPEndPoint)
RTPSession.SendRtcpFeedback(SDPMediaTypesEnum, RTCPFeedback)
RTPSession.SendRtcpReport(SDPMediaTypesEnum, RTCPCompoundPacket)
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
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 Source

RTCPeerConnection()

Constructor to create a new RTC peer connection instance.

Declaration
public RTCPeerConnection()
| Improve this Doc View Source

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
| Improve this Doc View Source

_renegotiationLock

Declaration
protected object _renegotiationLock
Field Value
Type Description
System.Object
| Improve this Doc View Source

_requireRenegotiation

Declaration
protected volatile bool _requireRenegotiation
Field Value
Type Description
System.Boolean

Properties

| Improve this Doc View Source

canTrickleIceCandidates

Declaration
public bool canTrickleIceCandidates { get; }
Property Value
Type Description
System.Boolean
| Improve this Doc View Source

connectionState

Declaration
public RTCPeerConnectionState connectionState { get; }
Property Value
Type Description
RTCPeerConnectionState
| Improve this Doc View Source

currentLocalDescription

Declaration
public RTCSessionDescription currentLocalDescription { get; }
Property Value
Type Description
RTCSessionDescription
| Improve this Doc View Source

currentRemoteDescription

Declaration
public RTCSessionDescription currentRemoteDescription { get; }
Property Value
Type Description
RTCSessionDescription
| Improve this Doc View Source

DataChannels

Declaration
public IReadOnlyCollection<RTCDataChannel> DataChannels { get; }
Property Value
Type Description
System.Collections.Generic.IReadOnlyCollection<RTCDataChannel>
| Improve this Doc View Source

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
| Improve this Doc View Source

DtlsCertificateSignatureAlgorithm

Declaration
public string DtlsCertificateSignatureAlgorithm { get; }
Property Value
Type Description
System.String
| Improve this Doc View Source

iceConnectionState

Declaration
public RTCIceConnectionState iceConnectionState { get; }
Property Value
Type Description
RTCIceConnectionState
| Improve this Doc View Source

iceGatheringState

Declaration
public RTCIceGatheringState iceGatheringState { get; }
Property Value
Type Description
RTCIceGatheringState
| Improve this Doc View Source

IceRole

The ICE role the peer is acting in.

Declaration
public IceRolesEnum IceRole { get; set; }
Property Value
Type Description
IceRolesEnum
| Improve this Doc View Source

IsDtlsNegotiationComplete

Declaration
public bool IsDtlsNegotiationComplete { get; }
Property Value
Type Description
System.Boolean
| Improve this Doc View Source

localDescription

Declaration
public RTCSessionDescription localDescription { get; }
Property Value
Type Description
RTCSessionDescription
| Improve this Doc View Source

LocalSdpSessionID

Declaration
public string LocalSdpSessionID { get; }
Property Value
Type Description
System.String
| Improve this Doc View Source

pendingLocalDescription

Declaration
public RTCSessionDescription pendingLocalDescription { get; }
Property Value
Type Description
RTCSessionDescription
| Improve this Doc View Source

pendingRemoteDescription

Declaration
public RTCSessionDescription pendingRemoteDescription { get; }
Property Value
Type Description
RTCSessionDescription
| Improve this Doc View Source

remoteDescription

Declaration
public RTCSessionDescription remoteDescription { get; }
Property Value
Type Description
RTCSessionDescription
| Improve this Doc View Source

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
| Improve this Doc View Source

RequireRenegotiation

Declaration
public override bool RequireRenegotiation { get; protected set; }
Property Value
Type Description
System.Boolean
Overrides
RTPSession.RequireRenegotiation
| Improve this Doc View Source

sctp

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

| Improve this Doc View Source

SdpSessionID

Declaration
public string SdpSessionID { get; }
Property Value
Type Description
System.String
| Improve this Doc View Source

SessionID

Declaration
public string SessionID { get; }
Property Value
Type Description
System.String
| Improve this Doc View Source

signalingState

Declaration
public RTCSignalingState signalingState { get; }
Property Value
Type Description
RTCSignalingState

Methods

| Improve this Doc View Source

addIceCandidate(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.

| Improve this Doc View Source

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 Source

CancelOnNegotiationNeededTask()

Cancel current Negotiation Event Call to prevent running thread to call OnNegotiationNeeded

Declaration
protected virtual void CancelOnNegotiationNeededTask()
| Improve this Doc View Source

close()

Closes the connection with the default reason.

Declaration
public void close()
| Improve this Doc View Source

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
RTPSession.Close(String)
| Improve this Doc View Source

createAnswer(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.

| Improve this Doc View Source

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
RTPSession.CreateAnswer(IPAddress)
| Improve this Doc View Source

createDataChannel(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

| Improve this Doc View Source

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.

| Improve this Doc View Source

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
RTPSession.CreateOffer(IPAddress)
| Improve this Doc View Source

CreateRtpChannel()

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
RTPSession.CreateRtpChannel()
| Improve this Doc View Source

Dispose()

Close the session if the instance is out of scope.

Declaration
public override void Dispose()
Overrides
RTPSession.Dispose()
| Improve this Doc View Source

Dispose(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
RTPSession.Dispose(Boolean)
| Improve this Doc View Source

getConfiguration()

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.

| Improve this Doc View Source

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
| Improve this Doc View Source

restartIce()

Restarts the ICE session gathering and connection checks.

Declaration
public void restartIce()
| Improve this Doc View Source

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
| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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
| Improve this Doc View Source

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
RTPSession.SetRemoteDescription(SdpType, SDP)
| Improve this Doc View Source

StartOnNegotiationNeededTask()

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 Source

onconnectionstatechange

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>
| Improve this Doc View Source

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>
| Improve this Doc View Source

onicecandidate

A new ICE candidate is available for the Peer Connection.

Declaration
public event Action<RTCIceCandidate> onicecandidate
Event Type
Type Description
System.Action<RTCIceCandidate>
| Improve this Doc View Source

onicecandidateerror

A failure occurred when gathering ICE candidates.

Declaration
public event Action<RTCIceCandidate, string> onicecandidateerror
Event Type
Type Description
System.Action<RTCIceCandidate, System.String>
| Improve this Doc View Source

oniceconnectionstatechange

This Peer Connection's ICE connection state has changed.

Declaration
public event Action<RTCIceConnectionState> oniceconnectionstatechange
Event Type
Type Description
System.Action<RTCIceConnectionState>
| Improve this Doc View Source

onicegatheringstatechange

This Peer Connection's ICE gathering state has changed.

Declaration
public event Action<RTCIceGatheringState> onicegatheringstatechange
Event Type
Type Description
System.Action<RTCIceGatheringState>
| Improve this Doc View Source

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
| Improve this Doc View Source

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

Implements

IMediaSession
System.IDisposable
IRTCPeerConnection

Extension Methods

JSONWriter.ToJson(Object)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX