class WebRTCMultiplayer
package godot
extends NetworkedMultiplayerPeer › PacketPeer › Reference › Object
This class constructs a full mesh of godot.WebRTCPeerConnection
(one connection for each peer) that can be used as a godot.MultiplayerAPI.networkPeer
.
You can add each godot.WebRTCPeerConnection
via godot.WebRTCMultiplayer.addPeer
or remove them via godot.WebRTCMultiplayer.removePeer
. Peers must be added in godot.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.
NetworkedMultiplayerPeer.connection_succeeded
and NetworkedMultiplayerPeer.server_disconnected
will not be emitted unless server_compatibility
is true
in godot.WebRTCMultiplayer.initialize
. Beside that data transfer works like in a godot.NetworkedMultiplayerPeer
.
Constructor
Methods
addPeer(peer:WebRTCPeerConnection, peerId:Int, ?unreliableLifetime:Int):Error
Add a new peer to the mesh with the given peer_id
. The godot.WebRTCPeerConnection
must be in state godot.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 godot.WebRTCPeerConnection.createDataChannel
).
getPeer(peerId:Int):Dictionary
Return a dictionary representation of the peer with given peer_id
with three keys. connection
containing the godot.WebRTCPeerConnection
to this peer, channels
an array of three godot.WebRTCDataChannel
, and connected
a boolean representing if the peer connection is currently connected (all three channels are open).
getPeers():Dictionary
Returns a dictionary which keys are the peer ids and values the peer representation as in godot.WebRTCMultiplayer.getPeer
.
hasPeer(peerId:Int):Bool
Returns true
if the given peer_id
is in the peers map (it might not be connected though).
initialize(peerId:Int, ?serverCompatibility:Bool):Error
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 godot.NetworkedMultiplayerPeer_ConnectionStatus.connected
and NetworkedMultiplayerPeer.connection_succeeded
will not be emitted.
If server_compatibilty
is true
the peer will suppress all NetworkedMultiplayerPeer.peer_connected
signals until a peer with id godot.NetworkedMultiplayerPeer.targetPeerServer
connects and then emit NetworkedMultiplayerPeer.connection_succeeded
. After that the signal NetworkedMultiplayerPeer.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 NetworkedMultiplayerPeer.server_disconnected
will be emitted and state will become godot.NetworkedMultiplayerPeer_ConnectionStatus.connected
.
removePeer(peerId:Int):Void
Remove the peer with given peer_id
from the mesh. If the peer was connected, and NetworkedMultiplayerPeer.peer_connected
was emitted for it, then NetworkedMultiplayerPeer.peer_disconnected
will be emitted.