Abstract interface for WebSocket client implementations. More...
#include <websocket_interface.h>

Public Types | |
| using | MessageCallback = std::function<void(const std::string& message)> |
| using | BinaryMessageCallback = std::function<void(const uint8_t* data, size_t length)> |
| using | OpenCallback = std::function<void()> |
| using | CloseCallback = std::function<void(int code, const std::string& reason)> |
| using | ErrorCallback = std::function<void(const std::string& error)> |
Public Member Functions | |
| virtual | ~IWebSocket ()=default |
| virtual absl::Status | Connect (const std::string &url)=0 |
| Connect to a WebSocket server. | |
| virtual absl::Status | Send (const std::string &message)=0 |
| Send a text message. | |
| virtual absl::Status | SendBinary (const uint8_t *data, size_t length) |
| Send a binary message. | |
| virtual absl::Status | Close (int code=1000, const std::string &reason="")=0 |
| Close the WebSocket connection. | |
| virtual WebSocketState | GetState () const =0 |
| Get the current connection state. | |
| virtual bool | IsConnected () const |
| Check if the WebSocket is connected. | |
| virtual void | OnMessage (MessageCallback callback)=0 |
| Set callback for text message events. | |
| virtual void | OnBinaryMessage (BinaryMessageCallback callback) |
| Set callback for binary message events. | |
| virtual void | OnOpen (OpenCallback callback)=0 |
| Set callback for connection open events. | |
| virtual void | OnClose (CloseCallback callback)=0 |
| Set callback for connection close events. | |
| virtual void | OnError (ErrorCallback callback)=0 |
| Set callback for error events. | |
| virtual std::string | GetUrl () const |
| Get the WebSocket URL. | |
| virtual void | SetAutoReconnect (bool enable, int delay_seconds=5) |
| Set automatic reconnection. | |
Protected Attributes | |
| std::string | url_ |
| WebSocketState | state_ = WebSocketState::kDisconnected |
| MessageCallback | message_callback_ |
| BinaryMessageCallback | binary_message_callback_ |
| OpenCallback | open_callback_ |
| CloseCallback | close_callback_ |
| ErrorCallback | error_callback_ |
| bool | auto_reconnect_ = false |
| int | reconnect_delay_seconds_ = 5 |
Abstract interface for WebSocket client implementations.
This interface abstracts WebSocket operations to support both native (using various libraries) and WASM (using emscripten WebSocket) implementations. All methods use absl::Status for consistent error handling.
Definition at line 33 of file websocket_interface.h.
| using yaze::net::IWebSocket::MessageCallback = std::function<void(const std::string& message)> |
Definition at line 36 of file websocket_interface.h.
| using yaze::net::IWebSocket::BinaryMessageCallback = std::function<void(const uint8_t* data, size_t length)> |
Definition at line 37 of file websocket_interface.h.
| using yaze::net::IWebSocket::OpenCallback = std::function<void()> |
Definition at line 38 of file websocket_interface.h.
| using yaze::net::IWebSocket::CloseCallback = std::function<void(int code, const std::string& reason)> |
Definition at line 39 of file websocket_interface.h.
| using yaze::net::IWebSocket::ErrorCallback = std::function<void(const std::string& error)> |
Definition at line 40 of file websocket_interface.h.
|
virtualdefault |
|
pure virtual |
Connect to a WebSocket server.
| url | The WebSocket URL (ws:// or wss://) |
Implemented in yaze::net::HttpLibWebSocket.
|
pure virtual |
Send a text message.
| message | The text message to send |
Implemented in yaze::net::HttpLibWebSocket.
|
inlinevirtual |
Send a binary message.
| data | The binary data to send |
| length | The length of the data |
Reimplemented in yaze::net::HttpLibWebSocket.
Definition at line 64 of file websocket_interface.h.
|
pure virtual |
Close the WebSocket connection.
| code | Optional close code (default: 1000 for normal closure) |
| reason | Optional close reason |
Implemented in yaze::net::HttpLibWebSocket.
|
pure virtual |
Get the current connection state.
Implemented in yaze::net::HttpLibWebSocket.
Referenced by IsConnected().
|
inlinevirtual |
Check if the WebSocket is connected.
Definition at line 88 of file websocket_interface.h.
References GetState(), and yaze::net::kConnected.

|
pure virtual |
Set callback for text message events.
| callback | Function to call when a text message is received |
Implemented in yaze::net::HttpLibWebSocket.
|
inlinevirtual |
Set callback for binary message events.
| callback | Function to call when binary data is received |
Reimplemented in yaze::net::HttpLibWebSocket.
Definition at line 102 of file websocket_interface.h.
References binary_message_callback_.
|
pure virtual |
Set callback for connection open events.
| callback | Function to call when connection is established |
Implemented in yaze::net::HttpLibWebSocket.
|
pure virtual |
Set callback for connection close events.
| callback | Function to call when connection is closed |
Implemented in yaze::net::HttpLibWebSocket.
|
pure virtual |
Set callback for error events.
| callback | Function to call when an error occurs |
Implemented in yaze::net::HttpLibWebSocket.
|
inlinevirtual |
Get the WebSocket URL.
Definition at line 129 of file websocket_interface.h.
References url_.
|
inlinevirtual |
Set automatic reconnection.
| enable | Enable or disable auto-reconnect |
| delay_seconds | Delay between reconnection attempts |
Definition at line 136 of file websocket_interface.h.
References auto_reconnect_, and reconnect_delay_seconds_.
|
protected |
Definition at line 142 of file websocket_interface.h.
Referenced by GetUrl(), and yaze::net::HttpLibWebSocket::ParseWebSocketUrl().
|
protected |
Definition at line 143 of file websocket_interface.h.
Referenced by yaze::net::HttpLibWebSocket::Close(), yaze::net::HttpLibWebSocket::Connect(), yaze::net::HttpLibWebSocket::GetState(), yaze::net::HttpLibWebSocket::HttpLibWebSocket(), yaze::net::HttpLibWebSocket::ReceiveLoop(), yaze::net::HttpLibWebSocket::Send(), yaze::net::HttpLibWebSocket::SendBinary(), and yaze::net::HttpLibWebSocket::~HttpLibWebSocket().
|
protected |
Definition at line 146 of file websocket_interface.h.
Referenced by yaze::net::HttpLibWebSocket::OnMessage(), and yaze::net::HttpLibWebSocket::ReceiveLoop().
|
protected |
Definition at line 147 of file websocket_interface.h.
Referenced by OnBinaryMessage(), and yaze::net::HttpLibWebSocket::OnBinaryMessage().
|
protected |
Definition at line 148 of file websocket_interface.h.
Referenced by yaze::net::HttpLibWebSocket::Connect(), and yaze::net::HttpLibWebSocket::OnOpen().
|
protected |
Definition at line 149 of file websocket_interface.h.
Referenced by yaze::net::HttpLibWebSocket::Close(), and yaze::net::HttpLibWebSocket::OnClose().
|
protected |
Definition at line 150 of file websocket_interface.h.
Referenced by yaze::net::HttpLibWebSocket::OnError(), and yaze::net::HttpLibWebSocket::ReceiveLoop().
|
protected |
Definition at line 153 of file websocket_interface.h.
Referenced by SetAutoReconnect().
|
protected |
Definition at line 154 of file websocket_interface.h.
Referenced by SetAutoReconnect().