Class RTCPeerConnection
Represents a WebRTC connection between the local peer and remote peer.
Inheritance
RTCPeerConnection
Syntax
public class RTCPeerConnection : IDisposable
Constructors
RTCPeerConnection()
This constructor creates an instance of peer connection with a default configuration.
Declaration
public RTCPeerConnection()
See Also
RTCPeerConnection(ref RTCConfiguration)
This constructor creates an instance of peer connection with a configuration provided by user.
An RTCConfiguration object providing options to configure the new connection.
Declaration
public RTCPeerConnection(ref RTCConfiguration configuration)
Parameters
See Also
Properties
ConnectionState
Declaration
public RTCPeerConnectionState ConnectionState { get; }
Property Value
Examples
var peerConnection = new RTCPeerConnection(configuration);
var connectionState = peerConnection.ConnectionState;
See Also
CurrentLocalDescription
Declaration
public RTCSessionDescription CurrentLocalDescription { get; }
Property Value
CurrentRemoteDescription
Declaration
public RTCSessionDescription CurrentRemoteDescription { get; }
Property Value
IceConnectionState
Declaration
public RTCIceConnectionState IceConnectionState { get; }
Property Value
Examples
var peerConnection = new RTCPeerConnection(configuration);
var iceConnectionState = peerConnection.IceConnectionState;
See Also
LocalDescription
Declaration
public RTCSessionDescription LocalDescription { get; }
Property Value
OnDataChannel
Declaration
public DelegateOnDataChannel OnDataChannel { set; }
Property Value
OnIceCandidate
Declaration
public DelegateOnIceCandidate OnIceCandidate { set; }
Property Value
See Also
OnIceConnectionChange
Declaration
public DelegateOnIceConnectionChange OnIceConnectionChange { set; }
Property Value
Examples
peerConnection.OnIceConnectionChange = iceConnectionState =>
{
...
};
See Also
OnNegotiationNeeded
Declaration
public DelegateOnNegotiationNeeded OnNegotiationNeeded { set; }
Property Value
OnTrack
Declaration
public DelegateOnTrack OnTrack { set; }
Property Value
PendingLocalDescription
Declaration
public RTCSessionDescription PendingLocalDescription { get; }
Property Value
PendingRemoteDescription
Declaration
public RTCSessionDescription PendingRemoteDescription { get; }
Property Value
RemoteDescription
Declaration
public RTCSessionDescription RemoteDescription { get; }
Property Value
SignalingState
Declaration
public RTCSignalingState SignalingState { get; }
Property Value
Examples
var peerConnection = new RTCPeerConnection(configuration);
var signalingState = peerConnection.SignalingState;
See Also
Methods
AddIceCandidate(ref RTCIceCandidate)
Declaration
public void AddIceCandidate(ref RTCIceCandidate candidate)
Parameters
Declaration
public RTCRtpSender AddTrack(MediaStreamTrack track, MediaStream stream = null)
Parameters
Returns
Declaration
public RTCRtpTransceiver AddTransceiver(MediaStreamTrack track)
Parameters
Returns
AddTransceiver(TrackKind)
Declaration
public RTCRtpTransceiver AddTransceiver(TrackKind kind)
Parameters
Returns
Close()
Declaration
See Also
CreateAnswer(ref RTCAnswerOptions)
Create an SDP (Session Description Protocol) answer to start a new connection
to a remote peer.
Declaration
public RTCSessionDescriptionAsyncOperation CreateAnswer(ref RTCAnswerOptions options)
Parameters
Returns
CreateDataChannel(String, ref RTCDataChannelInit)
Creates a new data channel related the remote peer.
Declaration
public RTCDataChannel CreateDataChannel(string label, ref RTCDataChannelInit options)
Parameters
Type |
Name |
Description |
String |
label |
A string for the data channel.
This string may be checked by Label.
|
RTCDataChannelInit |
options |
A struct provides configuration options for the data channel.
|
Returns
CreateOffer(ref RTCOfferOptions)
Create an SDP (Session Description Protocol) offer to start a new connection
to a remote peer.
Declaration
public RTCSessionDescriptionAsyncOperation CreateOffer(ref RTCOfferOptions options)
Parameters
Type |
Name |
Description |
RTCOfferOptions |
options |
A parameter to request for the offer.
|
Returns
See Also
Dispose()
Declaration
Finalize()
Declaration
protected void Finalize()
GetConfiguration()
Returns an object which indicates the current configuration
of the RTCPeerConnection.
Declaration
public RTCConfiguration GetConfiguration()
Returns
Examples
var configuration = myPeerConnection.GetConfiguration();
if(configuration.urls.length == 0)
{
configuration.urls = new[] {"stun:stun.l.google.com:19302"};
}
myPeerConnection.SetConfiguration(configuration);
See Also
GetReceivers()
Returns array of objects each of which represents one RTP receiver.
Declaration
public IEnumerable<RTCRtpReceiver> GetReceivers()
Returns
Examples
var senders = peerConnection.GetReceivers();
See Also
GetSenders()
Returns array of objects each of which represents one RTP sender.
Declaration
public IEnumerable<RTCRtpSender> GetSenders()
Returns
Examples
var senders = peerConnection.GetSenders();
See Also
GetStats()
Returns an AsyncOperation which resolves with data providing statistics.
Declaration
public RTCStatsReportAsyncOperation GetStats()
Returns
Examples
var operation = peerConnection.GetStats();
yield return operation;
if (!operation.IsError)
{
var report = operation.Value;
foreach (var stat in report.Stats.Values)
{
Debug.Log(stat.Type.ToString());
}
}
See Also
GetTransceivers()
Returns array of objects each of which represents one RTP transceiver.
Declaration
public IEnumerable<RTCRtpTransceiver> GetTransceivers()
Returns
Examples
var transceivers = peerConnection.GetTransceivers();
See Also
RemoveTrack(RTCRtpSender)
Declaration
public void RemoveTrack(RTCRtpSender sender)
Parameters
See Also
SetConfiguration(ref RTCConfiguration)
This method sets the current configuration of the RTCPeerConnection
This lets you change the ICE servers used by the connection
and which transport policies to use.
Declaration
public RTCErrorType SetConfiguration(ref RTCConfiguration configuration)
Parameters
Type |
Name |
Description |
RTCConfiguration |
configuration |
The changes are not additive; instead,
the new values completely replace the existing ones.
|
Returns
Examples
var configuration = new RTCConfiguration
{
iceServers = new[]
{
new RTCIceServer
{
urls = new[] {"stun:stun.l.google.com:19302"},
username = "",
credential = "",
credentialType = RTCIceCredentialType.Password
}
}
};
var error = myPeerConnection.SetConfiguration(ref configuration);
if(error == RTCErrorType.None)
{
...
}
See Also
SetLocalDescription(ref RTCSessionDescription)
This method changes the session description
of the local connection to negotiate with other connections.
Declaration
public RTCSetSessionDescriptionAsyncOperation SetLocalDescription(ref RTCSessionDescription desc)
Parameters
Returns
Exceptions
Type |
Condition |
ArgumentException |
Thrown when an argument has an invalid value.
For example, when passed the sdp which is null or empty.
|
RTCErrorException |
Thrown when an argument has an invalid value.
For example, when passed the sdp which is not be able to parse.
|
See Also
SetRemoteDescription(ref RTCSessionDescription)
This method changes the session description
of the remote connection to negotiate with local connections.
Declaration
public RTCSetSessionDescriptionAsyncOperation SetRemoteDescription(ref RTCSessionDescription desc)
Parameters
Returns
Exceptions
Type |
Condition |
ArgumentException |
Thrown when an argument has an invalid value.
For example, when passed the sdp which is null or empty.
|
RTCErrorException |
Thrown when an argument has an invalid value.
For example, when passed the sdp which is not be able to parse.
|
See Also