Files
spark/src/lib/io/websocket/websocket_client.h
T

47 lines
1.3 KiB
C++

#pragma once
#include "lib/io/websocket/websocket_client_config.h"
#include "lib/utils/Delegate.h"
#include <boost/asio/io_context.hpp>
#include <memory>
#include <string>
#include <websocketpp/config/core_client.hpp>
#include <websocketpp/message_buffer/message.hpp>
namespace bts::websocket {
class WebsocketClient {
public:
WebsocketClient(
WebsocketClientConfig config,
boost::asio::io_context *io_context = nullptr);
~WebsocketClient();
using OpenHandler = bts::core::Delegate<void(const std::error_code &)>;
using MessageHandler = bts::core::Delegate<void(const std::string &)>;
using CloseHandler = bts::core::Delegate<void(const std::error_code &)>;
void connect();
void disconnect();
bool is_connected() const;
boost::asio::io_context *io_context();
void run();
void run_one();
OpenHandler &open_handler();
MessageHandler &message_handler();
CloseHandler &close_handler();
websocketpp::lib::error_code send_text(const std::string &text);
void ping(const std::string &payload = "");
void ping_continuously(int interval_secs, const std::string &payload = "");
void stop_continous_ping();
const std::string &url() const;
private:
struct PImpl;
std::unique_ptr<PImpl> me_;
};
} // namespace bts::websocket