WebRTCMultiplayerPeer.xml 5.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="WebRTCMultiplayerPeer" inherits="MultiplayerPeer" 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.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. [signal MultiplayerPeer.connection_succeeded] and [signal MultiplayerPeer.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 [MultiplayerPeer].
  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 one-click 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. <argument index="0" name="peer" type="WebRTCPeerConnection" />
  18. <argument index="1" name="peer_id" type="int" />
  19. <argument index="2" name="unreliable_lifetime" type="int" default="1" />
  20. <description>
  21. Add a new peer to the mesh with the given [code]peer_id[/code]. 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 [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]).
  23. </description>
  24. </method>
  25. <method name="close">
  26. <return type="void" />
  27. <description>
  28. Close all the add peer connections and channels, freeing all resources.
  29. </description>
  30. </method>
  31. <method name="get_peer">
  32. <return type="Dictionary" />
  33. <argument index="0" name="peer_id" type="int" />
  34. <description>
  35. 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).
  36. </description>
  37. </method>
  38. <method name="get_peers">
  39. <return type="Dictionary" />
  40. <description>
  41. Returns a dictionary which keys are the peer ids and values the peer representation as in [method get_peer].
  42. </description>
  43. </method>
  44. <method name="has_peer">
  45. <return type="bool" />
  46. <argument index="0" name="peer_id" type="int" />
  47. <description>
  48. Returns [code]true[/code] if the given [code]peer_id[/code] is in the peers map (it might not be connected though).
  49. </description>
  50. </method>
  51. <method name="initialize">
  52. <return type="int" enum="Error" />
  53. <argument index="0" name="peer_id" type="int" />
  54. <argument index="1" name="server_compatibility" type="bool" default="false" />
  55. <argument index="2" name="channels_config" type="Array" default="[]" />
  56. <description>
  57. Initialize the multiplayer peer with the given [code]peer_id[/code] (must be between 1 and 2147483647).
  58. If [code]server_compatibilty[/code] is [code]false[/code] (default), the multiplayer peer will be immediately in state [constant MultiplayerPeer.CONNECTION_CONNECTED] and [signal MultiplayerPeer.connection_succeeded] will not be emitted.
  59. If [code]server_compatibilty[/code] is [code]true[/code] the peer will suppress all [signal MultiplayerPeer.peer_connected] signals until a peer with id [constant MultiplayerPeer.TARGET_PEER_SERVER] connects and then emit [signal MultiplayerPeer.connection_succeeded]. After that the signal [signal MultiplayerPeer.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 MultiplayerPeer.server_disconnected] will be emitted and state will become [constant MultiplayerPeer.CONNECTION_CONNECTED].
  60. You can optionally specify a [code]channels_config[/code] array of [enum TransferMode] which will be used to create extra channels (WebRTC only supports one transfer mode per channel).
  61. </description>
  62. </method>
  63. <method name="remove_peer">
  64. <return type="void" />
  65. <argument index="0" name="peer_id" type="int" />
  66. <description>
  67. 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.
  68. </description>
  69. </method>
  70. </methods>
  71. </class>