-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathWebSocket.h
117 lines (103 loc) · 2.38 KB
/
WebSocket.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
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* \file WebSocket.h
* \brief Websocket interface PhxSocket uses.
*
* There's a couple different C++ Websocket libraries that can be used.
* In order to not get tied at the hips to any one of them, make it so any
* implementing users can pick the one they want to use.
*/
#ifndef WebSocket_H
#define WebSocket_H
#include <string>
class SocketDelegate;
typedef enum {
SocketConnecting,
SocketOpen,
SocketClosing,
SocketClosed
} SocketState;
class WebSocket {
protected:
std::string url;
SocketDelegate* delegate;
public:
WebSocket() {
}
/**
* \brief Constructor.
*
* This constructor will require url and delegate to be set.
*
* \param url The url to connect to.
* \param delegate The delegate to receive WebSocket callbacks.
* \return Websocket
*/
WebSocket(const std::string& url, SocketDelegate* delegate) {
this->url = url;
this->delegate = delegate;
}
/**
* \brief Open the websocket connection.
*
* Detailed description
*
* \param param
* \return return type
*/
virtual void open() = 0;
/**
* \brief Close the websocket connection.
*
* Detailed description
*
* \param param
* \return return type
*/
virtual void close() = 0;
/**
* \brief Send a message over websockets.
*
* Detailed description
*
* \param param
* \return return type
*/
virtual void send(const std::string& message) = 0;
// // Send a Data
// - (void)sendData:(nullable NSData *)data error:(NSError **)error;
/**
* \brief Get SocketState
*
* Detailed description
*
* \param param
* \return return type
*/
virtual SocketState getSocketState() = 0;
/**
* \brief Set the SocketDelegate.
*
* Detailed description
*
* \param param
* \return return type
*/
virtual void setDelegate(SocketDelegate* delegate) = 0;
/**
* \brief Get the SocketDelegate.
*
* Detailed description
*
* \param param
* \return return type
*/
virtual SocketDelegate* getDelegate() = 0;
/**
* \brief Sets the WebSocket URL.
*
* \param url The url to connect to.
* \return void
*/
virtual void setURL(const std::string& url) = 0;
};
#endif