summaryrefslogtreecommitdiff
path: root/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml
blob: 0b42c6ed3521baf59ad789c2d61de2872836e6fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?xml version="1.0" encoding="UTF-8" ?>
<class name="WebRTCMultiplayerPeer" inherits="MultiplayerPeer" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
	<brief_description>
		A simple interface to create a peer-to-peer mesh network composed of [WebRTCPeerConnection] that is compatible with the [MultiplayerAPI].
	</brief_description>
	<description>
		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.
		[signal MultiplayerPeer.connection_succeeded] and [signal MultiplayerPeer.server_disconnected] will not be emitted unless the peer is created using [method create_client]. Beside that data transfer works like in a [MultiplayerPeer].
		[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.
	</description>
	<tutorials>
	</tutorials>
	<methods>
		<method name="add_peer">
			<return type="int" enum="Error" />
			<param index="0" name="peer" type="WebRTCPeerConnection" />
			<param index="1" name="peer_id" type="int" />
			<param index="2" name="unreliable_lifetime" type="int" default="1" />
			<description>
				Add a new peer to the mesh with the given [code]peer_id[/code]. The [WebRTCPeerConnection] must be in state [constant WebRTCPeerConnection.STATE_NEW].
				Three channels will be created for reliable, unreliable, and ordered transport. The value of [code]unreliable_lifetime[/code] will be passed to the [code]maxPacketLifetime[/code] option when creating unreliable and ordered channels (see [method WebRTCPeerConnection.create_data_channel]).
			</description>
		</method>
		<method name="close">
			<return type="void" />
			<description>
				Close all the add peer connections and channels, freeing all resources.
			</description>
		</method>
		<method name="create_client">
			<return type="int" enum="Error" />
			<param index="0" name="peer_id" type="int" />
			<param index="1" name="channels_config" type="Array" default="[]" />
			<description>
				Initialize the multiplayer peer as a client with the given [code]peer_id[/code] (must be between 2 and 2147483647). In this mode, you should only call [method add_peer] once and with [code]peer_id[/code] 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 [code]channels_config[/code] array of [enum MultiplayerPeer.TransferMode] which will be used to create extra channels (WebRTC only supports one transfer mode per channel).
			</description>
		</method>
		<method name="create_mesh">
			<return type="int" enum="Error" />
			<param index="0" name="peer_id" type="int" />
			<param index="1" name="channels_config" type="Array" default="[]" />
			<description>
				Initialize the multiplayer peer as a mesh (i.e. all peers connect to each other) with the given [code]peer_id[/code] (must be between 1 and 2147483647).
			</description>
		</method>
		<method name="create_server">
			<return type="int" enum="Error" />
			<param index="0" name="channels_config" type="Array" default="[]" />
			<description>
				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 [code]channels_config[/code] array of [enum MultiplayerPeer.TransferMode] which will be used to create extra channels (WebRTC only supports one transfer mode per channel).
			</description>
		</method>
		<method name="get_peer">
			<return type="Dictionary" />
			<param index="0" name="peer_id" type="int" />
			<description>
				Returns a dictionary representation of the peer with given [code]peer_id[/code] 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).
			</description>
		</method>
		<method name="get_peers">
			<return type="Dictionary" />
			<description>
				Returns a dictionary which keys are the peer ids and values the peer representation as in [method get_peer].
			</description>
		</method>
		<method name="has_peer">
			<return type="bool" />
			<param index="0" name="peer_id" type="int" />
			<description>
				Returns [code]true[/code] if the given [code]peer_id[/code] is in the peers map (it might not be connected though).
			</description>
		</method>
		<method name="remove_peer">
			<return type="void" />
			<param index="0" name="peer_id" type="int" />
			<description>
				Remove the peer with given [code]peer_id[/code] 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.
			</description>
		</method>
	</methods>
</class>