Re-implement WebSocket get host/port.
Was lost during library switch
This commit is contained in:
parent
98497ff719
commit
025cc04d9e
7 changed files with 19 additions and 13 deletions
|
@ -193,12 +193,12 @@ void EMWSClient::disconnect_from_host(int p_code, String p_reason) {
|
|||
|
||||
IP_Address EMWSClient::get_connected_host() const {
|
||||
|
||||
return IP_Address();
|
||||
ERR_FAIL_V_MSG(IP_Address(), "Not supported in HTML5 export.");
|
||||
};
|
||||
|
||||
uint16_t EMWSClient::get_connected_port() const {
|
||||
|
||||
return 1025;
|
||||
ERR_FAIL_V_MSG(0, "Not supported in HTML5 export.");
|
||||
};
|
||||
|
||||
int EMWSClient::get_max_packet_size() const {
|
||||
|
|
|
@ -134,6 +134,8 @@ 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", "code", "reason"), &WebSocketClient::disconnect_from_host, DEFVAL(1000), DEFVAL(""));
|
||||
ClassDB::bind_method(D_METHOD("get_connected_host"), &WebSocketClient::get_connected_host);
|
||||
ClassDB::bind_method(D_METHOD("get_connected_port"), &WebSocketClient::get_connected_port);
|
||||
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);
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ void WSLClient::_do_handshake() {
|
|||
WSLPeer::PeerData *data = memnew(struct WSLPeer::PeerData);
|
||||
data->obj = this;
|
||||
data->conn = _connection;
|
||||
data->tcp = _tcp;
|
||||
data->is_server = false;
|
||||
data->id = 1;
|
||||
_peer->make_context(data, _in_buf_size, _in_pkt_size, _out_buf_size, _out_pkt_size);
|
||||
|
@ -305,12 +306,14 @@ void WSLClient::disconnect_from_host(int p_code, String p_reason) {
|
|||
|
||||
IP_Address WSLClient::get_connected_host() const {
|
||||
|
||||
return IP_Address();
|
||||
ERR_FAIL_COND_V(!_peer->is_connected_to_host(), IP_Address());
|
||||
return _peer->get_connected_host();
|
||||
}
|
||||
|
||||
uint16_t WSLClient::get_connected_port() const {
|
||||
|
||||
return 1025;
|
||||
ERR_FAIL_COND_V(!_peer->is_connected_to_host(), 0);
|
||||
return _peer->get_connected_port();
|
||||
}
|
||||
|
||||
Error WSLClient::set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets) {
|
||||
|
|
|
@ -208,7 +208,6 @@ void WSLPeer::make_context(PeerData *p_data, unsigned int p_in_buf_size, unsigne
|
|||
_data = p_data;
|
||||
_data->peer = this;
|
||||
_data->valid = true;
|
||||
_connection = Ref<StreamPeer>(_data->conn);
|
||||
|
||||
if (_data->is_server)
|
||||
wslay_event_context_server_init(&(_data->ctx), &wsl_callbacks, _data);
|
||||
|
@ -302,18 +301,16 @@ void WSLPeer::close(int p_code, String p_reason) {
|
|||
|
||||
IP_Address WSLPeer::get_connected_host() const {
|
||||
|
||||
ERR_FAIL_COND_V(!is_connected_to_host(), IP_Address());
|
||||
ERR_FAIL_COND_V(!is_connected_to_host() || _data->tcp.is_null(), IP_Address());
|
||||
|
||||
IP_Address ip;
|
||||
return ip;
|
||||
return _data->tcp->get_connected_host();
|
||||
}
|
||||
|
||||
uint16_t WSLPeer::get_connected_port() const {
|
||||
|
||||
ERR_FAIL_COND_V(!is_connected_to_host(), 0);
|
||||
ERR_FAIL_COND_V(!is_connected_to_host() || _data->tcp.is_null(), 0);
|
||||
|
||||
uint16_t port = 0;
|
||||
return port;
|
||||
return _data->tcp->get_connected_port();
|
||||
}
|
||||
|
||||
void WSLPeer::invalidate() {
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
#include "core/error_list.h"
|
||||
#include "core/io/packet_peer.h"
|
||||
#include "core/io/stream_peer_tcp.h"
|
||||
#include "core/ring_buffer.h"
|
||||
#include "packet_buffer.h"
|
||||
#include "websocket_peer.h"
|
||||
|
@ -55,6 +56,7 @@ public:
|
|||
void *obj;
|
||||
void *peer;
|
||||
Ref<StreamPeer> conn;
|
||||
Ref<StreamPeerTCP> tcp;
|
||||
int id;
|
||||
wslay_event_context_ptr ctx;
|
||||
|
||||
|
@ -77,7 +79,6 @@ private:
|
|||
static bool _wsl_poll(struct PeerData *p_data);
|
||||
static void _wsl_destroy(struct PeerData **p_data);
|
||||
|
||||
Ref<StreamPeer> _connection;
|
||||
struct PeerData *_data;
|
||||
uint8_t _is_string;
|
||||
// Our packet info is just a boolean (is_string), using uint8_t for it.
|
||||
|
|
|
@ -185,6 +185,7 @@ void WSLServer::poll() {
|
|||
WSLPeer::PeerData *data = memnew(struct WSLPeer::PeerData);
|
||||
data->obj = this;
|
||||
data->conn = ppeer->connection;
|
||||
data->tcp = ppeer->tcp;
|
||||
data->is_server = true;
|
||||
data->id = id;
|
||||
|
||||
|
@ -204,12 +205,13 @@ void WSLServer::poll() {
|
|||
return;
|
||||
|
||||
while (_server->is_connection_available()) {
|
||||
Ref<StreamPeer> conn = _server->take_connection();
|
||||
Ref<StreamPeerTCP> conn = _server->take_connection();
|
||||
if (is_refusing_new_connections())
|
||||
continue; // Conn will go out-of-scope and be closed.
|
||||
|
||||
Ref<PendingPeer> peer = memnew(PendingPeer);
|
||||
peer->connection = conn;
|
||||
peer->tcp = conn;
|
||||
peer->time = OS::get_singleton()->get_ticks_msec();
|
||||
_pending.push_back(peer);
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ private:
|
|||
bool _parse_request(const PoolStringArray p_protocols);
|
||||
|
||||
public:
|
||||
Ref<StreamPeerTCP> tcp;
|
||||
Ref<StreamPeer> connection;
|
||||
|
||||
int time;
|
||||
|
|
Loading…
Reference in a new issue