3#include "../../utils/scheduler.h"
4#include "WebSocketProtocol.h"
12#include <nlohmann/json.hpp>
13#include <websocketpp/config/asio_no_tls.hpp>
14#include <websocketpp/server.hpp>
20using websocketpp::connection_hdl;
22typedef std::shared_ptr<websocketpp::config::core::message_type> message_t;
101 std::optional<connection_hdl> client;
103 std::optional<std::pair<util::PeriodicScheduler<>::eventid_t,
util::Watchdog<>>>
110 websocketpp::server<websocketpp::config::asio> server;
121 bool validate(connection_hdl hdl);
123 void onOpen(connection_hdl hdl);
125 void onClose(connection_hdl hdl);
126 void onMessage(connection_hdl hdl, message_t message);
128 void onPong(connection_hdl hdl,
const std::string& payload);
131 std::optional<std::reference_wrapper<SingleClientWSServer::ProtocolData>>
_GLIBCXX_END_NAMESPACE_CXX11 typedef basic_string< char > string
SingleClientWSServer(const std::string &serverName, uint16_t port)
Construct a new server object, without starting it.
Definition WebSocketServer.cpp:16
void sendJSON(const std::string &protocolPath, const json &obj)
Serialize the JSON as a string and send it to the client connected to the given protocol path,...
Definition WebSocketServer.cpp:115
void sendRawString(const std::string &protocolPath, const std::string &str)
Send a string to the client connected to the given protocol path, if there is one.
Definition WebSocketServer.cpp:98
bool addProtocol(std::unique_ptr< WebSocketProtocol > protocol)
Register a protocol with this server.
Definition WebSocketServer.cpp:87
SingleClientWSServer(const std::string &serverName, uint16_t port)
Construct a new server object, without starting it.
Definition WebSocketServer.cpp:16
void stop()
Stop the server.
Definition WebSocketServer.cpp:60
bool start()
Start the server.
Definition WebSocketServer.cpp:38
~SingleClientWSServer()
Destroy the server after calling stop()
Definition WebSocketServer.cpp:34
Uses a single thread to periodically invoke callbacks at a given frequency.
Definition scheduler.h:38
Implements a thread-safe watchdog.
Definition scheduler.h:202