Class RTCPeerConnection | WebRTC | 2.1.3-preview
docs.unity3d.com
    Show / Hide Table of Contents

    Class RTCPeerConnection

    Represents a WebRTC connection between the local peer and remote peer.

    Inheritance
    Object
    RTCPeerConnection
    Namespace: Unity.WebRTC
    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)

    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
    Type Name Description
    RTCConfiguration configuration
    See Also
    RTCPeerConnection()

    Properties

    ConnectionState

    The readonly property of the RTCPeerConnection indicates the current state of the peer connection by returning one of the RTCPeerConnectionState enum.

    Declaration
    public RTCPeerConnectionState ConnectionState { get; }
    Property Value
    Type Description
    RTCPeerConnectionState
    Examples
    var peerConnection = new RTCPeerConnection(configuration);
    var connectionState = peerConnection.ConnectionState;
    See Also
    IceConnectionState

    CurrentLocalDescription

    Declaration
    public RTCSessionDescription CurrentLocalDescription { get; }
    Property Value
    Type Description
    RTCSessionDescription

    CurrentRemoteDescription

    Declaration
    public RTCSessionDescription CurrentRemoteDescription { get; }
    Property Value
    Type Description
    RTCSessionDescription

    IceConnectionState

    The readonly property of the RTCPeerConnection indicates the current state of the peer connection by returning one of the RTCIceConnectionState enum.

    Declaration
    public RTCIceConnectionState IceConnectionState { get; }
    Property Value
    Type Description
    RTCIceConnectionState
    Examples
    var peerConnection = new RTCPeerConnection(configuration);
    var iceConnectionState = peerConnection.IceConnectionState;
    See Also
    ConnectionState

    LocalDescription

    Declaration
    public RTCSessionDescription LocalDescription { get; }
    Property Value
    Type Description
    RTCSessionDescription

    OnDataChannel

    Declaration
    public DelegateOnDataChannel OnDataChannel { set; }
    Property Value
    Type Description
    DelegateOnDataChannel

    OnIceCandidate

    Declaration
    public DelegateOnIceCandidate OnIceCandidate { set; }
    Property Value
    Type Description
    DelegateOnIceCandidate
    See Also
    RTCIceCandidate

    OnIceConnectionChange

    This property is delegate to be called when the IceConnectionState is changed.

    Declaration
    public DelegateOnIceConnectionChange OnIceConnectionChange { set; }
    Property Value
    Type Description
    DelegateOnIceConnectionChange

    A delegate containing IceConnectionState.

    Examples
    peerConnection.OnIceConnectionChange = iceConnectionState =>
    {
        ...
    };
    See Also
    IceConnectionState

    OnNegotiationNeeded

    Declaration
    public DelegateOnNegotiationNeeded OnNegotiationNeeded { set; }
    Property Value
    Type Description
    DelegateOnNegotiationNeeded

    OnTrack

    Declaration
    public DelegateOnTrack OnTrack { set; }
    Property Value
    Type Description
    DelegateOnTrack

    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

    SignalingState

    The readonly property of the RTCPeerConnection indicates the current state of the peer connection by returning one of the RTCSignalingState enum.

    Declaration
    public RTCSignalingState SignalingState { get; }
    Property Value
    Type Description
    RTCSignalingState
    Examples
    var peerConnection = new RTCPeerConnection(configuration);
    var signalingState = peerConnection.SignalingState;
    See Also
    ConnectionState

    Methods

    AddIceCandidate(ref RTCIceCandidate)

    Declaration
    public void AddIceCandidate(ref RTCIceCandidate candidate)
    Parameters
    Type Name Description
    RTCIceCandidate candidate

    AddTrack(MediaStreamTrack, MediaStream)

    Declaration
    public RTCRtpSender AddTrack(MediaStreamTrack track, MediaStream stream = null)
    Parameters
    Type Name Description
    MediaStreamTrack track
    MediaStream stream
    Returns
    Type Description
    RTCRtpSender
    See Also
    RemoveTrack(RTCRtpSender)

    AddTransceiver(MediaStreamTrack)

    Declaration
    public RTCRtpTransceiver AddTransceiver(MediaStreamTrack track)
    Parameters
    Type Name Description
    MediaStreamTrack track
    Returns
    Type Description
    RTCRtpTransceiver

    Close()

    Declaration
    public void Close()
    See Also
    Dispose()

    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
    Type Name Description
    RTCAnswerOptions options
    Returns
    Type Description
    RTCSessionDescriptionAsyncOperation

    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
    Type Description
    RTCDataChannel

    A new data channel.

    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
    Type Description
    RTCSessionDescriptionAsyncOperation
    See Also
    CreateAnswer(ref RTCAnswerOptions)

    Dispose()

    Declaration
    public void Dispose()

    Finalize()

    Declaration
    protected void Finalize()

    GetConfiguration()

    Returns an object which indicates the current configuration of the RTCPeerConnection.

    Declaration
    public RTCConfiguration GetConfiguration()
    Returns
    Type Description
    RTCConfiguration

    An object describing the RTCPeerConnection's current configuration.

    Examples
    var configuration = myPeerConnection.GetConfiguration();
    if(configuration.urls.length == 0)
    {
        configuration.urls = new[] {"stun:stun.l.google.com:19302"};
    }
    myPeerConnection.SetConfiguration(configuration);
    See Also
    SetConfiguration(ref RTCConfiguration)

    GetReceivers()

    Returns array of objects each of which represents one RTP receiver.

    Declaration
    public IEnumerable<RTCRtpReceiver> GetReceivers()
    Returns
    Type Description
    IEnumerable<RTCRtpReceiver>

    Array of the senders

    Examples
    var senders = peerConnection.GetReceivers();
    See Also
    GetSenders()
    GetTransceivers()

    GetSenders()

    Returns array of objects each of which represents one RTP sender.

    Declaration
    public IEnumerable<RTCRtpSender> GetSenders()
    Returns
    Type Description
    IEnumerable<RTCRtpSender>

    Array of the receivers

    Examples
    var senders = peerConnection.GetSenders();
    See Also
    GetReceivers()
    GetTransceivers()

    GetStats()

    Returns an AsyncOperation which resolves with data providing statistics.

    Declaration
    public RTCStatsReportAsyncOperation GetStats()
    Returns
    Type Description
    RTCStatsReportAsyncOperation

    An AsyncOperation which resolves with an RTCStatsReport object providing connection statistics.

    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
    RTCStatsReport

    GetTransceivers()

    Returns array of objects each of which represents one RTP transceiver.

    Declaration
    public IEnumerable<RTCRtpTransceiver> GetTransceivers()
    Returns
    Type Description
    IEnumerable<RTCRtpTransceiver>

    Array of the transceivers

    Examples
    var transceivers = peerConnection.GetTransceivers();
    See Also
    GetSenders()
    GetReceivers()

    RemoveTrack(RTCRtpSender)

    Declaration
    public void RemoveTrack(RTCRtpSender sender)
    Parameters
    Type Name Description
    RTCRtpSender sender
    See Also
    AddTrack(MediaStreamTrack, MediaStream)

    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
    Type Description
    RTCErrorType

    Error code.

    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
    GetConfiguration()

    SetLocalDescription(ref RTCSessionDescription)

    Declaration
    public RTCSetSessionDescriptionAsyncOperation SetLocalDescription(ref RTCSessionDescription desc)
    Parameters
    Type Name Description
    RTCSessionDescription desc
    Returns
    Type Description
    RTCSetSessionDescriptionAsyncOperation
    See Also
    LocalDescription

    SetRemoteDescription(ref RTCSessionDescription)

    Declaration
    public RTCSetSessionDescriptionAsyncOperation SetRemoteDescription(ref RTCSessionDescription desc)
    Parameters
    Type Name Description
    RTCSessionDescription desc
    Returns
    Type Description
    RTCSetSessionDescriptionAsyncOperation
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023