A WebSocket client adapter that leverages the Simple WebSocket Server library for managing WebSocket connections.
More...
|
| SimpleWebSocketClientAdapter () |
| Constructs the WebSocket client and initializes the io_context.
|
|
virtual | ~SimpleWebSocketClientAdapter ()=default |
| Default destructor for cleanup.
|
|
| SimpleWebSocketClientAdapter (const SimpleWebSocketClientAdapter &)=delete |
|
void | operator= (const SimpleWebSocketClientAdapter &)=delete |
|
std::string | get_http_version () override final |
| Retrieves the HTTP version used in the WebSocket connection.
|
|
Headers | get_headers () override final |
| Retrieves the headers associated with the WebSocket connection.
|
|
std::string | get_remote_endpoint () override final |
| Retrieves the remote endpoint information.
|
|
| BaseWebSocketClient ()=default |
| Default constructor.
|
|
virtual | ~BaseWebSocketClient ()=default |
| Virtual destructor.
|
|
std::function< void(std::unique_ptr< WebSocketEventData >)> & | event_handler () override final |
| Accessor for the event handler function.
|
|
std::function< void()> & | notify_handler () override final |
| Accesses the notification handler for WebSocket events.
|
|
void | set_config (std::unique_ptr< WebSocketConfig > config, std::function< void(bool)> callback) override final |
| Sets the configuration for the WebSocket client.
|
|
void | connect (std::function< void(bool)> callback) override final |
| Initiates a connection to the WebSocket server.
|
|
void | disconnect (std::function< void(bool)> callback) override final |
| Closes the connection to the WebSocket server.
|
|
bool | is_connected () const override final |
| Checks if the WebSocket client is actively running.
|
|
bool | is_running () const override final |
| Checks if the WebSocket client is actively running.
|
|
std::list< std::unique_ptr< WebSocketEventData > > | receive_events () const override final |
| Retrieves all pending WebSocket events in a batch.
|
|
std::unique_ptr< WebSocketEventData > | receive_event () const override final |
| Retrieves the next available WebSocket event, if any.
|
|
bool | send_message (const std::string &message, long rate_limit_id, std::function< void(const std::error_code &ec)> callback=nullptr) override final |
| Send a message through the WebSocket.
|
|
bool | send_close (const int status=1000, const std::string &reason=std::string(), std::function< void(const std::error_code &ec)> callback=nullptr) override final |
| Send a close request through the WebSocket.
|
|
void | process () override final |
| Processes internal operations such as event handling and state updates.
|
|
void | shutdown () override final |
| Shuts down the WebSocket client, disconnecting and clearing all pending events.
|
|
| IWebSocketClient ()=default |
| Default constructor.
|
|
virtual | ~IWebSocketClient ()=default |
| Virtual destructor for safe cleanup in derived classes.
|
|
| IWebSocketSender ()=default |
| Default constructor for IWebSocketSender.
|
|
virtual | ~IWebSocketSender ()=default |
| Virtual destructor for IWebSocketSender.
|
|
virtual bool | send_message (const std::string &message, long rate_limit_id=0, std::function< void(const std::error_code &)> callback=nullptr)=0 |
| Sends a WebSocket message.
|
|
virtual bool | send_close (int status=1000, const std::string &reason=std::string(), std::function< void(const std::error_code &)> callback=nullptr)=0 |
| Sends a close request to the WebSocket server.
|
|
|
bool | init_websocket () override final |
| Initializes and starts a WebSocket connection.
|
|
void | deinit_websocket () override final |
| Deinitializes the WebSocket connection.
|
|
void | send_message (std::shared_ptr< WebSocketSendInfo > &send_info) override final |
| Sends a WebSocket message.
|
|
void | send_close (std::shared_ptr< WebSocketSendInfo > &send_info) override final |
| Sends a WebSocket close request.
|
|
template<class ConnectionType> |
void | send_message (const ConnectionType &connection, const send_info_ptr_t &send_info) |
| Helper to send a message on a specific connection type.
|
|
template<class ConnectionType> |
void | send_close (const ConnectionType &connection, const send_info_ptr_t &send_info) |
| Helper to send a close request on a specific connection type.
|
|
template<class ClientType, class ConnectionType, class MessageType> |
void | init_client () |
| Initializes a WebSocket client based on the provided type and sets up callbacks.
|
|
template<class T> |
std::shared_ptr< T > | create_client (typename std::enable_if< std::is_same< T, WssClient >::value >::type *=0) |
|
template<class T> |
std::shared_ptr< T > | create_client (typename std::enable_if< std::is_same< T, WsClient >::value >::type *=0) |
|
template<class ConnectionType> |
std::unique_ptr< WebSocketEventData > | create_websocket_open_event (std::shared_ptr< ConnectionType > &connection) |
|
template<class MessageType> |
std::unique_ptr< WebSocketEventData > | create_websocket_message_event (std::shared_ptr< MessageType > &message) |
|
template<class T> |
void | init_connection (std::shared_ptr< T > &connection, typename std::enable_if< std::is_same< T, WssClient::Connection >::value >::type *=0) |
|
template<class T> |
void | init_connection (std::shared_ptr< T > &connection, typename std::enable_if< std::is_same< T, WsClient::Connection >::value >::type *=0) |
|
template<class ConnectionType> |
std::string | endpoint_to_string (const std::shared_ptr< ConnectionType > &connection) const |
|
template<typename SrcMap, typename DstMap> |
void | copy_headers (const SrcMap &src, DstMap &dst) |
|
|
enum class | FsmState {
INIT
, CONNECTING
, WORKING
, RECONNECTING
,
STOPPED
} |
| Finite State Machine (FSM) states for the WebSocket connection. More...
|
|
enum class | FsmEvent {
RequestConnect
, RequestDisconnect
, ConnectionOpened
, ConnectionClosed
,
ConnectionError
, MessageReceived
, UpdateConfig
} |
| Represents events in the finite state machine. More...
|
|
std::unique_ptr< WebSocketEventData > | create_websocket_event () |
| Creates a generic WebSocket event.
|
|
std::unique_ptr< WebSocketEventData > | create_websocket_close_event (const std::string &reason="Normal Closure", int status_code=1000) |
| Creates a WebSocket close event with a specified reason and status code.
|
|
std::unique_ptr< WebSocketEventData > | create_websocket_error_event (const std::error_code &error_code) |
| Creates a WebSocket error event with a specified error code.
|
|
void | add_send_callback (const std::error_code &error_code, const std::function< void(const std::error_code &ec)> &callback) |
| Adds a send callback to the queue.
|
|
void | add_fsm_event (FsmEvent event_type, std::unique_ptr< WebSocketEventData > event_data) |
| Adds an FSM event to the event queue and triggers the notify handler.
|
|
std::unique_ptr< WebSocketConfig > | m_config |
| Current configuration for the WebSocket.
|
|
enum kurlyk::BaseWebSocketClient::FsmState | m_fsm_state = FsmState::INIT |
|
A WebSocket client adapter that leverages the Simple WebSocket Server library for managing WebSocket connections.
This class implements core WebSocket functionalities, such as connecting, sending messages, handling events, and managing the connection lifecycle with Simple WebSocket Server's SocketClient
and SocketClient<WS>
types.
Definition at line 18 of file SimpleWebSocketClientAdapter.hpp.