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
GatheringState
Declaration
public RTCIceGatheringState GatheringState { 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
OnConnectionStateChange
Declaration
public DelegateOnConnectionStateChange OnConnectionStateChange { get; set; }
Property Value
OnDataChannel
Declaration
public DelegateOnDataChannel OnDataChannel { get; set; }
Property Value
See Also
OnIceCandidate
Declaration
public DelegateOnIceCandidate OnIceCandidate { get; set; }
Property Value
See Also
OnIceConnectionChange
Declaration
public DelegateOnIceConnectionChange OnIceConnectionChange { get; set; }
Property Value
Examples
peerConnection.OnIceConnectionChange = iceConnectionState =>
{
...
};
See Also
OnIceGatheringStateChange
Declaration
public DelegateOnIceGatheringStateChange OnIceGatheringStateChange { get; set; }
Property Value
See Also
OnNegotiationNeeded
Declaration
public DelegateOnNegotiationNeeded OnNegotiationNeeded { get; set; }
Property Value
OnTrack
Declaration
public DelegateOnTrack OnTrack { get; set; }
Property Value
See Also
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(RTCIceCandidate)
Declaration
public bool AddIceCandidate(RTCIceCandidate candidate)
Parameters
Returns
Declaration
public RTCRtpSender AddTrack(MediaStreamTrack track, MediaStream stream = null)
Parameters
Returns
Declaration
public RTCRtpTransceiver AddTransceiver(MediaStreamTrack track, RTCRtpTransceiverInit init = null)
Parameters
Returns
AddTransceiver(TrackKind, RTCRtpTransceiverInit)
Declaration
public RTCRtpTransceiver AddTransceiver(TrackKind kind, RTCRtpTransceiverInit init = null)
Parameters
Returns
Close()
Declaration
See Also
CreateAnswer()
Declaration
public RTCSessionDescriptionAsyncOperation CreateAnswer()
Returns
CreateAnswer(ref RTCOfferAnswerOptions)
Create an SDP (Session Description Protocol) answer to start a new connection
to a remote peer.
Declaration
public RTCSessionDescriptionAsyncOperation CreateAnswer(ref RTCOfferAnswerOptions options)
Parameters
Returns
CreateDataChannel(String, RTCDataChannelInit)
Creates a new data channel related the remote peer.
Declaration
public RTCDataChannel CreateDataChannel(string label, RTCDataChannelInit options = null)
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()
Declaration
public RTCSessionDescriptionAsyncOperation CreateOffer()
Returns
CreateOffer(ref RTCOfferAnswerOptions)
Create an SDP (Session Description Protocol) offer to start a new connection
to a remote peer.
Declaration
public RTCSessionDescriptionAsyncOperation CreateOffer(ref RTCOfferAnswerOptions options)
Parameters
Returns
See Also
Dispose()
Declaration
Implements
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
// Already instantiated peerConnection as RTCPeerConnection.
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 RTCErrorType RemoveTrack(RTCRtpSender sender)
Parameters
Returns
See Also
RestartIce()
Declaration
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()
Declaration
public RTCSetSessionDescriptionAsyncOperation SetLocalDescription()
Returns
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