WebSocketClient.xml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="WebSocketClient" inherits="WebSocketMultiplayerPeer" version="3.2">
  3. <brief_description>
  4. A WebSocket client implementation.
  5. </brief_description>
  6. <description>
  7. This class implements a WebSocket client compatible with any RFC 6455-compliant WebSocket server.
  8. This client can be optionally used as a network peer for the [MultiplayerAPI].
  9. After starting the client ([method connect_to_url]), you will need to [method NetworkedMultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]).
  10. You will receive appropriate signals when connecting, disconnecting, or when new data is available.
  11. </description>
  12. <tutorials>
  13. </tutorials>
  14. <methods>
  15. <method name="connect_to_url">
  16. <return type="int" enum="Error">
  17. </return>
  18. <argument index="0" name="url" type="String">
  19. </argument>
  20. <argument index="1" name="protocols" type="PoolStringArray" default="PoolStringArray( )">
  21. </argument>
  22. <argument index="2" name="gd_mp_api" type="bool" default="false">
  23. </argument>
  24. <argument index="3" name="custom_headers" type="PoolStringArray" default="PoolStringArray( )">
  25. </argument>
  26. <description>
  27. Connects to the given URL requesting one of the given [code]protocols[/code] as sub-protocol. If the list empty (default), no sub-protocol will be requested.
  28. If [code]true[/code] is passed as [code]gd_mp_api[/code], the client will behave like a network peer for the [MultiplayerAPI], connections to non-Godot servers will not work, and [signal data_received] will not be emitted.
  29. If [code]false[/code] is passed instead (default), you must call [PacketPeer] functions ([code]put_packet[/code], [code]get_packet[/code], etc.) on the [WebSocketPeer] returned via [code]get_peer(1)[/code] and not on this object directly (e.g. [code]get_peer(1).put_packet(data)[/code]).
  30. You can optionally pass a list of [code]custom_headers[/code] to be added to the handshake HTTP request.
  31. [b]Note:[/b] Specifying [code]custom_headers[/code] is not supported in HTML5 exports due to browsers restrictions.
  32. </description>
  33. </method>
  34. <method name="disconnect_from_host">
  35. <return type="void">
  36. </return>
  37. <argument index="0" name="code" type="int" default="1000">
  38. </argument>
  39. <argument index="1" name="reason" type="String" default="&quot;&quot;">
  40. </argument>
  41. <description>
  42. Disconnects this client from the connected host. See [method WebSocketPeer.close] for more information.
  43. </description>
  44. </method>
  45. <method name="get_connected_host" qualifiers="const">
  46. <return type="String">
  47. </return>
  48. <description>
  49. Return the IP address of the currently connected host.
  50. </description>
  51. </method>
  52. <method name="get_connected_port" qualifiers="const">
  53. <return type="int">
  54. </return>
  55. <description>
  56. Return the IP port of the currently connected host.
  57. </description>
  58. </method>
  59. </methods>
  60. <members>
  61. <member name="trusted_ssl_certificate" type="X509Certificate" setter="set_trusted_ssl_certificate" getter="get_trusted_ssl_certificate">
  62. If specified, this [X509Certificate] will be the only one accepted when connecting to an SSL host. Any other certificate provided by the server will be regarded as invalid.
  63. [b]Note:[/b] Specifying a custom [code]trusted_ssl_certificate[/code] is not supported in HTML5 exports due to browsers restrictions.
  64. </member>
  65. <member name="verify_ssl" type="bool" setter="set_verify_ssl_enabled" getter="is_verify_ssl_enabled">
  66. If [code]true[/code], SSL certificate verification is enabled.
  67. [b]Note:[/b] You must specify the certificates to be used in the Project Settings for it to work when exported.
  68. </member>
  69. </members>
  70. <signals>
  71. <signal name="connection_closed">
  72. <argument index="0" name="was_clean_close" type="bool">
  73. </argument>
  74. <description>
  75. Emitted when the connection to the server is closed. [code]was_clean_close[/code] will be [code]true[/code] if the connection was shutdown cleanly.
  76. </description>
  77. </signal>
  78. <signal name="connection_error">
  79. <description>
  80. Emitted when the connection to the server fails.
  81. </description>
  82. </signal>
  83. <signal name="connection_established">
  84. <argument index="0" name="protocol" type="String">
  85. </argument>
  86. <description>
  87. Emitted when a connection with the server is established, [code]protocol[/code] will contain the sub-protocol agreed with the server.
  88. </description>
  89. </signal>
  90. <signal name="data_received">
  91. <description>
  92. Emitted when a WebSocket message is received.
  93. [b]Note:[/b] This signal is [i]not[/i] emitted when used as high-level multiplayer peer.
  94. </description>
  95. </signal>
  96. <signal name="server_close_request">
  97. <argument index="0" name="code" type="int">
  98. </argument>
  99. <argument index="1" name="reason" type="String">
  100. </argument>
  101. <description>
  102. Emitted when the server requests a clean close. You should keep polling until you get a [signal connection_closed] signal to achieve the clean close. See [method WebSocketPeer.close] for more details.
  103. </description>
  104. </signal>
  105. </signals>
  106. <constants>
  107. </constants>
  108. </class>