class_webrtcmultiplayer.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the WebRTCMultiplayer.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_WebRTCMultiplayer:
  6. WebRTCMultiplayer
  7. =================
  8. **Inherits:** :ref:`NetworkedMultiplayerPeer<class_NetworkedMultiplayerPeer>` **<** :ref:`PacketPeer<class_PacketPeer>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. A simple interface to create a peer-to-peer mesh network composed of :ref:`WebRTCPeerConnection<class_WebRTCPeerConnection>` that is compatible with the :ref:`MultiplayerAPI<class_MultiplayerAPI>`.
  10. Description
  11. -----------
  12. This class constructs a full mesh of :ref:`WebRTCPeerConnection<class_WebRTCPeerConnection>` (one connection for each peer) that can be used as a :ref:`MultiplayerAPI.network_peer<class_MultiplayerAPI_property_network_peer>`.
  13. You can add each :ref:`WebRTCPeerConnection<class_WebRTCPeerConnection>` via :ref:`add_peer<class_WebRTCMultiplayer_method_add_peer>` or remove them via :ref:`remove_peer<class_WebRTCMultiplayer_method_remove_peer>`. Peers must be added in :ref:`WebRTCPeerConnection.STATE_NEW<class_WebRTCPeerConnection_constant_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.
  14. :ref:`NetworkedMultiplayerPeer.connection_succeeded<class_NetworkedMultiplayerPeer_signal_connection_succeeded>` and :ref:`NetworkedMultiplayerPeer.server_disconnected<class_NetworkedMultiplayerPeer_signal_server_disconnected>` will not be emitted unless ``server_compatibility`` is ``true`` in :ref:`initialize<class_WebRTCMultiplayer_method_initialize>`. Beside that data transfer works like in a :ref:`NetworkedMultiplayerPeer<class_NetworkedMultiplayerPeer>`.
  15. Properties
  16. ----------
  17. +-----------------------------------------------------------------+------------------------+-------------------------------+
  18. | :ref:`bool<class_bool>` | refuse_new_connections | ``false`` *(parent override)* |
  19. +-----------------------------------------------------------------+------------------------+-------------------------------+
  20. | :ref:`TransferMode<enum_NetworkedMultiplayerPeer_TransferMode>` | transfer_mode | ``2`` *(parent override)* |
  21. +-----------------------------------------------------------------+------------------------+-------------------------------+
  22. Methods
  23. -------
  24. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`add_peer<class_WebRTCMultiplayer_method_add_peer>` **(** :ref:`WebRTCPeerConnection<class_WebRTCPeerConnection>` peer, :ref:`int<class_int>` peer_id, :ref:`int<class_int>` unreliable_lifetime=1 **)** |
  26. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | void | :ref:`close<class_WebRTCMultiplayer_method_close>` **(** **)** |
  28. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`Dictionary<class_Dictionary>` | :ref:`get_peer<class_WebRTCMultiplayer_method_get_peer>` **(** :ref:`int<class_int>` peer_id **)** |
  30. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Dictionary<class_Dictionary>` | :ref:`get_peers<class_WebRTCMultiplayer_method_get_peers>` **(** **)** |
  32. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`bool<class_bool>` | :ref:`has_peer<class_WebRTCMultiplayer_method_has_peer>` **(** :ref:`int<class_int>` peer_id **)** |
  34. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`initialize<class_WebRTCMultiplayer_method_initialize>` **(** :ref:`int<class_int>` peer_id, :ref:`bool<class_bool>` server_compatibility=false **)** |
  36. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | void | :ref:`remove_peer<class_WebRTCMultiplayer_method_remove_peer>` **(** :ref:`int<class_int>` peer_id **)** |
  38. +---------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. Method Descriptions
  40. -------------------
  41. .. _class_WebRTCMultiplayer_method_add_peer:
  42. - :ref:`Error<enum_@GlobalScope_Error>` **add_peer** **(** :ref:`WebRTCPeerConnection<class_WebRTCPeerConnection>` peer, :ref:`int<class_int>` peer_id, :ref:`int<class_int>` unreliable_lifetime=1 **)**
  43. Add a new peer to the mesh with the given ``peer_id``. The :ref:`WebRTCPeerConnection<class_WebRTCPeerConnection>` must be in state :ref:`WebRTCPeerConnection.STATE_NEW<class_WebRTCPeerConnection_constant_STATE_NEW>`.
  44. Three channels will be created for reliable, unreliable, and ordered transport. The value of ``unreliable_lifetime`` will be passed to the ``maxPacketLifetime`` option when creating unreliable and ordered channels (see :ref:`WebRTCPeerConnection.create_data_channel<class_WebRTCPeerConnection_method_create_data_channel>`).
  45. ----
  46. .. _class_WebRTCMultiplayer_method_close:
  47. - void **close** **(** **)**
  48. Close all the add peer connections and channels, freeing all resources.
  49. ----
  50. .. _class_WebRTCMultiplayer_method_get_peer:
  51. - :ref:`Dictionary<class_Dictionary>` **get_peer** **(** :ref:`int<class_int>` peer_id **)**
  52. Return a dictionary representation of the peer with given ``peer_id`` with three keys. ``connection`` containing the :ref:`WebRTCPeerConnection<class_WebRTCPeerConnection>` to this peer, ``channels`` an array of three :ref:`WebRTCDataChannel<class_WebRTCDataChannel>`, and ``connected`` a boolean representing if the peer connection is currently connected (all three channels are open).
  53. ----
  54. .. _class_WebRTCMultiplayer_method_get_peers:
  55. - :ref:`Dictionary<class_Dictionary>` **get_peers** **(** **)**
  56. Returns a dictionary which keys are the peer ids and values the peer representation as in :ref:`get_peer<class_WebRTCMultiplayer_method_get_peer>`.
  57. ----
  58. .. _class_WebRTCMultiplayer_method_has_peer:
  59. - :ref:`bool<class_bool>` **has_peer** **(** :ref:`int<class_int>` peer_id **)**
  60. Returns ``true`` if the given ``peer_id`` is in the peers map (it might not be connected though).
  61. ----
  62. .. _class_WebRTCMultiplayer_method_initialize:
  63. - :ref:`Error<enum_@GlobalScope_Error>` **initialize** **(** :ref:`int<class_int>` peer_id, :ref:`bool<class_bool>` server_compatibility=false **)**
  64. Initialize the multiplayer peer with the given ``peer_id`` (must be between 1 and 2147483647).
  65. If ``server_compatibilty`` is ``false`` (default), the multiplayer peer will be immediately in state :ref:`NetworkedMultiplayerPeer.CONNECTION_CONNECTED<class_NetworkedMultiplayerPeer_constant_CONNECTION_CONNECTED>` and :ref:`NetworkedMultiplayerPeer.connection_succeeded<class_NetworkedMultiplayerPeer_signal_connection_succeeded>` will not be emitted.
  66. If ``server_compatibilty`` is ``true`` the peer will suppress all :ref:`NetworkedMultiplayerPeer.peer_connected<class_NetworkedMultiplayerPeer_signal_peer_connected>` signals until a peer with id :ref:`NetworkedMultiplayerPeer.TARGET_PEER_SERVER<class_NetworkedMultiplayerPeer_constant_TARGET_PEER_SERVER>` connects and then emit :ref:`NetworkedMultiplayerPeer.connection_succeeded<class_NetworkedMultiplayerPeer_signal_connection_succeeded>`. After that the signal :ref:`NetworkedMultiplayerPeer.peer_connected<class_NetworkedMultiplayerPeer_signal_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 :ref:`NetworkedMultiplayerPeer.server_disconnected<class_NetworkedMultiplayerPeer_signal_server_disconnected>` will be emitted and state will become :ref:`NetworkedMultiplayerPeer.CONNECTION_CONNECTED<class_NetworkedMultiplayerPeer_constant_CONNECTION_CONNECTED>`.
  67. ----
  68. .. _class_WebRTCMultiplayer_method_remove_peer:
  69. - void **remove_peer** **(** :ref:`int<class_int>` peer_id **)**
  70. Remove the peer with given ``peer_id`` from the mesh. If the peer was connected, and :ref:`NetworkedMultiplayerPeer.peer_connected<class_NetworkedMultiplayerPeer_signal_peer_connected>` was emitted for it, then :ref:`NetworkedMultiplayerPeer.peer_disconnected<class_NetworkedMultiplayerPeer_signal_peer_disconnected>` will be emitted.
  71. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  72. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  73. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`