Skip to main content
Version: 20 Mar 2024

DataChannel

Class that represents a data channel used by the MLWebRTC API.

Public Fields

Label

Gets the label of the data channel.


public string Label { get; set; }


ParentConnection

Gets the connection associated with the data channel.


public PeerConnection ParentConnection { get; set; }

TypeDescription
PeerConnectionClass that represents a connection used by the MLWebRTC API.

Public Methods

DataChannel CreateLocal

Creates an initialized DataChannel object.

public static DataChannel CreateLocal(
MLWebRTC.PeerConnection connection,
out MLResult result,
string label ="local"
)

Parameters

TypeNameDescription
MLWebRTC.PeerConnectionconnectionThe connection to create the data channel with.
out MLResultlabelThe label to give the data channel.
stringresultThe MLResult object of the inner platform call(s).

Returns: An initialized DataChannel object.


MLResult Destroy

Destroys the data channel object.

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 IsOpen

Checks if the data channel is currently open.

public MLResult IsOpen(
out bool open
)

Parameters

TypeNameDescription
out boolopenTrue if data channel is open.

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 OnClosedDelegate

Delegate that describes the requirements of the OnClosed callback.

public delegate void OnClosedDelegate(
MLWebRTC.DataChannel dataChannel
)

Parameters

TypeNameDescription
MLWebRTC.DataChanneldataChannelThe data channel associated with the event.

delegate void OnMessageBinaryDelegate

Delegate that describes the requirements of the OnMessageBinary callback.

public delegate void OnMessageBinaryDelegate(
MLWebRTC.DataChannel dataChannel,
byte [] message
)

Parameters

TypeNameDescription
MLWebRTC.DataChanneldataChannelThe data channel associated with the event.
byte []messageThe message byte array.

delegate void OnMessageTextDelegate

Delegate that describes the requirements of the OnMessageText callback.

public delegate void OnMessageTextDelegate(
MLWebRTC.DataChannel dataChannel,
string message
)

Parameters

TypeNameDescription
MLWebRTC.DataChanneldataChannelThe data channel associated with the event.
stringmessageThe message string.

delegate void OnOpenedDelegate

Delegate that describes the requirements of the OnOpened callback.

public delegate void OnOpenedDelegate(
MLWebRTC.DataChannel dataChannel
)

Parameters

TypeNameDescription
MLWebRTC.DataChanneldataChannelThe data channel associated with the event.

MLResult SendMessage

Sends a string message to a data channel.

public MLResult SendMessage(
string message
)

Parameters

TypeNameDescription
stringmessageThe string to send.

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.Result will be MLResult.Code.WebRTCResultDataChannelIsClosed if data channel is closed.


MLResult SendMessage< T >

Sends a byte array message to a data channel.

public MLResult SendMessage< T >(
T [] message
)

Parameters

TypeNameDescription
T []messageThe byte array to send.

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.Result will be MLResult.Code.WebRTCResultDataChannelIsClosed if data channel is closed.


Public Events

OnClosed

Event invoked for when a data channel closes.

public OnClosedDelegate OnClosed()

OnMessageBinary

Event invoked for when a data channel receives a binary message.

public OnMessageBinaryDelegate OnMessageBinary()

OnMessageText

Event invoked for when a data channel receives a text message.

public OnMessageTextDelegate OnMessageText()

OnOpened

Event invoked for when a data channel opens.

public OnOpenedDelegate OnOpened()