mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-27 16:16:35 +03:00
restart ra ws on timeout
This commit is contained in:
@@ -34,6 +34,7 @@ void RemoteAuthClient::Stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_connected = false;
|
m_connected = false;
|
||||||
|
if (m_timeout_conn) m_timeout_conn.disconnect();
|
||||||
m_ws.Stop(1000);
|
m_ws.Stop(1000);
|
||||||
m_heartbeat_waiter.kill();
|
m_heartbeat_waiter.kill();
|
||||||
if (m_heartbeat_thread.joinable()) m_heartbeat_thread.join();
|
if (m_heartbeat_thread.joinable()) m_heartbeat_thread.join();
|
||||||
@@ -44,6 +45,7 @@ bool RemoteAuthClient::IsConnected() const noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RemoteAuthClient::OnGatewayMessage(const std::string &str) {
|
void RemoteAuthClient::OnGatewayMessage(const std::string &str) {
|
||||||
|
m_log->trace(str);
|
||||||
auto j = nlohmann::json::parse(str);
|
auto j = nlohmann::json::parse(str);
|
||||||
const auto opcode = j.at("op").get<std::string>();
|
const auto opcode = j.at("op").get<std::string>();
|
||||||
if (opcode == "hello") {
|
if (opcode == "hello") {
|
||||||
@@ -67,6 +69,8 @@ void RemoteAuthClient::HandleGatewayHello(const nlohmann::json &j) {
|
|||||||
m_heartbeat_msec = heartbeat_interval;
|
m_heartbeat_msec = heartbeat_interval;
|
||||||
m_heartbeat_thread = std::thread(&RemoteAuthClient::HeartbeatThread, this);
|
m_heartbeat_thread = std::thread(&RemoteAuthClient::HeartbeatThread, this);
|
||||||
|
|
||||||
|
m_timeout_conn = Glib::signal_timeout().connect(sigc::mem_fun(*this, &RemoteAuthClient::OnTimeout), timeout_ms);
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
m_signal_hello.emit();
|
m_signal_hello.emit();
|
||||||
@@ -294,6 +298,13 @@ void RemoteAuthClient::OnDispatch() {
|
|||||||
OnGatewayMessage(msg);
|
OnGatewayMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RemoteAuthClient::OnTimeout() {
|
||||||
|
m_log->trace("Socket timeout");
|
||||||
|
Stop();
|
||||||
|
Start();
|
||||||
|
return false; // disconnect
|
||||||
|
}
|
||||||
|
|
||||||
RemoteAuthClient::type_signal_hello RemoteAuthClient::signal_hello() {
|
RemoteAuthClient::type_signal_hello RemoteAuthClient::signal_hello() {
|
||||||
return m_signal_hello;
|
return m_signal_hello;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ private:
|
|||||||
|
|
||||||
void OnDispatch();
|
void OnDispatch();
|
||||||
|
|
||||||
|
bool OnTimeout();
|
||||||
|
sigc::connection m_timeout_conn;
|
||||||
|
|
||||||
Websocket m_ws;
|
Websocket m_ws;
|
||||||
bool m_connected = false;
|
bool m_connected = false;
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ void RemoteAuthDialog::OnFingerprint(const std::string &fingerprint) {
|
|||||||
m_image.property_pixbuf() = pb;
|
m_image.property_pixbuf() = pb;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteAuthDialog::OnPendingTicket(Snowflake user_id, std::string discriminator, std::string avatar_hash, std::string username) {
|
void RemoteAuthDialog::OnPendingTicket(Snowflake user_id, const std::string &discriminator, const std::string &avatar_hash, const std::string &username) {
|
||||||
Glib::ustring name = username;
|
Glib::ustring name = username;
|
||||||
if (discriminator != "0") {
|
if (discriminator != "0") {
|
||||||
name += "#" + discriminator;
|
name += "#" + discriminator;
|
||||||
@@ -119,6 +119,6 @@ void RemoteAuthDialog::OnToken(const std::string &token) {
|
|||||||
|
|
||||||
void RemoteAuthDialog::OnError(const std::string &error) {
|
void RemoteAuthDialog::OnError(const std::string &error) {
|
||||||
m_ra.Stop();
|
m_ra.Stop();
|
||||||
Abaddon::Get().ShowConfirm(error, dynamic_cast<Gtk::Window*>(get_toplevel()));
|
Abaddon::Get().ShowConfirm(error, dynamic_cast<Gtk::Window *>(get_toplevel()));
|
||||||
response(Gtk::RESPONSE_CANCEL);
|
response(Gtk::RESPONSE_CANCEL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ private:
|
|||||||
|
|
||||||
void OnHello();
|
void OnHello();
|
||||||
void OnFingerprint(const std::string &fingerprint);
|
void OnFingerprint(const std::string &fingerprint);
|
||||||
void OnPendingTicket(Snowflake user_id, std::string discriminator, std::string avatar_hash, std::string username);
|
void OnPendingTicket(Snowflake user_id, const std::string &discriminator, const std::string &avatar_hash, const std::string &username);
|
||||||
void OnPendingLogin();
|
void OnPendingLogin();
|
||||||
void OnToken(const std::string &token);
|
void OnToken(const std::string &token);
|
||||||
void OnError(const std::string &error);
|
void OnError(const std::string &error);
|
||||||
|
|||||||
Reference in New Issue
Block a user