Skip to main content
Version: 20 Mar 2024

PeerConnection

Class that represents a connection used by the MLWebRTC API.

Public Fields

IceCandidate

Gets the ice candidate chosen by the connection.


public MLWebRTC.IceCandidate IceCandidate { get; set; }

TypeDescription
MLWebRTC.IceCandidateClass that represents an ice candidate used by the MLWebRTC API.

IceServers

Gets the ice servers used for the connection.


public MLWebRTC.IceServer [] IceServers { get; set; }

TypeDescription
MLWebRTC.IceServer []Class that represents an ice server used by the MLWebRTC API.

Public Methods

MLResult AddLocalTrack

Adds a local track to the connection.

public MLResult AddLocalTrack(
MLWebRTC.MediaStream.Track trackToAdd
)

Parameters

TypeNameDescription
MLWebRTC.MediaStream.TracktrackToAddTrack to add to the connection.

Returns: MLResult.Result will be MLResult.Code.Ok if destroying all handles was successful. MLResult.Result will be MLResult.Code.WebRTCResultInstanceNotCreated if MLWebRTC instance was not created. MLResult.Result will be MLResult.Code.WebRTCResultMismatchingHandle if an incorrect handle was sent.


MLResult AddRemoteIceCandidate

Adds an ice candidate to the connection.

public MLResult AddRemoteIceCandidate(
MLWebRTC.IceCandidate iceCandidate
)

Parameters

TypeNameDescription
MLWebRTC.IceCandidateiceCandidateThe ice candidate to add.

Returns: MLResult.Result will be MLResult.Code.Ok if destroying all handles was successful. MLResult.Result will be MLResult.Code.WebRTCResultInstanceNotCreated if MLWebRTC instance was not created. MLResult.Result will be MLResult.Code.WebRTCResultMismatchingHandle if an incorrect handle was sent. MLResult.Result will be MLResult.Code.InvalidParam if an invalid parameter was passed.


bool ContainsTrack

public bool ContainsTrack(
MediaStream.Track track
)

Parameters

TypeNameDescription
MediaStream.TracktrackStruct that represents a media stream track object.

MLResult CreateOffer

Creates the offer for the connection.

public MLResult CreateOffer()

Returns: MLResult.Result will be MLResult.Code.Ok if destroying all handles was successful. MLResult.Result will be MLResult.Code.WebRTCResultInstanceNotCreated if MLWebRTC instance was not created. MLResult.Result will be MLResult.Code.WebRTCResultMismatchingHandle if an incorrect handle was sent.


PeerConnection CreateRemote

Creates an initialized PeerConnection object.

public static PeerConnection CreateRemote(
MLWebRTC.IceServer [] iceServers,
out MLResult result
)

Parameters

TypeNameDescription
MLWebRTC.IceServer []iceServersThe ice servers to create the connection with.
out MLResultresultThe MLResult object of the inner platform call(s).

Returns: An initialized PeerConnection object.


PeerConnection CreateRemote

Creates an initialized PeerConnection object with a forward proxy configuration.

public static PeerConnection CreateRemote(
MLWebRTC.IceServer [] iceServers,
MLWebRTC.ProxyConfig proxyConfig,
out MLResult result
)

Parameters

TypeNameDescription
MLWebRTC.IceServer []iceServersThe ice servers to create the connection with.
MLWebRTC.ProxyConfigproxyConfigConfiguration for the forward proxy.
out MLResultresultThe MLResult object of the inner platform call(s).

Returns: An initialized PeerConnection object.


MLResult Destroy

Destroys the connection.

public MLResult Destroy()

Returns: MLResult.Result will be MLResult.Code.Ok if destroying all handles was successful. MLResult.Result will be MLResult.Code.WebRTCResultInstanceNotCreated if MLWebRTC instance was not created. MLResult.Result will be MLResult.Code.WebRTCResultMismatchingHandle if an incorrect handle was sent.


MLResult HasFailed

Gets if the connection has failed or not.

public MLResult HasFailed(
out bool failed
)

Parameters

TypeNameDescription
out boolfailedTrue if connection has failed.

Returns: MLResult.Result will be MLResult.Code.Ok if destroying all handles was successful. MLResult.Result will be MLResult.Code.WebRTCResultInstanceNotCreated if MLWebRTC instance was not created. MLResult.Result will be MLResult.Code.WebRTCResultMismatchingHandle if an incorrect handle was sent. MLResult.Result will be MLResult.Code.InvalidParam if an invalid parameter was passed.


MLResult IsConnected

Gets if the connection is currently connected or not.

public MLResult IsConnected(
out bool connected
)

Parameters

TypeNameDescription
out boolconnectedTrue if connected.

Returns: MLResult.Result will be MLResult.Code.Ok if destroying all handles was successful. MLResult.Result will be MLResult.Code.WebRTCResultInstanceNotCreated if MLWebRTC instance was not created. MLResult.Result will be MLResult.Code.WebRTCResultMismatchingHandle if an incorrect handle was sent. MLResult.Result will be MLResult.Code.InvalidParam if an invalid parameter was passed.


delegate void OnConnectedDelegate

Delegate describing the callback necessary to monitor if a connection has been made.

public delegate void OnConnectedDelegate(
MLWebRTC.PeerConnection connection
)

Parameters

TypeNameDescription
MLWebRTC.PeerConnectionconnectionThe connection the event was invoked on.

delegate void OnDataChannelReceivedDelegate

A delegate that describes the requirements of the OnDataChannelReceivedDelegate callback.

public delegate void OnDataChannelReceivedDelegate(
MLWebRTC.PeerConnection connection,
MLWebRTC.DataChannel dataChannel
)

Parameters

TypeNameDescription
MLWebRTC.PeerConnectionconnectionThe connection the event was invoked on.
MLWebRTC.DataChanneldataChannelThe data channel that was added to the connection.

delegate void OnDisconnectedDelegate

Delegate describing the callback necessary to monitor if a disconnection has been made.

public delegate void OnDisconnectedDelegate(
MLWebRTC.PeerConnection connection
)

Parameters

TypeNameDescription
MLWebRTC.PeerConnectionconnectionThe connection the event was invoked on.

delegate void OnErrorDelegate

Delegate describing the callback necessary to monitor errors.

public delegate void OnErrorDelegate(
MLWebRTC.PeerConnection connection,
string message
)

Parameters

TypeNameDescription
MLWebRTC.PeerConnectionconnectionThe connection the event was invoked on.
stringmessageThe error message.

delegate void OnIceGatheringCompletedDelegate

Delegate describing the callback necessary to notify that all ICEs have been gathered.

public delegate void OnIceGatheringCompletedDelegate(
MLWebRTC.PeerConnection connection
)

Parameters

TypeNameDescription
MLWebRTC.PeerConnectionconnectionThe connection the event was invoked on.

delegate void OnLocalAnswerCreatedDelegate

Delegate describing the callback necessary to monitor when an answer to an offer is sent.

public delegate void OnLocalAnswerCreatedDelegate(
MLWebRTC.PeerConnection connection,
string sendAnswer
)

Parameters

TypeNameDescription
MLWebRTC.PeerConnectionconnectionThe connection the event was invoked on.
stringsendAnswerThe json of the answer sent.

delegate void OnLocalIceCandidateFoundDelegate

Delegate describing the callback necessary to monitor when an ice candidate is sent.

public delegate void OnLocalIceCandidateFoundDelegate(
MLWebRTC.PeerConnection connection,
MLWebRTC.IceCandidate iceCandidate
)

Parameters

TypeNameDescription
MLWebRTC.PeerConnectionconnectionThe connection the event was invoked on.
MLWebRTC.IceCandidateiceCandidateThe ice candidate that was sent.

delegate void OnLocalOfferCreatedDelegate

Delegate describing the callback necessary to monitor when an offer is sent.

public delegate void OnLocalOfferCreatedDelegate(
MLWebRTC.PeerConnection connection,
string sdpSend
)

Parameters

TypeNameDescription
MLWebRTC.PeerConnectionconnectionThe connection the event was invoked on.
stringsdpSendThe json of the offer sent.

delegate void OnTrackAddedMultipleStreamsDelegate

A delegate that describes the requirements of the OnTrackAddedDelegate callback.

public delegate void OnTrackAddedMultipleStreamsDelegate(
List< MLWebRTC.MediaStream > mediaStreams,
MLWebRTC.MediaStream.Track addedTrack
)

Parameters

TypeNameDescription
List< MLWebRTC.MediaStream >mediaStreamsThe media stream associated with the added track.
MLWebRTC.MediaStream.TrackaddedTrackThe track that was added to the connection.

delegate void OnTrackRemovedMultipleStreamsDelegate

A delegate that describes the requirements of the OnTrackRemovedDelegate callback.

public delegate void OnTrackRemovedMultipleStreamsDelegate(
List< MLWebRTC.MediaStream > mediaStreams,
MLWebRTC.MediaStream.Track removedTrack
)

Parameters

TypeNameDescription
List< MLWebRTC.MediaStream >mediaStreamsThe media stream associated with the removed track.
MLWebRTC.MediaStream.TrackremovedTrackThe track that was removed from the connection.

MLResult RemoveLocalTrack

Removes a local track to the connection.

public MLResult RemoveLocalTrack(
MLWebRTC.MediaStream.Track trackToRemove
)

Parameters

TypeNameDescription
MLWebRTC.MediaStream.TracktrackToRemoveTrack to remove to the connection.

Returns: MLResult.Result will be MLResult.Code.Ok if destroying all handles was successful. MLResult.Result will be MLResult.Code.WebRTCResultInstanceNotCreated if MLWebRTC instance was not created. MLResult.Result will be MLResult.Code.WebRTCResultMismatchingHandle if an incorrect handle was sent.


MLResult SetRemoteAnswer

Sets the remote answer for the connection.

public MLResult SetRemoteAnswer(
string remoteAnswer
)

Parameters

TypeNameDescription
stringremoteAnswerThe answer to set.

Returns: MLResult.Result will be MLResult.Code.Ok if destroying all handles was successful. MLResult.Result will be MLResult.Code.WebRTCResultInstanceNotCreated if MLWebRTC instance was not created. MLResult.Result will be MLResult.Code.WebRTCResultMismatchingHandle if an incorrect handle was sent. MLResult.Result will be MLResult.Code.InvalidParam if an invalid parameter was passed.


MLResult SetRemoteOffer

Sets the remote offer for the connection.

public MLResult SetRemoteOffer(
string remoteOffer
)

Parameters

TypeNameDescription
stringremoteOfferThe offer to set.

Returns: MLResult.Result will be MLResult.Code.Ok if destroying all handles was successful. MLResult.Result will be MLResult.Code.WebRTCResultInstanceNotCreated if MLWebRTC instance was not created. MLResult.Result will be MLResult.Code.WebRTCResultMismatchingHandle if an incorrect handle was sent. MLResult.Result will be MLResult.Code.InvalidParam if an invalid parameter was passed.


Public Events

OnConnected

Event invoked for when a connection between a local and remote peer is established.

public OnConnectedDelegate OnConnected()

OnDataChannelReceived

Event invoked for when a data channel is received by a connection.

public OnDataChannelReceivedDelegate OnDataChannelReceived()

OnDisconnected

Event invoked for when a connection between a local and remote peer is destroyed.

public OnDisconnectedDelegate OnDisconnected()

OnError

Event invoked for when an error occurs.

public OnErrorDelegate OnError()

OnIceGatheringCompleted

Event invoked for when ice gathering completed.

public OnIceGatheringCompletedDelegate OnIceGatheringCompleted()

OnLocalAnswerCreated

Event invoked for when an answer is sent.

public OnLocalAnswerCreatedDelegate OnLocalAnswerCreated()

OnLocalIceCandidateFound

Event invoked for when an ice candidate is sent.

public OnLocalIceCandidateFoundDelegate OnLocalIceCandidateFound()

OnLocalOfferCreated

Event invoked for when an offer is sent.

public OnLocalOfferCreatedDelegate OnLocalOfferCreated()

OnTrackAddedMultipleStreams

Event invoked for when a track is added to a connection.

public OnTrackAddedMultipleStreamsDelegate OnTrackAddedMultipleStreams()

OnTrackRemovedMultipleStreams

Event invoked for when a track is removed from a connection.

public OnTrackRemovedMultipleStreamsDelegate OnTrackRemovedMultipleStreams()