Skip to content
0.2.0-dev Download ZIP
78 lines ·5.3 KB Raw
1<?xml version="1.0" encoding="UTF-8" ?>
2<class name="WebRTCMultiplayerPeer" inherits="MultiplayerPeer" api_type="core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
3 <brief_description>
4 A simple interface to create a peer-to-peer mesh network composed of [WebRTCPeerConnection] that is compatible with the [MultiplayerAPI].
5 </brief_description>
6 <description>
7 This class constructs a full mesh of [WebRTCPeerConnection] (one connection for each peer) that can be used as a [member MultiplayerAPI.multiplayer_peer].
8 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.
9 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.
10 [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 remote deploy. Otherwise, network communication of any kind will be blocked by Android.
11 </description>
12 <tutorials>
13 </tutorials>
14 <methods>
15 <method name="add_peer">
16 <return type="int" enum="Error" />
17 <param index="0" name="peer" type="WebRTCPeerConnection" />
18 <param index="1" name="peer_id" type="int" />
19 <param index="2" name="unreliable_lifetime" type="int" default="1" />
20 <description>
21 Add a new peer to the mesh with the given [param peer_id]. The [WebRTCPeerConnection] must be in state [constant WebRTCPeerConnection.STATE_NEW].
22 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]).
23 </description>
24 </method>
25 <method name="create_client">
26 <return type="int" enum="Error" />
27 <param index="0" name="peer_id" type="int" />
28 <param index="1" name="channels_config" type="Array" default="[]" />
29 <description>
30 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.
31 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).
32 </description>
33 </method>
34 <method name="create_mesh">
35 <return type="int" enum="Error" />
36 <param index="0" name="peer_id" type="int" />
37 <param index="1" name="channels_config" type="Array" default="[]" />
38 <description>
39 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).
40 </description>
41 </method>
42 <method name="create_server">
43 <return type="int" enum="Error" />
44 <param index="0" name="channels_config" type="Array" default="[]" />
45 <description>
46 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.
47 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).
48 </description>
49 </method>
50 <method name="get_peer">
51 <return type="Dictionary" />
52 <param index="0" name="peer_id" type="int" />
53 <description>
54 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).
55 </description>
56 </method>
57 <method name="get_peers">
58 <return type="Dictionary" />
59 <description>
60 Returns a dictionary which keys are the peer ids and values the peer representation as in [method get_peer].
61 </description>
62 </method>
63 <method name="has_peer">
64 <return type="bool" />
65 <param index="0" name="peer_id" type="int" />
66 <description>
67 Returns [code]true[/code] if the given [param peer_id] is in the peers map (it might not be connected though).
68 </description>
69 </method>
70 <method name="remove_peer">
71 <return type="void" />
72 <param index="0" name="peer_id" type="int" />
73 <description>
74 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.
75 </description>
76 </method>
77 </methods>
78</class>