reckfellENGINE

WebRtcMultiplayerPeer

A simple interface to create a peer-to-peer mesh network composed of WebRTCPeerConnection that is compatible with the MultiplayerAPI.

On this page
class WebRtcMultiplayerPeerReckfellSharpInherits MultiplayerPeer

A simple interface to create a peer-to-peer mesh network composed of WebRtcPeerConnection that is compatible with the MultiplayerApi.

This class constructs a full mesh of WebRtcPeerConnection (one connection for each peer) that can be used as a MultiplayerApi.MultiplayerPeer. You can add each WebRtcPeerConnection via WebRtcMultiplayerPeer.AddPeer or remove them via WebRtcMultiplayerPeer.RemovePeer. Peers must be added in WebRtcPeerConnection.ConnectionState.New state to allow it to create the appropriate channels. This class will not create offers nor set descriptions, it will only poll them, and notify connections and disconnections. When creating the peer via WebRtcMultiplayerPeer.CreateClient or WebRtcMultiplayerPeer.CreateServer the MultiplayerPeer.IsServerRelaySupported method will return true enabling peer exchange and packet relaying when supported by the MultiplayerApi implementation. Note: When exporting to Android, make sure to enable the INTERNET permission in the Android export preset before exporting the project or using remote deploy. Otherwise, network communication of any kind will be blocked by Android.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

WebRtcMultiplayerPeerConstructor
# WebRtcMultiplayerPeer
C#
public WebRtcMultiplayerPeer();

Methods8

AddPeerError
# AddPeer
C#
public Error AddPeer(WebRtcPeerConnection peer, int peerId, int unreliableLifetime = 1);

Add a new peer to the mesh with the given peer_id. The WebRtcPeerConnection must be in state WebRtcPeerConnection.ConnectionState.New. Three channels will be created for reliable, unreliable, and ordered transport. The value of unreliable_lifetime will be passed to the "maxPacketLifetime" option when creating unreliable and ordered channels (see WebRtcPeerConnection.CreateDataChannel).

Parameters
NameTypeDefault
peerWebRtcPeerConnection—
peerIdint—
unreliableLifetimeint1
Returns Error
CreateClientError
# CreateClient
C#
public Error CreateClient(int peerId, Reckfell.Collections.Array channelsConfig = null);

Initialize the multiplayer peer as a client with the given peer_id (must be between 2 and 2147483647). In this mode, you should only call WebRtcMultiplayerPeer.AddPeer once and with peer_id of 1. This mode enables MultiplayerPeer.IsServerRelaySupported, allowing the upper MultiplayerApi layer to perform peer exchange and packet relaying. You can optionally specify a channels_config array of MultiplayerPeer.TransferModeEnum which will be used to create extra channels (WebRTC only supports one transfer mode per channel).

Parameters
NameTypeDefault
peerIdint—
channelsConfigReckfell.Collections.Arraynull
Returns Error
CreateMeshError
# CreateMesh
C#
public Error CreateMesh(int peerId, Reckfell.Collections.Array channelsConfig = null);

Initialize the multiplayer peer as a mesh (i.e. all peers connect to each other) with the given peer_id (must be between 1 and 2147483647).

Parameters
NameTypeDefault
peerIdint—
channelsConfigReckfell.Collections.Arraynull
Returns Error
CreateServerError
# CreateServer
C#
public Error CreateServer(Reckfell.Collections.Array channelsConfig = null);

Initialize the multiplayer peer as a server (with unique ID of 1). This mode enables MultiplayerPeer.IsServerRelaySupported, allowing the upper MultiplayerApi layer to perform peer exchange and packet relaying. You can optionally specify a channels_config array of MultiplayerPeer.TransferModeEnum which will be used to create extra channels (WebRTC only supports one transfer mode per channel).

Parameters
NameTypeDefault
channelsConfigReckfell.Collections.Arraynull
Returns Error
GetPeerReckfell.Collections.Dictionary
# GetPeer
C#
public Reckfell.Collections.Dictionary GetPeer(int peerId);

Returns a dictionary representation of the peer with given peer_id with three keys. "connection" containing the WebRtcPeerConnection to this peer, "channels" an array of three WebRtcDataChannel, and "connected" a boolean representing if the peer connection is currently connected (all three channels are open).

Parameters
NameTypeDefault
peerIdint—
Returns Reckfell.Collections.Dictionary
GetPeersReckfell.Collections.Dictionary
# GetPeers
C#
public Reckfell.Collections.Dictionary GetPeers();

Returns a dictionary which keys are the peer ids and values the peer representation as in WebRtcMultiplayerPeer.GetPeer.

Returns Reckfell.Collections.Dictionary
HasPeerbool
# HasPeer
C#
public bool HasPeer(int peerId);

Returns true if the given peer_id is in the peers map (it might not be connected though).

Parameters
NameTypeDefault
peerIdint—
Returns bool
RemovePeervoid
# RemovePeer
C#
public void RemovePeer(int peerId);

Remove the peer with given peer_id from the mesh. If the peer was connected, and MultiplayerPeer.PeerConnected was emitted for it, then MultiplayerPeer.PeerDisconnected will be emitted.

Parameters
NameTypeDefault
peerIdint—
Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.