diff options
Diffstat (limited to 'app/qafbwsclient.h')
-rw-r--r-- | app/qafbwsclient.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/app/qafbwsclient.h b/app/qafbwsclient.h new file mode 100644 index 0000000..2576ecb --- /dev/null +++ b/app/qafbwsclient.h @@ -0,0 +1,50 @@ +#ifndef QAFBWSCLIENT_H +#define QAFBWSCLIENT_H + +#include <QObject> +#include <QMap> +#include <QSharedPointer> +#include <QWebSocket> +#include <QJsonValue> + +enum class AfMsgType + : int +{ + Call = 2, + RetOk = 3, + RetErr = 4, + Event = 5 +}; + +class QAfbWsMsg; + +class QAfbWsClient + : public QObject +{ + Q_OBJECT +public: + explicit QAfbWsClient(QObject* parent = nullptr); + + void open(const QUrl& url); + void close(); + QUrl url() const; + QSharedPointer<QAfbWsMsg> call(const QString &api, const QString &verb, const QJsonValue &args = QJsonValue()); + +signals: + void connected(); + void disconnected(); + void error(QAbstractSocket::SocketError err, QString errStr); + +private slots: + void onSocketConnected(); + void onSocketDisconnected(); + void onSocketError(QAbstractSocket::SocketError err); + void onSocketTextMessageReceived(QString msg); + +private: + int m_nextCallId; + QWebSocket m_socket; + QMap<int, QSharedPointer<QAfbWsMsg>> m_calls; +}; + +#endif // QAFBWSCLIENT_H |