-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.h
104 lines (81 loc) · 2.1 KB
/
client.h
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef SIO_CLIENT_H
#define SIO_CLIENT_H
#include <QObject>
#include <QUrl>
#include <QJsonDocument>
#include <QWebSocket>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QTimer>
#include <QJSValue>
#include <QMap>
#include "protocol.h"
#include "nsp.h"
namespace SocketIO {
class Client : public QObject
{
friend class Nsp;
Q_OBJECT
public:
enum State {
Disconnected = 0,
Opening,
Opened,
Connecting,
Connected,
Disconnecting
};
explicit Client(int eioVersion = 4, QObject *parent = nullptr);
~Client();
QString sessionID();
Q_PROPERTY(QString state READ getState)
QString getState();
Q_INVOKABLE void on(QString ev, QJSValue cb);
Q_INVOKABLE void off(QString ev);
Q_INVOKABLE void once(QString ev, QJSValue cb);
Q_INVOKABLE void eemit(QString ev, QJSValue data);
Q_INVOKABLE Nsp * of(QString name);
signals:
void stateChanged(State);
void connected();
void disconnected();
public slots:
void open(QUrl url);
void close();
void restart();
private slots:
void handshakeReplyFinished(QNetworkReply *reply);
void onSocketError(QAbstractSocket::SocketError error);
void onWsConnected();
void onWsDisconnected();
void onWsStateChanged(QAbstractSocket::SocketState st);
void onTextMessage(QString textMessage);
void onBinaryMessage(QByteArray msg);
void sendPulse(QString rawData = "");
void sendUpgrade();
void sendConnect(QString nsp="/");
void sendPacket(Packet * p);
// void parseTextMessage(QString msg);
private:
QUrl handshakeUrl();
QUrl wsUrl();
void resetPulseTimer();
void resetTimoutTimer();
void connectionTimedOut();
private:
State _state;
QUrl _url;
QString _sessionID;
int _engineIoVerion;
QWebSocket * _ws;
QNetworkAccessManager * _accessManager;
Protocol _protocol;
qint32 _connectionTimeout;
qint32 _pulseTimeout;
QTimer * _pulseTimer;
QTimer * _timeoutTimer;
QMap<QString,Nsp*> _nsps;
};
}
#endif // SOCKETIOCLIENT_H