WebRTCMultiplayerPeer

package
v0.0.0-...-e10d1cd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 25 Imported by: 0

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

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 Any

type Any interface {
	gd.IsClass
	AsWebRTCMultiplayerPeer() Instance
}

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 = MoreArgs

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

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]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

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

func (self *Extension[T]) AsWebRTCMultiplayerPeer() Instance

type ID

type ID Object.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.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

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 New

func New() Instance

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) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsPacketPeer

func (self Instance) AsPacketPeer() PacketPeer.Instance

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsWebRTCMultiplayerPeer

func (self Instance) AsWebRTCMultiplayerPeer() Instance

func (Instance) CreateClient

func (self Instance) CreateClient(peer_id int) 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 (Instance) CreateMesh

func (self Instance) CreateMesh(peer_id int) 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 (Instance) CreateServer

func (self Instance) CreateServer() 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).

func (Instance) GetPeer

func (self Instance) GetPeer(peer_id int) Conn

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

func (self Instance) GetPeers() map[int]Conn

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

func (Instance) HasPeer

func (self Instance) HasPeer(peer_id int) bool

Returns true if the given 'peer_id' is in the peers map (it might not be connected though).

func (Instance) ID

func (self Instance) ID() ID

func (Instance) MoreArgs

func (self Instance) MoreArgs() MoreArgs

MoreArgs enables certain functions to be called with additional 'optional' arguments.

func (Instance) RemovePeer

func (self Instance) RemovePeer(peer_id int)

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.

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL