Fix EMWSClient::get_connection_status(), try catch
(cherry picked from commit ebeeb67224
)
This commit is contained in:
parent
06344ac10d
commit
50763ecac4
|
@ -91,10 +91,14 @@ Error EMWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port,
|
||||||
int peer_sock = EM_ASM_INT({
|
int peer_sock = EM_ASM_INT({
|
||||||
var proto_str = UTF8ToString($2);
|
var proto_str = UTF8ToString($2);
|
||||||
var socket = null;
|
var socket = null;
|
||||||
if (proto_str) {
|
try {
|
||||||
socket = new WebSocket(UTF8ToString($1), proto_str.split(","));
|
if (proto_str) {
|
||||||
} else {
|
socket = new WebSocket(UTF8ToString($1), proto_str.split(","));
|
||||||
socket = new WebSocket(UTF8ToString($1));
|
} else {
|
||||||
|
socket = new WebSocket(UTF8ToString($1));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
var c_ptr = Module.IDHandler.get($0);
|
var c_ptr = Module.IDHandler.get($0);
|
||||||
socket.binaryType = "arraybuffer";
|
socket.binaryType = "arraybuffer";
|
||||||
|
@ -174,6 +178,8 @@ Error EMWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port,
|
||||||
return Module.IDHandler.add(socket);
|
return Module.IDHandler.add(socket);
|
||||||
}, _js_id, str.utf8().get_data(), proto_string.utf8().get_data());
|
}, _js_id, str.utf8().get_data(), proto_string.utf8().get_data());
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
if (peer_sock == -1)
|
||||||
|
return FAILED;
|
||||||
|
|
||||||
static_cast<Ref<EMWSPeer> >(_peer)->set_sock(peer_sock, _in_buf_size, _in_pkt_size);
|
static_cast<Ref<EMWSPeer> >(_peer)->set_sock(peer_sock, _in_buf_size, _in_pkt_size);
|
||||||
|
|
||||||
|
@ -190,11 +196,11 @@ Ref<WebSocketPeer> EMWSClient::get_peer(int p_peer_id) const {
|
||||||
|
|
||||||
NetworkedMultiplayerPeer::ConnectionStatus EMWSClient::get_connection_status() const {
|
NetworkedMultiplayerPeer::ConnectionStatus EMWSClient::get_connection_status() const {
|
||||||
|
|
||||||
if (_peer->is_connected_to_host())
|
if (_peer->is_connected_to_host()) {
|
||||||
|
if (_is_connecting)
|
||||||
|
return CONNECTION_CONNECTING;
|
||||||
return CONNECTION_CONNECTED;
|
return CONNECTION_CONNECTED;
|
||||||
|
}
|
||||||
if (_is_connecting)
|
|
||||||
return CONNECTION_CONNECTING;
|
|
||||||
|
|
||||||
return CONNECTION_DISCONNECTED;
|
return CONNECTION_DISCONNECTED;
|
||||||
};
|
};
|
||||||
|
|
|
@ -68,12 +68,17 @@ Error EMWSPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
|
||||||
bytes_array[i] = getValue($1+i, 'i8');
|
bytes_array[i] = getValue($1+i, 'i8');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($3) {
|
try {
|
||||||
sock.send(bytes_array.buffer);
|
if ($3) {
|
||||||
} else {
|
sock.send(bytes_array.buffer);
|
||||||
var string = new TextDecoder("utf-8").decode(bytes_array);
|
} else {
|
||||||
sock.send(string);
|
var string = new TextDecoder("utf-8").decode(bytes_array);
|
||||||
|
sock.send(string);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}, peer_sock, p_buffer, p_buffer_size, is_bin);
|
}, peer_sock, p_buffer, p_buffer_size, is_bin);
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue