Documentation
¶
Overview ¶
Package WebRTCMultiplayerPeer provides methods for working with WebRTCMultiplayerPeer object instances.
Index ¶
- type Advanced
- type Any
- type Conn
- type Expanded
- func (self Expanded) AddPeer(peer WebRTCPeerConnection.Instance, peer_id int, unreliable_lifetime int) error
- func (self Expanded) CreateClient(peer_id int, channels_config []any) error
- func (self Expanded) CreateMesh(peer_id int, channels_config []any) error
- func (self Expanded) CreateServer(channels_config []any) error
- 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) RemovePeer(peer_id int)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) Virtual(name string) reflect.Value
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 Expanded ¶
type Expanded [1]gdclass.WebRTCMultiplayerPeer
func (Expanded) AddPeer ¶
func (self Expanded) AddPeer(peer WebRTCPeerConnection.Instance, peer_id int, unreliable_lifetime int) error
Add a new peer to the mesh with the given [param peer_id]. The [WebRTCPeerConnection] must be in state [constant WebRTCPeerConnection.STATE_NEW]. Three channels will be created for reliable, unreliable, and ordered transport. The value of [param unreliable_lifetime] will be passed to the [code]"maxPacketLifetime"[/code] option when creating unreliable and ordered channels (see [method WebRTCPeerConnection.create_data_channel]).
func (Expanded) CreateClient ¶
Initialize the multiplayer peer as a client with the given [param peer_id] (must be between 2 and 2147483647). In this mode, you should only call [method add_peer] once and with [param peer_id] of [code]1[/code]. This mode enables [method MultiplayerPeer.is_server_relay_supported], allowing the upper [MultiplayerAPI] layer to perform peer exchange and packet relaying. You can optionally specify a [param channels_config] array of [enum MultiplayerPeer.TransferMode] which will be used to create extra channels (WebRTC only supports one transfer mode per channel).
func (Expanded) CreateMesh ¶
Initialize the multiplayer peer as a mesh (i.e. all peers connect to each other) with the given [param peer_id] (must be between 1 and 2147483647).
func (Expanded) CreateServer ¶
Initialize the multiplayer peer as a server (with unique ID of [code]1[/code]). This mode enables [method MultiplayerPeer.is_server_relay_supported], allowing the upper [MultiplayerAPI] layer to perform peer exchange and packet relaying. You can optionally specify a [param channels_config] array of [enum MultiplayerPeer.TransferMode] which will be used to create extra channels (WebRTC only supports one transfer mode per channel).
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
This class constructs a full mesh of [WebRTCPeerConnection] (one connection for each peer) that can be used as a [member MultiplayerAPI.multiplayer_peer]. You can add each [WebRTCPeerConnection] via [method add_peer] or remove them via [method remove_peer]. 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. When creating the peer via [method create_client] or [method create_server] the [method MultiplayerPeer.is_server_relay_supported] method will return [code]true[/code] enabling peer exchange and packet relaying when supported by the [MultiplayerAPI] implementation. [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] 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.
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 [param peer_id]. The [WebRTCPeerConnection] must be in state [constant WebRTCPeerConnection.STATE_NEW]. Three channels will be created for reliable, unreliable, and ordered transport. The value of [param unreliable_lifetime] will be passed to the [code]"maxPacketLifetime"[/code] option when creating unreliable and ordered channels (see [method WebRTCPeerConnection.create_data_channel]).
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 [param peer_id] (must be between 2 and 2147483647). In this mode, you should only call [method add_peer] once and with [param peer_id] of [code]1[/code]. This mode enables [method MultiplayerPeer.is_server_relay_supported], allowing the upper [MultiplayerAPI] layer to perform peer exchange and packet relaying. You can optionally specify a [param channels_config] array of [enum 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 [param peer_id] (must be between 1 and 2147483647).
func (Instance) CreateServer ¶
Initialize the multiplayer peer as a server (with unique ID of [code]1[/code]). This mode enables [method MultiplayerPeer.is_server_relay_supported], allowing the upper [MultiplayerAPI] layer to perform peer exchange and packet relaying. You can optionally specify a [param channels_config] array of [enum 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 [param peer_id] with three keys. [code]"connection"[/code] containing the [WebRTCPeerConnection] to this peer, [code]"channels"[/code] an array of three [WebRTCDataChannel], and [code]"connected"[/code] 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 [method get_peer].
func (Instance) HasPeer ¶
Returns [code]true[/code] if the given [param peer_id] is in the peers map (it might not be connected though).
func (Instance) RemovePeer ¶
Remove the peer with given [param peer_id] from the mesh. If the peer was connected, and [signal MultiplayerPeer.peer_connected] was emitted for it, then [signal MultiplayerPeer.peer_disconnected] will be emitted.