WebRTCMultiplayer

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

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

    You can add each via add_peer or remove them via . Peers must be added in 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.

    and NetworkedMultiplayerPeer.server_disconnected will not be emitted unless is true in . Beside that data transfer works like in a NetworkedMultiplayerPeer.

    add_peer ( peer, int peer_id, unreliable_lifetime=1 )
    voidclose ( )
    get_peer ( peer_id )
    Dictionary ( )
    bool ( int peer_id )
    initialize ( peer_id, bool server_compatibility=false )
    void ( int peer_id )

    Three channels will be created for reliable, unreliable, and ordered transport. The value of unreliable_lifetime will be passed to the option when creating unreliable and ordered channels (see ).


    • void close ( )

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


    Return 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 , and connected a boolean representing if the peer connection is currently connected (all three channels are open).


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


    • has_peer ( int peer_id )

    • initialize ( int peer_id, server_compatibility=false )

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

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

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


    • void remove_peer ( int peer_id )

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