summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/websocket/editor_debugger_server_websocket.cpp92
-rw-r--r--modules/websocket/editor_debugger_server_websocket.h63
-rw-r--r--modules/websocket/emws_client.cpp5
-rw-r--r--modules/websocket/register_types.cpp24
-rw-r--r--modules/websocket/remote_debugger_peer_websocket.cpp134
-rw-r--r--modules/websocket/remote_debugger_peer_websocket.h66
-rw-r--r--modules/websocket/websocket_macros.h12
-rw-r--r--modules/websocket/wsl_client.cpp8
-rw-r--r--modules/websocket/wsl_server.cpp8
9 files changed, 377 insertions, 35 deletions
diff --git a/modules/websocket/editor_debugger_server_websocket.cpp b/modules/websocket/editor_debugger_server_websocket.cpp
new file mode 100644
index 0000000000..cc8507227e
--- /dev/null
+++ b/modules/websocket/editor_debugger_server_websocket.cpp
@@ -0,0 +1,92 @@
+/*************************************************************************/
+/* script_editor_debugger_websocket.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "editor_debugger_server_websocket.h"
+
+#include "core/project_settings.h"
+#include "editor/editor_settings.h"
+#include "modules/websocket/remote_debugger_peer_websocket.h"
+
+void EditorDebuggerServerWebSocket::_peer_connected(int p_id, String _protocol) {
+ pending_peers.push_back(p_id);
+}
+
+void EditorDebuggerServerWebSocket::_peer_disconnected(int p_id, bool p_was_clean) {
+ if (pending_peers.find(p_id))
+ pending_peers.erase(p_id);
+}
+
+void EditorDebuggerServerWebSocket::poll() {
+ server->poll();
+}
+
+Error EditorDebuggerServerWebSocket::start() {
+ int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
+ Vector<String> protocols;
+ protocols.push_back("binary"); // compatibility with EMSCRIPTEN TCP-to-WebSocket layer.
+ return server->listen(remote_port, protocols);
+}
+
+void EditorDebuggerServerWebSocket::stop() {
+ server->stop();
+ pending_peers.clear();
+}
+
+bool EditorDebuggerServerWebSocket::is_active() const {
+ return server->is_listening();
+}
+
+bool EditorDebuggerServerWebSocket::is_connection_available() const {
+ return pending_peers.size() > 0;
+}
+
+Ref<RemoteDebuggerPeer> EditorDebuggerServerWebSocket::take_connection() {
+ ERR_FAIL_COND_V(!is_connection_available(), Ref<RemoteDebuggerPeer>());
+ RemoteDebuggerPeer *peer = memnew(RemoteDebuggerPeerWebSocket(server->get_peer(pending_peers[0])));
+ pending_peers.pop_front();
+ return peer;
+}
+
+EditorDebuggerServerWebSocket::EditorDebuggerServerWebSocket() {
+ server = Ref<WebSocketServer>(WebSocketServer::create());
+ int max_pkts = (int)GLOBAL_GET("network/limits/debugger/max_queued_messages");
+ server->set_buffers(8192, max_pkts, 8192, max_pkts);
+ server->connect("client_connected", callable_mp(this, &EditorDebuggerServerWebSocket::_peer_connected));
+ server->connect("client_disconnected", callable_mp(this, &EditorDebuggerServerWebSocket::_peer_disconnected));
+}
+
+EditorDebuggerServerWebSocket::~EditorDebuggerServerWebSocket() {
+ stop();
+}
+
+EditorDebuggerServer *EditorDebuggerServerWebSocket::create(const String &p_protocol) {
+ ERR_FAIL_COND_V(p_protocol != "ws://", NULL);
+ return memnew(EditorDebuggerServerWebSocket);
+}
diff --git a/modules/websocket/editor_debugger_server_websocket.h b/modules/websocket/editor_debugger_server_websocket.h
new file mode 100644
index 0000000000..81a31d8364
--- /dev/null
+++ b/modules/websocket/editor_debugger_server_websocket.h
@@ -0,0 +1,63 @@
+/*************************************************************************/
+/* script_editor_debugger_websocket.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef SCRIPT_EDITOR_DEBUGGER_WEBSOCKET_H
+#define SCRIPT_EDITOR_DEBUGGER_WEBSOCKET_H
+
+#include "modules/websocket/websocket_server.h"
+
+#include "editor/debugger/editor_debugger_server.h"
+
+class EditorDebuggerServerWebSocket : public EditorDebuggerServer {
+
+ GDCLASS(EditorDebuggerServerWebSocket, EditorDebuggerServer);
+
+private:
+ Ref<WebSocketServer> server;
+ List<int> pending_peers;
+
+public:
+ static EditorDebuggerServer *create(const String &p_protocol);
+
+ void _peer_connected(int p_peer, String p_protocol);
+ void _peer_disconnected(int p_peer, bool p_was_clean);
+
+ void poll();
+ Error start();
+ void stop();
+ bool is_active() const;
+ bool is_connection_available() const;
+ Ref<RemoteDebuggerPeer> take_connection();
+
+ EditorDebuggerServerWebSocket();
+ ~EditorDebuggerServerWebSocket();
+};
+
+#endif // SCRIPT_EDITOR_DEBUGGER_WEBSOCKET_H
diff --git a/modules/websocket/emws_client.cpp b/modules/websocket/emws_client.cpp
index bceb65c315..bc9d75d327 100644
--- a/modules/websocket/emws_client.cpp
+++ b/modules/websocket/emws_client.cpp
@@ -231,8 +231,9 @@ Error EMWSClient::set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffe
}
EMWSClient::EMWSClient() {
- _in_buf_size = nearest_shift((int)GLOBAL_GET(WSC_IN_BUF) - 1) + 10;
- _in_pkt_size = nearest_shift((int)GLOBAL_GET(WSC_IN_PKT) - 1);
+ _in_buf_size = DEF_BUF_SHIFT;
+ _in_pkt_size = DEF_PKT_SHIFT;
+
_is_connecting = false;
_peer = Ref<EMWSPeer>(memnew(EMWSPeer));
/* clang-format off */
diff --git a/modules/websocket/register_types.cpp b/modules/websocket/register_types.cpp
index e389d75ffd..1ad249e1eb 100644
--- a/modules/websocket/register_types.cpp
+++ b/modules/websocket/register_types.cpp
@@ -40,24 +40,12 @@
#include "wsl_client.h"
#include "wsl_server.h"
#endif
+#ifdef TOOLS_ENABLED
+#include "editor/debugger/editor_debugger_server.h"
+#include "editor_debugger_server_websocket.h"
+#endif
void register_websocket_types() {
-#define _SET_HINT(NAME, _VAL_, _MAX_) \
- GLOBAL_DEF(NAME, _VAL_); \
- ProjectSettings::get_singleton()->set_custom_property_info(NAME, PropertyInfo(Variant::INT, NAME, PROPERTY_HINT_RANGE, "2," #_MAX_ ",1,or_greater"));
-
- // Client buffers project settings
- _SET_HINT(WSC_IN_BUF, 64, 4096);
- _SET_HINT(WSC_IN_PKT, 1024, 16384);
- _SET_HINT(WSC_OUT_BUF, 64, 4096);
- _SET_HINT(WSC_OUT_PKT, 1024, 16384);
-
- // Server buffers project settings
- _SET_HINT(WSS_IN_BUF, 64, 4096);
- _SET_HINT(WSS_IN_PKT, 1024, 16384);
- _SET_HINT(WSS_OUT_BUF, 64, 4096);
- _SET_HINT(WSS_OUT_PKT, 1024, 16384);
-
#ifdef JAVASCRIPT_ENABLED
EMWSPeer::make_default();
EMWSClient::make_default();
@@ -72,6 +60,10 @@ void register_websocket_types() {
ClassDB::register_custom_instance_class<WebSocketServer>();
ClassDB::register_custom_instance_class<WebSocketClient>();
ClassDB::register_custom_instance_class<WebSocketPeer>();
+
+#ifdef TOOLS_ENABLED
+ EditorDebuggerServer::register_protocol_handler("ws://", EditorDebuggerServerWebSocket::create);
+#endif
}
void unregister_websocket_types() {}
diff --git a/modules/websocket/remote_debugger_peer_websocket.cpp b/modules/websocket/remote_debugger_peer_websocket.cpp
new file mode 100644
index 0000000000..f132b58e05
--- /dev/null
+++ b/modules/websocket/remote_debugger_peer_websocket.cpp
@@ -0,0 +1,134 @@
+/*************************************************************************/
+/* script_debugger_websocket.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "remote_debugger_peer_websocket.h"
+
+#include "core/project_settings.h"
+
+Error RemoteDebuggerPeerWebSocket::connect_to_host(const String &p_uri) {
+
+ Vector<String> protocols;
+ protocols.push_back("binary"); // Compatibility for emscripten TCP-to-WebSocket.
+
+ ws_client->connect_to_url(p_uri, protocols);
+ ws_client->poll();
+
+ if (ws_client->get_connection_status() == WebSocketClient::CONNECTION_DISCONNECTED) {
+
+ ERR_PRINT("Remote Debugger: Unable to connect. Status: " + String::num(ws_client->get_connection_status()) + ".");
+ return FAILED;
+ }
+
+ ws_peer = ws_client->get_peer(1);
+
+ return OK;
+}
+
+bool RemoteDebuggerPeerWebSocket::is_peer_connected() {
+ return ws_peer.is_valid() && ws_peer->is_connected_to_host();
+}
+
+void RemoteDebuggerPeerWebSocket::poll() {
+ ws_client->poll();
+
+ while (ws_peer->is_connected_to_host() && ws_peer->get_available_packet_count() > 0 && in_queue.size() < max_queued_messages) {
+ Variant var;
+ Error err = ws_peer->get_var(var);
+ ERR_CONTINUE(err != OK);
+ ERR_CONTINUE(var.get_type() != Variant::ARRAY);
+ in_queue.push_back(var);
+ }
+
+ while (ws_peer->is_connected_to_host() && out_queue.size() > 0) {
+ Array var = out_queue[0];
+ Error err = ws_peer->put_var(var);
+ ERR_BREAK(err != OK); // Peer buffer full?
+ out_queue.pop_front();
+ }
+}
+
+int RemoteDebuggerPeerWebSocket::get_max_message_size() const {
+ return 8 << 20; // 8 Mib
+}
+
+bool RemoteDebuggerPeerWebSocket::has_message() {
+ return in_queue.size() > 0;
+}
+
+Array RemoteDebuggerPeerWebSocket::get_message() {
+ ERR_FAIL_COND_V(in_queue.size() < 1, Array());
+ Array msg = in_queue[0];
+ in_queue.pop_front();
+ return msg;
+}
+
+Error RemoteDebuggerPeerWebSocket::put_message(const Array &p_arr) {
+ if (out_queue.size() >= max_queued_messages)
+ return ERR_OUT_OF_MEMORY;
+ out_queue.push_back(p_arr);
+ return OK;
+}
+
+void RemoteDebuggerPeerWebSocket::close() {
+ if (ws_peer.is_valid()) {
+ ws_peer.unref();
+ }
+ ws_client->disconnect_from_host();
+}
+
+bool RemoteDebuggerPeerWebSocket::can_block() const {
+#ifdef JAVASCRIPT_ENABLED
+ return false;
+#else
+ return true;
+#endif
+}
+
+RemoteDebuggerPeerWebSocket::RemoteDebuggerPeerWebSocket(Ref<WebSocketPeer> p_peer) {
+#ifdef JAVASCRIPT_ENABLED
+ ws_client = Ref<WebSocketClient>(memnew(EMWSClient));
+#else
+ ws_client = Ref<WebSocketClient>(memnew(WSLClient));
+#endif
+ max_queued_messages = (int)GLOBAL_GET("network/limits/debugger/max_queued_messages");
+ ws_client->set_buffers(8192, max_queued_messages, 8192, max_queued_messages);
+ ws_peer = p_peer;
+}
+
+RemoteDebuggerPeer *RemoteDebuggerPeerWebSocket::create(const String &p_uri) {
+ ERR_FAIL_COND_V(!p_uri.begins_with("ws://") && !p_uri.begins_with("wss://"), NULL);
+ RemoteDebuggerPeerWebSocket *peer = memnew(RemoteDebuggerPeerWebSocket);
+ Error err = peer->connect_to_host(p_uri);
+ if (err != OK) {
+ memdelete(peer);
+ return NULL;
+ }
+ return peer;
+}
diff --git a/modules/websocket/remote_debugger_peer_websocket.h b/modules/websocket/remote_debugger_peer_websocket.h
new file mode 100644
index 0000000000..fe46533bed
--- /dev/null
+++ b/modules/websocket/remote_debugger_peer_websocket.h
@@ -0,0 +1,66 @@
+/*************************************************************************/
+/* script_debugger_websocket.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef SCRIPT_DEBUGGER_WEBSOCKET_H
+#define SCRIPT_DEBUGGER_WEBSOCKET_H
+
+#ifdef JAVASCRIPT_ENABLED
+#include "modules/websocket/emws_client.h"
+#else
+#include "modules/websocket/wsl_client.h"
+#endif
+#include "core/debugger/remote_debugger_peer.h"
+
+class RemoteDebuggerPeerWebSocket : public RemoteDebuggerPeer {
+
+ Ref<WebSocketClient> ws_client;
+ Ref<WebSocketPeer> ws_peer;
+ List<Array> in_queue;
+ List<Array> out_queue;
+
+ int max_queued_messages;
+
+public:
+ static RemoteDebuggerPeer *create(const String &p_uri);
+
+ Error connect_to_host(const String &p_uri);
+ bool is_peer_connected();
+ int get_max_message_size() const;
+ bool has_message();
+ Error put_message(const Array &p_arr);
+ Array get_message();
+ void close();
+ void poll();
+ bool can_block() const;
+
+ RemoteDebuggerPeerWebSocket(Ref<WebSocketPeer> p_peer = Ref<WebSocketPeer>());
+};
+
+#endif // SCRIPT_DEBUGGER_WEBSOCKET_H
diff --git a/modules/websocket/websocket_macros.h b/modules/websocket/websocket_macros.h
index f7eafcff1f..cf4545b435 100644
--- a/modules/websocket/websocket_macros.h
+++ b/modules/websocket/websocket_macros.h
@@ -31,15 +31,9 @@
#ifndef WEBSOCKETMACTOS_H
#define WEBSOCKETMACTOS_H
-#define WSC_IN_BUF "network/limits/websocket_client/max_in_buffer_kb"
-#define WSC_IN_PKT "network/limits/websocket_client/max_in_packets"
-#define WSC_OUT_BUF "network/limits/websocket_client/max_out_buffer_kb"
-#define WSC_OUT_PKT "network/limits/websocket_client/max_out_packets"
-
-#define WSS_IN_BUF "network/limits/websocket_server/max_in_buffer_kb"
-#define WSS_IN_PKT "network/limits/websocket_server/max_in_packets"
-#define WSS_OUT_BUF "network/limits/websocket_server/max_out_buffer_kb"
-#define WSS_OUT_PKT "network/limits/websocket_server/max_out_packets"
+// Defaults per peer buffers, 1024 packets with a shared 65536 bytes payload.
+#define DEF_PKT_SHIFT 10
+#define DEF_BUF_SHIFT 16
/* clang-format off */
#define GDCICLASS(CNAME) \
diff --git a/modules/websocket/wsl_client.cpp b/modules/websocket/wsl_client.cpp
index 9f05500eb9..0eaafe2d66 100644
--- a/modules/websocket/wsl_client.cpp
+++ b/modules/websocket/wsl_client.cpp
@@ -336,10 +336,10 @@ Error WSLClient::set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer
}
WSLClient::WSLClient() {
- _in_buf_size = nearest_shift((int)GLOBAL_GET(WSC_IN_BUF) - 1) + 10;
- _in_pkt_size = nearest_shift((int)GLOBAL_GET(WSC_IN_PKT) - 1);
- _out_buf_size = nearest_shift((int)GLOBAL_GET(WSC_OUT_BUF) - 1) + 10;
- _out_pkt_size = nearest_shift((int)GLOBAL_GET(WSC_OUT_PKT) - 1);
+ _in_buf_size = DEF_BUF_SHIFT;
+ _in_pkt_size = DEF_PKT_SHIFT;
+ _out_buf_size = DEF_BUF_SHIFT;
+ _out_pkt_size = DEF_PKT_SHIFT;
_peer.instance();
_tcp.instance();
diff --git a/modules/websocket/wsl_server.cpp b/modules/websocket/wsl_server.cpp
index 6f155a6ffa..cc4685973e 100644
--- a/modules/websocket/wsl_server.cpp
+++ b/modules/websocket/wsl_server.cpp
@@ -298,10 +298,10 @@ Error WSLServer::set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer
}
WSLServer::WSLServer() {
- _in_buf_size = nearest_shift((int)GLOBAL_GET(WSS_IN_BUF) - 1) + 10;
- _in_pkt_size = nearest_shift((int)GLOBAL_GET(WSS_IN_PKT) - 1);
- _out_buf_size = nearest_shift((int)GLOBAL_GET(WSS_OUT_BUF) - 1) + 10;
- _out_pkt_size = nearest_shift((int)GLOBAL_GET(WSS_OUT_PKT) - 1);
+ _in_buf_size = DEF_BUF_SHIFT;
+ _in_pkt_size = DEF_PKT_SHIFT;
+ _out_buf_size = DEF_BUF_SHIFT;
+ _out_pkt_size = DEF_PKT_SHIFT;
_server.instance();
}