summaryrefslogtreecommitdiff
path: root/modules/websocket/websocket_client.cpp
diff options
context:
space:
mode:
authorMax Hilbrunner <mhilbrunner@users.noreply.github.com>2018-09-24 06:29:30 +0200
committerGitHub <noreply@github.com>2018-09-24 06:29:30 +0200
commitaaef640b8c3e7c7c49aae11a1c8c9e606223fefd (patch)
tree384a64093351ad6c8db4e20fcde8b3403404e9fe /modules/websocket/websocket_client.cpp
parent399910ddd82e84f078ebefb3ed2c51d2ef989235 (diff)
parentdf43b94e6ebaad30991e7b909f40cd89aee9d6fd (diff)
Merge pull request #22383 from Faless/ws_close
Implement WebSocket close frame handling
Diffstat (limited to 'modules/websocket/websocket_client.cpp')
-rw-r--r--modules/websocket/websocket_client.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/modules/websocket/websocket_client.cpp b/modules/websocket/websocket_client.cpp
index 7701163085..f9b94dc519 100644
--- a/modules/websocket/websocket_client.cpp
+++ b/modules/websocket/websocket_client.cpp
@@ -107,12 +107,17 @@ void WebSocketClient::_on_connect(String p_protocol) {
}
}
-void WebSocketClient::_on_disconnect() {
+void WebSocketClient::_on_close_request(int p_code, String p_reason) {
+
+ emit_signal("server_close_request", p_code, p_reason);
+}
+
+void WebSocketClient::_on_disconnect(bool p_was_clean) {
if (_is_multiplayer) {
emit_signal("connection_failed");
} else {
- emit_signal("connection_closed");
+ emit_signal("connection_closed", p_was_clean);
}
}
@@ -127,7 +132,7 @@ void WebSocketClient::_on_error() {
void WebSocketClient::_bind_methods() {
ClassDB::bind_method(D_METHOD("connect_to_url", "url", "protocols", "gd_mp_api"), &WebSocketClient::connect_to_url, DEFVAL(PoolVector<String>()), DEFVAL(false));
- ClassDB::bind_method(D_METHOD("disconnect_from_host"), &WebSocketClient::disconnect_from_host);
+ ClassDB::bind_method(D_METHOD("disconnect_from_host", "code", "reason"), &WebSocketClient::disconnect_from_host, DEFVAL(1000), DEFVAL(""));
ClassDB::bind_method(D_METHOD("set_verify_ssl_enabled", "enabled"), &WebSocketClient::set_verify_ssl_enabled);
ClassDB::bind_method(D_METHOD("is_verify_ssl_enabled"), &WebSocketClient::is_verify_ssl_enabled);
@@ -135,6 +140,7 @@ void WebSocketClient::_bind_methods() {
ADD_SIGNAL(MethodInfo("data_received"));
ADD_SIGNAL(MethodInfo("connection_established", PropertyInfo(Variant::STRING, "protocol")));
- ADD_SIGNAL(MethodInfo("connection_closed"));
+ ADD_SIGNAL(MethodInfo("server_close_request", PropertyInfo(Variant::INT, "code"), PropertyInfo(Variant::STRING, "reason")));
+ ADD_SIGNAL(MethodInfo("connection_closed", PropertyInfo(Variant::BOOL, "was_clean_close")));
ADD_SIGNAL(MethodInfo("connection_error"));
}