Deep RTS
Websockets.h
Go to the documentation of this file.
1//
2// Created by per on 18.10.2020.
3//
4
5#ifndef HORIZON_WEBSOCKETS_H
6#define HORIZON_WEBSOCKETS_H
7#include <drogon/WebSocketController.h>
8#include <nlohmann/json.hpp>
9
10class AI;
11
12
13class Websockets : public drogon::WebSocketController<Websockets, false> {
14private:
15 std::map<int, drogon::WebSocketConnectionPtr> _clientsMap; //UserID--->connection
16 std::mutex _mapMtx;
17public:
18
20 void handleNewMessage(const drogon::WebSocketConnectionPtr &,
21 std::string &&,
22 const drogon::WebSocketMessageType &) override;
24 const drogon::WebSocketConnectionPtr &) override;
25 void handleNewConnection(const drogon::HttpRequestPtr &,
26 const drogon::WebSocketConnectionPtr &) override;
27 WS_PATH_LIST_BEGIN
28 // list path definations here;
29 WS_PATH_ADD("/ws", "drogon::LocalHostFilter", drogon::Get);
30 WS_PATH_LIST_END
31
32
33
34
35 static void send(const drogon::WebSocketConnectionPtr &conn, const std::string& channel, const nlohmann::json & data);
36};
37
38
39#endif //HORIZON_WEBSOCKETS_H
nlohmann::json json
Definition: Websockets.cpp:17
Definition: Websockets.h:13
void handleNewMessage(const drogon::WebSocketConnectionPtr &, std::string &&, const drogon::WebSocketMessageType &) override
Definition: Websockets.cpp:18
WS_PATH_LIST_BEGIN WS_PATH_ADD("/ws", "drogon::LocalHostFilter", drogon::Get)
void handleConnectionClosed(const drogon::WebSocketConnectionPtr &) override
Definition: Websockets.cpp:41
static WS_PATH_LIST_END void send(const drogon::WebSocketConnectionPtr &conn, const std::string &channel, const nlohmann::json &data)
Definition: Websockets.cpp:72
void handleNewConnection(const drogon::HttpRequestPtr &, const drogon::WebSocketConnectionPtr &) override
Definition: Websockets.cpp:50