Merge pull request 'Websocket: keep connection alive' (#247) from tobtoht/feather:websocket_keepalive into master

Reviewed-on: https://git.wownero.com/feather/feather/pulls/247
This commit is contained in:
tobtoht 2020-12-22 23:11:56 +00:00
commit 900a9b3fac
2 changed files with 9 additions and 0 deletions

View file

@ -21,6 +21,14 @@ WSClient::WSClient(AppContext *ctx, const QUrl &url, QObject *parent) :
connect(&this->webSocket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error), this, &WSClient::onError);
m_tor = url.host().endsWith(".onion");
// Keep websocket connection alive
connect(&m_pingTimer, &QTimer::timeout, [this]{
if (this->webSocket.state() == QAbstractSocket::ConnectedState)
this->webSocket.ping();
});
m_pingTimer.setInterval(30 * 1000);
m_pingTimer.start();
}
void WSClient::sendMsg(const QByteArray &data) {

View file

@ -33,6 +33,7 @@ private slots:
private:
QTimer m_connectionTimer;
QTimer m_pingTimer;
AppContext *m_ctx;
bool m_tor = true;
};