mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
added a shitty reconnect implementation
This commit is contained in:
parent
8de0a59533
commit
d9cb8093cb
|
@ -33,6 +33,10 @@ AbstractIrcServer::AbstractIrcServer()
|
|||
[this] { this->onConnected(); });
|
||||
QObject::connect(this->readConnection.get(), &Communi::IrcConnection::disconnected,
|
||||
[this] { this->onDisconnected(); });
|
||||
|
||||
// listen to reconnect request
|
||||
this->readConnection->reconnectRequested.connect([this] { this->connect(); });
|
||||
// this->writeConnection->reconnectRequested.connect([this] { this->connect(); });
|
||||
}
|
||||
|
||||
IrcConnection *AbstractIrcServer::getReadConnection() const
|
||||
|
|
|
@ -7,6 +7,33 @@ namespace irc {
|
|||
IrcConnection::IrcConnection(QObject *parent)
|
||||
: Communi::IrcConnection(parent)
|
||||
{
|
||||
this->pingTimer_.setInterval(10000);
|
||||
this->pingTimer_.start();
|
||||
QObject::connect(&this->pingTimer_, &QTimer::timeout, [this] {
|
||||
if (!this->recentlyReceivedMessage_.load()) {
|
||||
this->sendRaw("PING");
|
||||
this->reconnectTimer_.start();
|
||||
}
|
||||
this->recentlyReceivedMessage_ = false;
|
||||
});
|
||||
|
||||
this->reconnectTimer_.setInterval(10000);
|
||||
this->reconnectTimer_.setSingleShot(true);
|
||||
QObject::connect(&this->reconnectTimer_, &QTimer::timeout,
|
||||
[this] { reconnectRequested.invoke(); });
|
||||
|
||||
QObject::connect(this, &Communi::IrcConnection::messageReceived,
|
||||
[this](Communi::IrcMessage *message) {
|
||||
if (message->command() == "PONG") {
|
||||
qDebug() << "PONG";
|
||||
}
|
||||
this->recentlyReceivedMessage_ = true;
|
||||
|
||||
if (this->reconnectTimer_.isActive()) {
|
||||
this->reconnectTimer_.stop();
|
||||
qDebug() << "reconnect stopped";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace irc
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
|
||||
#include <IrcConnection>
|
||||
#include <QTimer>
|
||||
|
||||
namespace chatterino {
|
||||
namespace providers {
|
||||
|
@ -10,6 +13,13 @@ class IrcConnection : public Communi::IrcConnection
|
|||
{
|
||||
public:
|
||||
IrcConnection(QObject *parent = nullptr);
|
||||
|
||||
pajlada::Signals::NoArgSignal reconnectRequested;
|
||||
|
||||
private:
|
||||
QTimer pingTimer_;
|
||||
QTimer reconnectTimer_;
|
||||
std::atomic<bool> recentlyReceivedMessage_{true};
|
||||
};
|
||||
|
||||
} // namespace irc
|
||||
|
|
Loading…
Reference in a new issue