4#ifndef MALENA_WEBSOCKET_PROVIDER_H
5#define MALENA_WEBSOCKET_PROVIDER_H
76 void send(
const std::string& text);
81 void onOpen(std::function<
void()> callback);
84 void onClose(std::function<
void(
int,
const std::string&)> callback);
87 void onError(std::function<
void(
const std::string&)> callback);
NetworkDispatcher(const std::string &keyField="type")
Persistent WebSocket client with main-thread callback delivery.
void onOpen(std::function< void()> callback)
Called on the main thread when the connection opens.
void send(const json &msg)
Send a JSON object as a UTF-8 text frame.
WebSocketProvider(const std::string &keyField="type")
void disconnect()
Close the connection gracefully.
void onError(std::function< void(const std::string &)> callback)
Called on the main thread on a protocol or network error.
void connect(const std::string &url)
Open a WebSocket connection to url.
void send(const std::string &text)
Send a raw text frame.
void setMaxReconnectAttempts(int n)
Maximum reconnect attempts. Pass -1 for unlimited.
void setReconnectDelay(int seconds)
Delay in seconds before reconnecting after an unexpected close.
void onClose(std::function< void(int, const std::string &)> callback)
Called on the main thread when the connection closes.
nlohmann::json json
Alias for nlohmann::json.