-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsocket.h
More file actions
72 lines (51 loc) · 971 Bytes
/
websocket.h
File metadata and controls
72 lines (51 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef WEBSOCKET_H
#define WEBSOCKET_H
#include <QObject>
#include <QWebSocket>
#include <QUrl>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QJsonArray>
class webSocket : public QObject
{
Q_OBJECT
QWebSocket* webSock;
QUrl m_url;
QString m_usrName;
bool Isconnected;
public:
explicit webSocket(const QUrl url, QObject *parent = nullptr);
void loginIn(QString userName);
bool logined()
{
return !m_usrName.isEmpty();
}
bool isConnected()
{
return Isconnected;
}
QString getUsrName()
{
return m_usrName;
}
signals:
void onLogined(bool);
void onNewMessage(QJsonDocument);
void connected();
void disconnected();
private slots:
void onReadyRead(QString);
void onConnected();
void onDisconnected();
public slots:
void sendMessage(QString message);
void getConnect()
{
if(!isConnected())
{
webSock->open(m_url);
}
}
};
#endif // WEBSOCKET_H