aboutsummaryrefslogtreecommitdiff
path: root/src/network/websocketconnection.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/websocketconnection.h')
-rw-r--r--src/network/websocketconnection.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/network/websocketconnection.h b/src/network/websocketconnection.h
new file mode 100644
index 00000000..9df9a49b
--- /dev/null
+++ b/src/network/websocketconnection.h
@@ -0,0 +1,43 @@
+#pragma once
+
+#include "aopacket.h"
+#include "serverinfo.h"
+
+#include <QObject>
+#include <QWebSocket>
+
+class AOApplication;
+
+class WebSocketConnection : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit WebSocketConnection(AOApplication *ao_app, QObject *parent = nullptr);
+ virtual ~WebSocketConnection();
+
+ bool isConnected();
+
+ void connectToServer(const ServerInfo &server);
+ void disconnectFromServer();
+
+ void sendPacket(AOPacket packet);
+
+Q_SIGNALS:
+ void connectedToServer();
+ void disconnectedFromServer();
+ void errorOccurred(QString error);
+
+ void receivedPacket(AOPacket packet);
+
+private:
+ AOApplication *ao_app;
+
+ QWebSocket *m_socket;
+ QAbstractSocket::SocketState m_last_state;
+
+private Q_SLOTS:
+ void onError();
+ void onStateChanged(QAbstractSocket::SocketState state);
+ void onTextMessageReceived(QString message);
+};