2021-05-02 18:22:38 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2023-01-02 19:30:11 +00:00
|
|
|
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
|
2021-05-02 18:22:38 +00:00
|
|
|
|
|
|
|
#ifndef FEATHER_WEBSOCKETCLIENT_H
|
|
|
|
#define FEATHER_WEBSOCKETCLIENT_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QWebSocket>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QPointer>
|
2021-05-18 15:59:18 +00:00
|
|
|
#include "constants.h"
|
2021-05-02 18:22:38 +00:00
|
|
|
|
|
|
|
class WebsocketClient : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit WebsocketClient(QObject *parent = nullptr);
|
2022-03-11 15:03:06 +00:00
|
|
|
~WebsocketClient() override;
|
2021-05-02 18:22:38 +00:00
|
|
|
void start();
|
2022-03-04 21:55:29 +00:00
|
|
|
void restart();
|
|
|
|
void stop();
|
2021-05-02 18:22:38 +00:00
|
|
|
void sendMsg(const QByteArray &data);
|
|
|
|
|
|
|
|
QWebSocket webSocket;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void connectionEstablished();
|
|
|
|
void WSMessage(QJsonObject message);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void onConnected();
|
2021-10-14 13:41:14 +00:00
|
|
|
void onDisconnected();
|
2022-02-23 23:42:06 +00:00
|
|
|
void onStateChanged(QAbstractSocket::SocketState state);
|
2021-05-02 18:22:38 +00:00
|
|
|
void onbinaryMessageReceived(const QByteArray &message);
|
|
|
|
void onError(QAbstractSocket::SocketError error);
|
2022-02-23 23:42:06 +00:00
|
|
|
void nextWebsocketUrl();
|
|
|
|
void onConnectionTimeout();
|
2021-05-02 18:22:38 +00:00
|
|
|
|
|
|
|
private:
|
2022-02-23 23:42:06 +00:00
|
|
|
QUrl m_url;
|
2021-05-02 18:22:38 +00:00
|
|
|
QTimer m_pingTimer;
|
2022-02-23 23:42:06 +00:00
|
|
|
QTimer m_connectionTimeout;
|
|
|
|
int m_timeout = 10;
|
|
|
|
int m_websocketUrlIndex = 0;
|
2022-03-04 21:55:29 +00:00
|
|
|
bool m_stopped = false;
|
2021-05-02 18:22:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //FEATHER_WEBSOCKETCLIENT_H
|