]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
Remove duplicate code
authortobtoht <thotbot@protonmail.com>
Thu, 14 Oct 2021 12:42:43 +0000 (14:42 +0200)
committertobtoht <thotbot@protonmail.com>
Thu, 14 Oct 2021 12:42:43 +0000 (14:42 +0200)
src/appcontext.h
src/utils/wsclient.cpp [deleted file]
src/utils/wsclient.h [deleted file]

index 46fd215c9b62612d4056d61f09042de2029ac0d4..ac4db6fdf5f001cdc01fde859ea20cc7380c442d 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "utils/os/whonix.h"
 #include "utils/networking.h"
-#include "utils/wsclient.h"
 #include "utils/FeatherSeed.h"
 #include "utils/daemonrpc.h"
 #include "utils/RestoreHeightLookup.h"
diff --git a/src/utils/wsclient.cpp b/src/utils/wsclient.cpp
deleted file mode 100644 (file)
index d9977f3..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-// SPDX-License-Identifier: BSD-3-Clause
-// Copyright (c) 2020-2021, The Monero Project.
-
-#include <QNetworkAccessManager>
-#include <utility>
-#include "wsclient.h"
-#include "utils/Utils.h"
-
-WSClient::WSClient(QUrl url, QObject *parent)
-    : QObject(parent)
-    , m_url(std::move(url))
-{
-    connect(&webSocket, &QWebSocket::binaryMessageReceived, this, &WSClient::onbinaryMessageReceived);
-    connect(&webSocket, &QWebSocket::connected, this, &WSClient::onConnected);
-    connect(&webSocket, &QWebSocket::disconnected, this, &WSClient::closed);
-    connect(&webSocket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error), this, &WSClient::onError);
-    connect(&m_connectionTimer, &QTimer::timeout, this, &WSClient::checkConnection);
-
-    // Keep websocket connection alive
-    connect(&m_pingTimer, &QTimer::timeout, [this]{
-        if (webSocket.state() == QAbstractSocket::ConnectedState)
-            webSocket.ping();
-    });
-    m_pingTimer.setInterval(30 * 1000);
-    m_pingTimer.start();
-}
-
-void WSClient::sendMsg(const QByteArray &data) {
-    if (webSocket.state() == QAbstractSocket::ConnectedState)
-        webSocket.sendBinaryMessage(data);
-}
-
-void WSClient::onToggleConnect(bool connect) {
-    m_connect = connect;
-    if (m_connect)
-        checkConnection();
-}
-
-void WSClient::start() {
-    // connect & reconnect on errors/close
-#ifdef QT_DEBUG
-    qDebug() << "WebSocket connect:" << m_url.url();
-#endif
-
-    if (m_connect)
-        webSocket.open(m_url);
-
-    if (!m_connectionTimer.isActive()) {
-        m_connectionTimer.start(2000);
-    }
-}
-
-void WSClient::checkConnection() {
-    if (!m_connect)
-        return;
-
-    if (webSocket.state() == QAbstractSocket::UnconnectedState) {
-#ifdef QT_DEBUG
-        qDebug() << "WebSocket reconnect";
-#endif
-        this->start();
-    }
-}
-
-void WSClient::onConnected() {
-#ifdef QT_DEBUG
-    qDebug() << "WebSocket connected";
-#endif
-    emit connectionEstablished();
-}
-
-void WSClient::onError(QAbstractSocket::SocketError error) {
-    qCritical() << "WebSocket error: " << error;
-    auto state = webSocket.state();
-    if (state == QAbstractSocket::ConnectedState || state == QAbstractSocket::ConnectingState)
-        webSocket.abort();
-}
-
-void WSClient::onbinaryMessageReceived(const QByteArray &message) {
-#ifdef QT_DEBUG
-    qDebug() << "WebSocket received:" << message;
-#endif
-    if (!Utils::validateJSON(message)) {
-        qCritical() << "Could not interpret WebSocket message as JSON";
-        return;
-    }
-
-    QJsonDocument doc = QJsonDocument::fromJson(message);
-    QJsonObject object = doc.object();
-    if(!object.contains("cmd") || !object.contains("data")) {
-        qCritical() << "Invalid WebSocket message received";
-        return;
-    }
-
-    emit WSMessage(object);
-}
diff --git a/src/utils/wsclient.h b/src/utils/wsclient.h
deleted file mode 100644 (file)
index 29a7955..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-// SPDX-License-Identifier: BSD-3-Clause
-// Copyright (c) 2020-2021, The Monero Project.
-
-#ifndef FEATHER_WSCLIENT_H
-#define FEATHER_WSCLIENT_H
-
-#include <QObject>
-#include <QtWebSockets/QWebSocket>
-#include <QTimer>
-
-class WSClient : public QObject
-{
-    Q_OBJECT
-
-public:
-    explicit WSClient(QUrl url, QObject *parent = nullptr);
-    void start();
-    void sendMsg(const QByteArray &data);
-    QWebSocket webSocket;
-
-public slots:
-    void onToggleConnect(bool connect);
-
-signals:
-    void closed();
-    void connectionEstablished();
-    void WSMessage(QJsonObject message);
-
-private slots:
-    void onConnected();
-    void onbinaryMessageReceived(const QByteArray &message);
-    void checkConnection();
-    void onError(QAbstractSocket::SocketError error);
-
-private:
-    bool m_connect = false;
-    QUrl m_url;
-    QTimer m_connectionTimer;
-    QTimer m_pingTimer;
-};
-
-#endif // FEATHER_WSCLIENT_H
\ No newline at end of file