:github_url: hide .. Generated automatically by doc/tools/make_rst.py in Godot's source tree. .. DO NOT EDIT THIS FILE, but the WebRTCMultiplayerPeer.xml source instead. .. The source is found in doc/classes or modules//doc_classes. .. _class_WebRTCMultiplayerPeer: WebRTCMultiplayerPeer ===================== **Inherits:** :ref:`MultiplayerPeer` **<** :ref:`PacketPeer` **<** :ref:`RefCounted` **<** :ref:`Object` A simple interface to create a peer-to-peer mesh network composed of :ref:`WebRTCPeerConnection` that is compatible with the :ref:`MultiplayerAPI`. Description ----------- This class constructs a full mesh of :ref:`WebRTCPeerConnection` (one connection for each peer) that can be used as a :ref:`MultiplayerAPI.multiplayer_peer`. You can add each :ref:`WebRTCPeerConnection` via :ref:`add_peer` or remove them via :ref:`remove_peer`. Peers must be added in :ref:`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. \ :ref:`MultiplayerPeer.connection_succeeded` and :ref:`MultiplayerPeer.server_disconnected` will not be emitted unless ``server_compatibility`` is ``true`` in :ref:`initialize`. Beside that data transfer works like in a :ref:`MultiplayerPeer`. \ **Note:** When exporting to Android, make sure to enable the ``INTERNET`` 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. Methods ------- +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`add_peer` **(** :ref:`WebRTCPeerConnection` peer, :ref:`int` peer_id, :ref:`int` unreliable_lifetime=1 **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`close` **(** **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Dictionary` | :ref:`get_peer` **(** :ref:`int` peer_id **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Dictionary` | :ref:`get_peers` **(** **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`has_peer` **(** :ref:`int` peer_id **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`initialize` **(** :ref:`int` peer_id, :ref:`bool` server_compatibility=false, :ref:`Array` channels_config=[] **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`remove_peer` **(** :ref:`int` peer_id **)** | +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Method Descriptions ------------------- .. _class_WebRTCMultiplayerPeer_method_add_peer: - :ref:`Error` **add_peer** **(** :ref:`WebRTCPeerConnection` peer, :ref:`int` peer_id, :ref:`int` unreliable_lifetime=1 **)** Add a new peer to the mesh with the given ``peer_id``. The :ref:`WebRTCPeerConnection` must be in state :ref:`WebRTCPeerConnection.STATE_NEW`. 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_WebRTCMultiplayerPeer_method_close: - void **close** **(** **)** Close all the add peer connections and channels, freeing all resources. ---- .. _class_WebRTCMultiplayerPeer_method_get_peer: - :ref:`Dictionary` **get_peer** **(** :ref:`int` peer_id **)** Returns a dictionary representation of the peer with given ``peer_id`` with three keys. ``connection`` containing the :ref:`WebRTCPeerConnection` to this peer, ``channels`` an array of three :ref:`WebRTCDataChannel`, and ``connected`` a boolean representing if the peer connection is currently connected (all three channels are open). ---- .. _class_WebRTCMultiplayerPeer_method_get_peers: - :ref:`Dictionary` **get_peers** **(** **)** Returns a dictionary which keys are the peer ids and values the peer representation as in :ref:`get_peer`. ---- .. _class_WebRTCMultiplayerPeer_method_has_peer: - :ref:`bool` **has_peer** **(** :ref:`int` peer_id **)** Returns ``true`` if the given ``peer_id`` is in the peers map (it might not be connected though). ---- .. _class_WebRTCMultiplayerPeer_method_initialize: - :ref:`Error` **initialize** **(** :ref:`int` peer_id, :ref:`bool` server_compatibility=false, :ref:`Array` channels_config=[] **)** Initialize the multiplayer peer with the given ``peer_id`` (must be between 1 and 2147483647). If ``server_compatibilty`` is ``false`` (default), the multiplayer peer will be immediately in state :ref:`MultiplayerPeer.CONNECTION_CONNECTED` and :ref:`MultiplayerPeer.connection_succeeded` will not be emitted. If ``server_compatibilty`` is ``true`` the peer will suppress all :ref:`MultiplayerPeer.peer_connected` signals until a peer with id :ref:`MultiplayerPeer.TARGET_PEER_SERVER` connects and then emit :ref:`MultiplayerPeer.connection_succeeded`. After that the signal :ref:`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 :ref:`MultiplayerPeer.server_disconnected` will be emitted and state will become :ref:`MultiplayerPeer.CONNECTION_CONNECTED`. You can optionally specify a ``channels_config`` array of :ref:`TransferMode` which will be used to create extra channels (WebRTC only supports one transfer mode per channel). ---- .. _class_WebRTCMultiplayerPeer_method_remove_peer: - void **remove_peer** **(** :ref:`int` peer_id **)** Remove the peer with given ``peer_id`` from the mesh. If the peer was connected, and :ref:`MultiplayerPeer.peer_connected` was emitted for it, then :ref:`MultiplayerPeer.peer_disconnected` will be emitted. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)` .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`