-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebsocket.h
68 lines (40 loc) · 1.19 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
#ifndef _REMI_WEBSOCKET__
#define _REMI_WEBSOCKET__
#include "remi.h"
#include "base64.h"
#include "TinySHA1.hpp"
#include <iostream>
#include <vector>
#include <time.h>
using namespace std;
namespace remi {
namespace server {
class WebsocketClientInterface {
public:
WebsocketClientInterface(remi_socket clientSock, bool doHandshake = true, int expireTimeoutSeconds = 60);
void* _run();
void stop();
bool isDead() {
return _stopFlag;
}
bool isExpired() {
return (_expireTimeoutSeconds > 0) && (remi_timestamp() - _secondsSinceLastPing) > _expireTimeoutSeconds;
}
void handshake();
void on_message(const char* message, unsigned long long len);
void send_message(std::string message);
bool readNextMessage();
static std::string packUpdateMessage(std::string tagToUpdateIdentifier, std::string htmlContent);
static std::string packExecuteJavascriptMessage(std::string command);
private:
Dictionary<Buffer*>* parseParams(const char* paramString, unsigned long len);
remi_thread _t;
remi_socket _sock;
bool _handshakeDone;
bool _stopFlag;
long long int _secondsSinceLastPing;
int _expireTimeoutSeconds;
};
}
}
#endif