Skip to main content
Version: 20 Mar 2024

NativeBindings

Native bindings for the MLWebRTC.PeerConnection class.

Inherits from:
MagicLeapNativeBindings

Public Methods

MLResult.Code CreateRemoteConnection

Creates a remote connection and sets up the native callbacks.

public static MLResult.Code CreateRemoteConnection(
MLWebRTC.IceServer [] iceServers,
out PeerConnection connection
)

Parameters

TypeNameDescription
MLWebRTC.IceServer []iceServersThe ice servers to create the connection with.
out PeerConnectionconnectionThe created connection object.

Returns: MLResult.Result will be MLResult.Code.Ok if the connection was successfully created. MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.


MLResult.Code CreateRemoteConnection

Creates a remote connection with a forward proxy configuration and sets up the native callbacks.

public static MLResult.Code CreateRemoteConnection(
MLWebRTC.IceServer [] iceServers,
MLWebRTC.ProxyConfig proxyConfig,
out PeerConnection connection
)

Parameters

TypeNameDescription
MLWebRTC.IceServer []iceServersThe ice servers to create the connection with.
MLWebRTC.ProxyConfigproxyConfigThe forward proxy configuration.
out PeerConnectionconnectionThe created connection object.

Returns: MLResult.Result will be MLResult.Code.Ok if the connection was successfully created. MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.


MLResult.Code MLWebRTCConnectionAddLocalSourceTrackEx

Add a local source as a media track to the connection.

public MLResult.Code MLWebRTCConnectionAddLocalSourceTrackEx(
ulong connectionHandle,
ulong localSourceHandle,
ref MLWebRTCTrackInfo trackInfo
)

Parameters

TypeNameDescription
ulongconnectionHandleThe handle to the connection to set the local source to.
ulonglocalSourceHandleThe handle to the local source to set onto the connection.
ref MLWebRTCTrackInfotrackInfoInformation about the track to be added

Returns: MLResult.Result will be MLResult.Code.Ok if the source was successfully set on the connection. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.


MLResult.Code MLWebRTCConnectionAddRemoteIceCandidate

Adds a remote ice candidate from a connection.

public MLResult.Code MLWebRTCConnectionAddRemoteIceCandidate(
ulong connectionHandle,
in MLWebRTCConnectionIceCandidate candidate
)

Parameters

TypeNameDescription
ulongconnectionHandleThe handle to the connection to send the ice candidate to.
in MLWebRTCConnectionIceCandidatecandidateThe ice candidate to send.

Returns: MLResult.Result will be MLResult.Code.Ok if the ice candidate was successfully sent. MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.


MLResult.Code MLWebRTCConnectionCreate

Creates a WebRTC connection.

public MLResult.Code MLWebRTCConnectionCreate(
in MLWebRTCConnectionConfig config,
in MLWebRTCConnectionEventCallbacks callbacks,
out ulong connectionHandle
)

Parameters

TypeNameDescription
in MLWebRTCConnectionConfigconfigThe configuration that holds the ice servers.
in MLWebRTCConnectionEventCallbackscallbacksThe object that holds all the callbacks that will be invoked natively.
out ulongconnectionHandleThe handle of the connection to return to the caller.

Returns: MLResult.Result will be MLResult.Code.Ok if the connection was successfully created. MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.


MLResult.Code MLWebRTCConnectionCreateOffer

Creates an offer with a connection.

public MLResult.Code MLWebRTCConnectionCreateOffer(
ulong connectionHandle
)

Parameters

TypeNameDescription
ulongconnectionHandleThe handle to the connection creating the offer.

Returns: MLResult.Result will be MLResult.Code.Ok if the offer was successfully created. MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.


MLResult.Code MLWebRTCConnectionDestroy

Destroys a WebRTC connection.

public MLResult.Code MLWebRTCConnectionDestroy(
ulong connectionHandle
)

Parameters

TypeNameDescription
ulongconnectionHandleThe handle to the connection to destroy.

Returns: MLResult.Result will be MLResult.Code.Ok if the connection was successfully destroyed. MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.


MLResult.Code MLWebRTCConnectionHasFailed

Gets if a connection has failed

public MLResult.Code MLWebRTCConnectionHasFailed(
ulong connectionHandle,
out bool hasFailed
)

Parameters

TypeNameDescription
ulongconnectionHandleThe handle to the connection in question.
out boolhasFailedUsed to return to the user to determine if the connection has failed or not.

Returns: MLResult.Result will be MLResult.Code.Ok if the connection status was successfully queried. MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.


MLResult.Code MLWebRTCConnectionIsConnected

Gets if a connection is currently connected.

public MLResult.Code MLWebRTCConnectionIsConnected(
ulong connectionHandle,
out bool isConnected
)

Parameters

TypeNameDescription
ulongconnectionHandleThe handle to the connection in question.
out boolisConnectedUsed to return to the user to determine if the connection is connected or not.

Returns: MLResult.Result will be MLResult.Code.Ok if the connection status was successfully queried. MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.


MLResult.Code MLWebRTCConnectionProcessEvents

Processes events of a connection, responsible for callbacks being invoked natively.

public MLResult.Code MLWebRTCConnectionProcessEvents(
ulong connectionHandle
)

Parameters

TypeNameDescription
ulongconnectionHandleThe handle to the connection to process events from.

Returns: MLResult.Result will be MLResult.Code.Ok if the connection had it's events successfully processed. MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.


MLResult.Code MLWebRTCConnectionRemoveLocalSourceTrack

Sets the local source of a connection.

public MLResult.Code MLWebRTCConnectionRemoveLocalSourceTrack(
ulong connectionHandle,
ulong localSourceHandle
)

Parameters

TypeNameDescription
ulongconnectionHandleThe handle to the connection to set the local source to.
ulonglocalSourceHandleThe handle to the local source to set onto the connection.

Returns: MLResult.Result will be MLResult.Code.Ok if the source was successfully set on the connection. MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.


MLResult.Code MLWebRTCConnectionSetRemoteAnswer

Sets the answer to an offer from a remote connection.

public MLResult.Code MLWebRTCConnectionSetRemoteAnswer(
ulong connectionHandle,
string answer
)

Parameters

TypeNameDescription
ulongconnectionHandleThe handle to the connection answering to the offer.
stringanswerThe json formatted answer string to set.

Returns: MLResult.Result will be MLResult.Code.Ok if the answer was successfully set. MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.


MLResult.Code MLWebRTCConnectionSetRemoteOffer

Sets an offer from a remote connection.

public MLResult.Code MLWebRTCConnectionSetRemoteOffer(
ulong connectionHandle,
string offer
)

Parameters

TypeNameDescription
ulongconnectionHandleThe handle to the connection responding to the offer.
stringofferThe offer string.

Returns: MLResult.Result will be MLResult.Code.Ok if the offer was successfully set. MLResult.Result will be MLResult.Code.PermissionDenied if necessary permission is missing. MLResult.Result will be MLResult.Code.UnspecifiedFailure if failed due to other internal error.


delegate void OnConnectedDelegate

A delegate that describes the requirements of the OnConnectedDelegate callback.

public delegate void OnConnectedDelegate(
IntPtr context
)

Parameters

TypeNameDescription
IntPtrcontextPointer to a context object.

delegate void OnDataChannelReceivedDelegate

A delegate that describes the requirements of the OnDataChannelReceivedDelegate callback.

public delegate void OnDataChannelReceivedDelegate(
ulong remoteDataChanelHandle,
IntPtr context
)

Parameters

TypeNameDescription
ulongremoteDataChanelHandleThe handle to the newly received data channel.
IntPtrcontextPointer to a context object.

delegate void OnDisconnectedDelegate

A delegate that describes the requirements of the OnDisconnectedDelegate callback.

public delegate void OnDisconnectedDelegate(
IntPtr context
)

Parameters

TypeNameDescription
IntPtrcontextPointer to a context object.

delegate void OnErrorDelegate

A delegate that describes the requirements of the OnError callback.

public delegate void OnErrorDelegate(
string message,
IntPtr context
)

Parameters

TypeNameDescription
stringmessageThe error message.
IntPtrcontextPointer to a context object.

delegate void OnIceGatheringCompletedDelegate

A delegate that describes the requirements of the OnIceGatheringCompleted callback.

public delegate void OnIceGatheringCompletedDelegate(
IntPtr context
)

Parameters

TypeNameDescription
IntPtrcontextPointer to a context object.

delegate void OnLocalAnswerCreatedDelegate

A delegate that describes the requirements of the OnSendAnswer callback.

public delegate void OnLocalAnswerCreatedDelegate(
string answer,
IntPtr context
)

Parameters

TypeNameDescription
stringanswerThe json formatted answer string.
IntPtrcontextPointer to a context object.

delegate void OnLocalIceCandidateFoundDelegate

A delegate that describes the requirements of the OnSendIceCandidate callback.

public delegate void OnLocalIceCandidateFoundDelegate(
in MLWebRTCConnectionIceCandidate iceCandidate,
IntPtr context
)

Parameters

TypeNameDescription
in MLWebRTCConnectionIceCandidateiceCandidateThe ice candidate object that was sent.
IntPtrcontextPointer to a context object.

delegate void OnLocalOfferCreatedDelegate

A delegate that describes the requirements of the OnSendOfferDelegate callback.

public delegate void OnLocalOfferCreatedDelegate(
string offer,
IntPtr context
)

Parameters

TypeNameDescription
stringofferThe json formatted offer string.
IntPtrcontextPointer to a context object.

delegate void OnTrackAddedDelegate

A delegate that describes the requirements of the OnTrackAddedDelegate callback.

public delegate void OnTrackAddedDelegate(
in MLWebRTC.Source.NativeBindings.MLWebRTCSource sourceNative,
uint numStreamIds,
IntPtr streamIdsPtr,
IntPtr context
)

Parameters

TypeNameDescription
in MLWebRTC.Source.NativeBindings.MLWebRTCSourcesourceNativeThe native source object that was added.
uintnumStreamIdsThe number of streams this track belongs to.
IntPtrstreamIdsPtrThe names of the streams this track belongs to.
IntPtrcontextPointer to a context object.

delegate void OnTrackRemovedDelegate

A delegate that describes the requirements of the OnTrackRemovedDelegate callback.

public delegate void OnTrackRemovedDelegate(
ulong remoteSourceHandle,
IntPtr context
)

Parameters

TypeNameDescription
ulongremoteSourceHandleThe handle to the removed source.
IntPtrcontextPointer to a context object.