WebRTCMultiplayer.xml 5.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="WebRTCMultiplayer" inherits="NetworkedMultiplayerPeer" version="4.0">
  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. </return>
  17. <argument index="0" name="peer" type="WebRTCPeerConnection">
  18. </argument>
  19. <argument index="1" name="peer_id" type="int">
  20. </argument>
  21. <argument index="2" name="unreliable_lifetime" type="int" default="1">
  22. </argument>
  23. <description>
  24. Add a new peer to the mesh with the given [code]peer_id[/code]. The [WebRTCPeerConnection] must be in state [constant WebRTCPeerConnection.STATE_NEW].
  25. 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]).
  26. </description>
  27. </method>
  28. <method name="close">
  29. <return type="void">
  30. </return>
  31. <description>
  32. Close all the add peer connections and channels, freeing all resources.
  33. </description>
  34. </method>
  35. <method name="get_peer">
  36. <return type="Dictionary">
  37. </return>
  38. <argument index="0" name="peer_id" type="int">
  39. </argument>
  40. <description>
  41. 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).
  42. </description>
  43. </method>
  44. <method name="get_peers">
  45. <return type="Dictionary">
  46. </return>
  47. <description>
  48. Returns a dictionary which keys are the peer ids and values the peer representation as in [method get_peer].
  49. </description>
  50. </method>
  51. <method name="has_peer">
  52. <return type="bool">
  53. </return>
  54. <argument index="0" name="peer_id" type="int">
  55. </argument>
  56. <description>
  57. Returns [code]true[/code] if the given [code]peer_id[/code] is in the peers map (it might not be connected though).
  58. </description>
  59. </method>
  60. <method name="initialize">
  61. <return type="int" enum="Error">
  62. </return>
  63. <argument index="0" name="peer_id" type="int">
  64. </argument>
  65. <argument index="1" name="server_compatibility" type="bool" default="false">
  66. </argument>
  67. <description>
  68. Initialize the multiplayer peer with the given [code]peer_id[/code] (must be between 1 and 2147483647).
  69. 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.
  70. 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].
  71. </description>
  72. </method>
  73. <method name="remove_peer">
  74. <return type="void">
  75. </return>
  76. <argument index="0" name="peer_id" type="int">
  77. </argument>
  78. <description>
  79. 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.
  80. </description>
  81. </method>
  82. </methods>
  83. <members>
  84. <member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" override="true" default="false" />
  85. <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="NetworkedMultiplayerPeer.TransferMode" default="2" />
  86. </members>
  87. <constants>
  88. </constants>
  89. </class>