Documentation
¶
Overview ¶
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 AddPeer or remove them via RemovePeer. Peers must be added in [Webrtcpeerconnection.StateNew] 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 CreateClient or 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 one-click deploy. Otherwise, network communication of any kind will be blocked by Android.
Index ¶
- type Advanced
- type Any
- type Conn
- type Expanded
- type Extension
- func (self *Extension[T]) AsMultiplayerPeer() MultiplayerPeer.Instance
- func (self *Extension[T]) AsObject() [1]gd.Object
- func (self *Extension[T]) AsPacketPeer() PacketPeer.Instance
- func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
- func (self *Extension[T]) AsWebRTCMultiplayerPeer() Instance
- type ID
- type Instance
- func (self Instance) AddPeer(peer WebRTCPeerConnection.Instance, peer_id int) error
- func (self Instance) AsMultiplayerPeer() MultiplayerPeer.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsPacketPeer() PacketPeer.Instance
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) AsWebRTCMultiplayerPeer() Instance
- func (self Instance) CreateClient(peer_id int) error
- func (self Instance) CreateMesh(peer_id int) error
- func (self Instance) CreateServer() error
- func (self Instance) GetPeer(peer_id int) Conn
- func (self Instance) GetPeers() map[int]Conn
- func (self Instance) HasPeer(peer_id int) bool
- func (self Instance) ID() ID
- func (self Instance) MoreArgs() MoreArgs
- func (self Instance) RemovePeer(peer_id int)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) Virtual(name string) reflect.Value
- type MoreArgs
- func (self MoreArgs) AddPeer(peer WebRTCPeerConnection.Instance, peer_id int, unreliable_lifetime int) error
- func (self MoreArgs) CreateClient(peer_id int, channels_config []MultiplayerPeer.TransferMode) error
- func (self MoreArgs) CreateMesh(peer_id int, channels_config []MultiplayerPeer.TransferMode) error
- func (self MoreArgs) CreateServer(channels_config []MultiplayerPeer.TransferMode) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type Conn ¶
type Conn struct { Connection [1]gdclass.WebRTCPeerConnection `gd:"connection"` Channels [][1]gdclass.WebRTCDataChannel `gd:"channels"` Connected bool `gd:"connected"` }
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsMultiplayerPeer ¶
func (self *Extension[T]) AsMultiplayerPeer() MultiplayerPeer.Instance
func (*Extension[T]) AsPacketPeer ¶
func (self *Extension[T]) AsPacketPeer() PacketPeer.Instance
func (*Extension[T]) AsRefCounted ¶
func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
func (*Extension[T]) AsWebRTCMultiplayerPeer ¶
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
type Instance [1]gdclass.WebRTCMultiplayerPeer
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AddPeer ¶
func (self Instance) AddPeer(peer WebRTCPeerConnection.Instance, peer_id int) error
Add a new peer to the mesh with the given 'peer_id'. The WebRTCPeerConnection must be in state [Webrtcpeerconnection.StateNew].
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).
func (Instance) AsMultiplayerPeer ¶
func (self Instance) AsMultiplayerPeer() MultiplayerPeer.Instance
func (Instance) AsPacketPeer ¶
func (self Instance) AsPacketPeer() PacketPeer.Instance
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) AsWebRTCMultiplayerPeer ¶
func (Instance) CreateClient ¶
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 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.TransferMode] which will be used to create extra channels (WebRTC only supports one transfer mode per channel).
func (Instance) CreateMesh ¶
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).
func (Instance) CreateServer ¶
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.TransferMode] which will be used to create extra channels (WebRTC only supports one transfer mode per channel).
func (Instance) GetPeer ¶
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).
func (Instance) GetPeers ¶
Returns a dictionary which keys are the peer ids and values the peer representation as in GetPeer.
func (Instance) HasPeer ¶
Returns true if the given 'peer_id' is in the peers map (it might not be connected though).
func (Instance) MoreArgs ¶
MoreArgs enables certain functions to be called with additional 'optional' arguments.
func (Instance) RemovePeer ¶
Remove the peer with given 'peer_id' from the mesh. If the peer was connected, and OnMultiplayerpeer.PeerConnected was emitted for it, then OnMultiplayerpeer.PeerDisconnected will be emitted.
type MoreArgs ¶
type MoreArgs [1]gdclass.WebRTCMultiplayerPeer
MoreArgs is a container for Instance functions with additional 'optional' arguments.
func (MoreArgs) AddPeer ¶
func (self MoreArgs) AddPeer(peer WebRTCPeerConnection.Instance, peer_id int, unreliable_lifetime int) error
Add a new peer to the mesh with the given 'peer_id'. The WebRTCPeerConnection must be in state [Webrtcpeerconnection.StateNew].
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).
func (MoreArgs) CreateClient ¶
func (self MoreArgs) CreateClient(peer_id int, channels_config []MultiplayerPeer.TransferMode) error
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 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.TransferMode] which will be used to create extra channels (WebRTC only supports one transfer mode per channel).
func (MoreArgs) CreateMesh ¶
func (self MoreArgs) CreateMesh(peer_id int, channels_config []MultiplayerPeer.TransferMode) error
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).
func (MoreArgs) CreateServer ¶
func (self MoreArgs) CreateServer(channels_config []MultiplayerPeer.TransferMode) error
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.TransferMode] which will be used to create extra channels (WebRTC only supports one transfer mode per channel).