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

This class constructs a full mesh of WebRTCPeerConnection (one connection for each peer) that can be used as a MultiplayerAPI.NetworkPeer.

You can add each WebRTCPeerConnection via AddPeer(Godot.WebRTCPeerConnection, int, int) or remove them via RemovePeer(int). Peers must be added in [constant WebRTCPeerConnection.STATE_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.

connection_succeeded and server_disconnected will not be emitted unless server_compatibility is true in Initialize(int, bool). Beside that data transfer works like in a NetworkedMultiplayerPeer.

Inheritance Chain


    public WebRTCMultiplayer()


    public Error AddPeer(WebRTCPeerConnection peer, int peerId, int unreliableLifetime = 1)

Add a new peer to the mesh with the given peerId. The WebRTCPeerConnection must be in state [constant WebRTCPeerConnection.STATE_NEW].

Three channels will be created for reliable, unreliable, and ordered transport. The value of unreliableLifetime will be passed to the maxPacketLifetime option when creating unreliable and ordered channels (see WebRTCPeerConnection.CreateDataChannel(string, Godot.Collections.Dictionary)).

    public void Close()

Close all the add peer connections and channels, freeing all resources.

    public Dictionary GetPeer(int peerId)

Return a dictionary representation of the peer with given peerId 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).

    public Dictionary GetPeers()

Returns a dictionary which keys are the peer ids and values the peer representation as in GetPeer(int)

    public bool HasPeer(int peerId)

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

    public Error Initialize(int peerId, bool serverCompatibility = false)

Initialize the multiplayer peer with the given peerId (must be between 1 and 2147483647).

If server_compatibilty is false (default), the multiplayer peer will be immediately in state [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTED] and connection_succeeded will not be emitted.

If server_compatibilty is true the peer will suppress all peer_connected signals until a peer with id [constant NetworkedMultiplayerPeer.TARGET_PEER_SERVER] connects and then emit connection_succeeded. After that the signal peer_connected will be emitted for every already connected peer, and any new peer that might connect. If the server peer disconnects after that, signal server_disconnected will be emitted and state will become [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTED].

    public void RemovePeer(int peerId)

Remove the peer with given peerId from the mesh. If the peer was connected, and peer_connected was emitted for it, then peer_disconnected will be emitted.