public class WebRTCMultiplayer : NetworkedMultiplayerPeer
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.
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
unreliableLifetimewill be passed to the
maxPacketLifetimeoption when creating unreliable and ordered channels (see WebRTCPeerConnection.CreateDataChannel(string, Godot.Collections.Dictionary)).
public void Close()
public Dictionary GetPeer(int peerId)
Return a dictionary representation of the peer with given
peerIdwith three keys.
connectioncontaining the WebRTCPeerConnection to this peer,
channelsan array of three WebRTCDataChannel, and
connecteda 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)
public Error Initialize(int peerId, bool serverCompatibility = false)
Initialize the multiplayer peer with the given
peerId(must be between 1 and 2147483647).
false(default), the multiplayer peer will be immediately in state [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTED] and connection_succeeded will not be emitted.
truethe 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)