summaryrefslogtreecommitdiffstats
path: root/modules/websocket/emws_peer.h
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2020-10-23 18:33:20 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2020-11-10 11:42:51 +0100
commite2083871eb57e56fe637c3d8f6647ddb4ff539e0 (patch)
treea58669c68065541e0062f82d7edb45789d8f354f /modules/websocket/emws_peer.h
parent54cda5c3b8622c9168fcd5d1c68964ef7697b27e (diff)
downloadredot-engine-e2083871eb57e56fe637c3d8f6647ddb4ff539e0.tar.gz
[HTML5] Port JavaScript inline code to libraries.
The API is implemented in javascript, and generates C functions that can be called from godot. This allows much cleaner code replacing all `EM_ASM` calls in our C++ code with plain C function calls. This also gets rid of few hacks and comes with few optimizations (e.g. custom cursor shapes should be much faster now).
Diffstat (limited to 'modules/websocket/emws_peer.h')
-rw-r--r--modules/websocket/emws_peer.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/modules/websocket/emws_peer.h b/modules/websocket/emws_peer.h
index c94d7e9148..2291a32bbc 100644
--- a/modules/websocket/emws_peer.h
+++ b/modules/websocket/emws_peer.h
@@ -40,6 +40,18 @@
#include "packet_buffer.h"
#include "websocket_peer.h"
+extern "C" {
+typedef void (*WSOnOpen)(void *p_ref, char *p_protocol);
+typedef void (*WSOnMessage)(void *p_ref, const uint8_t *p_buf, int p_buf_len, int p_is_string);
+typedef void (*WSOnClose)(void *p_ref, int p_code, const char *p_reason, int p_is_clean);
+typedef void (*WSOnError)(void *p_ref);
+
+extern int godot_js_websocket_create(void *p_ref, const char *p_url, const char *p_proto, WSOnOpen p_on_open, WSOnMessage p_on_message, WSOnError p_on_error, WSOnClose p_on_close);
+extern int godot_js_websocket_send(int p_id, const uint8_t *p_buf, int p_buf_len, int p_raw);
+extern void godot_js_websocket_close(int p_id, int p_code, const char *p_reason);
+extern void godot_js_websocket_destroy(int p_id);
+}
+
class EMWSPeer : public WebSocketPeer {
GDCIIMPL(EMWSPeer, WebSocketPeer);
@@ -52,7 +64,7 @@ private:
uint8_t _is_string;
public:
- Error read_msg(uint8_t *p_data, uint32_t p_size, bool p_is_string);
+ Error read_msg(const uint8_t *p_data, uint32_t p_size, bool p_is_string);
void set_sock(int p_sock, unsigned int p_in_buf_size, unsigned int p_in_pkt_size);
virtual int get_available_packet_count() const;
virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size);