9#include <nlohmann/json.hpp>
16typedef std::function<void(
const json&)> msghandler_t;
17typedef std::function<bool(
const json&)> validator_t;
18typedef std::function<void()> connhandler_t;
19typedef std::function<void()> heartbeattimeouthandler_t;
68 const validator_t& validator);
87 void addConnectionHandler(
const connhandler_t& handler);
89 void addDisconnectionHandler(
const connhandler_t& handler);
101 const heartbeattimeouthandler_t& handler);
111 friend class SingleClientWSServer;
118 std::optional<std::pair<std::chrono::milliseconds, heartbeattimeouthandler_t>>
127 void processMessage(
const json& obj)
const;
132 void clientConnected();
137 void clientDisconnected();
142 void heartbeatTimedOut();
_GLIBCXX_END_NAMESPACE_CXX11 typedef basic_string< char > string
duration< int64_t, milli > milliseconds
WebSocketProtocol(const std::string &protocolPath)
Construct a new WebSocket protocol.
Definition WebSocketProtocol.cpp:11
bool removeMessageHandler(const std::string &messageType)
Remove the message handler for the given message type, if it exists.
Definition WebSocketProtocol.cpp:34
std::string getProtocolPath() const
Get the protocol path of the endpoint this protocol is served on.
Definition WebSocketProtocol.cpp:97
bool addMessageHandler(const std::string &messageType, const msghandler_t &callback)
Add a message handler for the given message type, if no handler already exists.
Definition WebSocketProtocol.cpp:14
WebSocketProtocol(const std::string &protocolPath)
Construct a new WebSocket protocol.
Definition WebSocketProtocol.cpp:11
bool hasMessageHandler(const std::string &messageType) const
Check if the given message type has an associated message handler.
Definition WebSocketProtocol.cpp:30
void setHeartbeatTimedOutHandler(std::chrono::milliseconds timeout, const heartbeattimeouthandler_t &handler)
Set the handler that's called when the heartbeat times out.
Definition WebSocketProtocol.cpp:50