WebRTCMultiplayer.xml 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="WebRTCMultiplayer" inherits="NetworkedMultiplayerPeer" version="3.6" 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.network_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. [signal NetworkedMultiplayerPeer.connection_succeeded] and [signal NetworkedMultiplayerPeer.server_disconnected] will not be emitted unless [code]server_compatibility[/code] is [code]true[/code] in [method initialize]. Beside that data transfer works like in a [NetworkedMultiplayerPeer].
  10. </description>
  11. <tutorials>
  12. </tutorials>
  13. <methods>
  14. <method name="add_peer">
  15. <return type="int" enum="Error" />
  16. <argument index="0" name="peer" type="WebRTCPeerConnection" />
  17. <argument index="1" name="peer_id" type="int" />
  18. <argument index="2" name="unreliable_lifetime" type="int" default="1" />
  19. <description>
  20. Add a new peer to the mesh with the given [code]peer_id[/code]. The [WebRTCPeerConnection] must be in state [constant WebRTCPeerConnection.STATE_NEW].
  21. 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]).
  22. </description>
  23. </method>
  24. <method name="close">
  25. <return type="void" />
  26. <description>
  27. Close all the add peer connections and channels, freeing all resources.
  28. </description>
  29. </method>
  30. <method name="get_peer">
  31. <return type="Dictionary" />
  32. <argument index="0" name="peer_id" type="int" />
  33. <description>
  34. Return 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).
  35. </description>
  36. </method>
  37. <method name="get_peers">
  38. <return type="Dictionary" />
  39. <description>
  40. Returns a dictionary which keys are the peer ids and values the peer representation as in [method get_peer].
  41. </description>
  42. </method>
  43. <method name="has_peer">
  44. <return type="bool" />
  45. <argument index="0" name="peer_id" type="int" />
  46. <description>
  47. Returns [code]true[/code] if the given [code]peer_id[/code] is in the peers map (it might not be connected though).
  48. </description>
  49. </method>
  50. <method name="initialize">
  51. <return type="int" enum="Error" />
  52. <argument index="0" name="peer_id" type="int" />
  53. <argument index="1" name="server_compatibility" type="bool" default="false" />
  54. <description>
  55. Initialize the multiplayer peer with the given [code]peer_id[/code] (must be between 1 and 2147483647).
  56. If [code]server_compatibilty[/code] is [code]false[/code] (default), the multiplayer peer will be immediately in state [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTED] and [signal NetworkedMultiplayerPeer.connection_succeeded] will not be emitted.
  57. If [code]server_compatibilty[/code] is [code]true[/code] the peer will suppress all [signal NetworkedMultiplayerPeer.peer_connected] signals until a peer with id [constant NetworkedMultiplayerPeer.TARGET_PEER_SERVER] connects and then emit [signal NetworkedMultiplayerPeer.connection_succeeded]. After that the signal [signal NetworkedMultiplayerPeer.peer_connected] will be emitted for every already connected peer, and any new peer that might connect. If the server peer disconnects after that, signal [signal NetworkedMultiplayerPeer.server_disconnected] will be emitted and state will become [constant NetworkedMultiplayerPeer.CONNECTION_CONNECTED].
  58. </description>
  59. </method>
  60. <method name="remove_peer">
  61. <return type="void" />
  62. <argument index="0" name="peer_id" type="int" />
  63. <description>
  64. Remove the peer with given [code]peer_id[/code] from the mesh. If the peer was connected, and [signal NetworkedMultiplayerPeer.peer_connected] was emitted for it, then [signal NetworkedMultiplayerPeer.peer_disconnected] will be emitted.
  65. </description>
  66. </method>
  67. </methods>
  68. <constants>
  69. </constants>
  70. </class>