2018-06-26 14:09:39 +02:00
|
|
|
#include "IrcConnection2.hpp"
|
2018-06-04 21:05:18 +02:00
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
IrcConnection::IrcConnection(QObject *parent)
|
|
|
|
: Communi::IrcConnection(parent)
|
|
|
|
{
|
2018-06-24 12:16:32 +02:00
|
|
|
// send ping every x seconds
|
2018-06-04 21:44:03 +02:00
|
|
|
this->pingTimer_.setInterval(5000);
|
2018-06-04 21:37:19 +02:00
|
|
|
this->pingTimer_.start();
|
|
|
|
QObject::connect(&this->pingTimer_, &QTimer::timeout, [this] {
|
2018-07-16 17:23:41 +02:00
|
|
|
if (this->isConnected()) {
|
|
|
|
if (!this->recentlyReceivedMessage_.load()) {
|
|
|
|
this->sendRaw("PING");
|
|
|
|
this->reconnectTimer_.start();
|
|
|
|
}
|
|
|
|
this->recentlyReceivedMessage_ = false;
|
2018-06-04 21:37:19 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-24 12:16:32 +02:00
|
|
|
// reconnect after x seconds without receiving a message
|
2018-06-04 21:44:03 +02:00
|
|
|
this->reconnectTimer_.setInterval(5000);
|
2018-06-04 21:37:19 +02:00
|
|
|
this->reconnectTimer_.setSingleShot(true);
|
2018-07-16 17:23:41 +02:00
|
|
|
QObject::connect(&this->reconnectTimer_, &QTimer::timeout, [this] {
|
|
|
|
if (this->isConnected()) {
|
|
|
|
reconnectRequested.invoke();
|
|
|
|
}
|
|
|
|
});
|
2018-06-04 21:37:19 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
QObject::connect(this, &Communi::IrcConnection::messageReceived,
|
|
|
|
[this](Communi::IrcMessage *) {
|
|
|
|
this->recentlyReceivedMessage_ = true;
|
2018-06-04 21:37:19 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
if (this->reconnectTimer_.isActive()) {
|
|
|
|
this->reconnectTimer_.stop();
|
|
|
|
}
|
|
|
|
});
|
2018-06-04 21:05:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|