1#ifndef YAZE_APP_NET_NATIVE_HTTPLIB_WEBSOCKET_H_
2#define YAZE_APP_NET_NATIVE_HTTPLIB_WEBSOCKET_H_
37 absl::Status
Connect(
const std::string& url)
override;
44 absl::Status
Send(
const std::string& message)
override;
52 absl::Status
SendBinary(
const uint8_t* data,
size_t length)
override;
60 absl::Status
Close(
int code = 1000,
61 const std::string& reason =
"")
override;
117 std::string& http_url);
Native WebSocket implementation using HTTP fallback.
~HttpLibWebSocket() override
void OnClose(CloseCallback callback) override
Set callback for connection close events.
void OnError(ErrorCallback callback) override
Set callback for error events.
void OnMessage(MessageCallback callback) override
Set callback for text message events.
std::atomic< bool > stop_receive_
absl::Status Connect(const std::string &url) override
Connect to a WebSocket server.
std::thread receive_thread_
absl::Status Send(const std::string &message) override
Send a text message.
absl::Status ParseWebSocketUrl(const std::string &ws_url, std::string &http_url)
Parse WebSocket URL into HTTP components.
void OnOpen(OpenCallback callback) override
Set callback for connection open events.
std::string http_endpoint_
absl::Status SendBinary(const uint8_t *data, size_t length) override
Send a binary message.
WebSocketState GetState() const override
Get the current connection state.
void OnBinaryMessage(BinaryMessageCallback callback) override
Set callback for binary message events.
void StopReceiveLoop()
Stop the receive loop.
absl::Status Close(int code=1000, const std::string &reason="") override
Close the WebSocket connection.
std::shared_ptr< httplib::Client > client_
void ReceiveLoop()
Background thread for receiving messages (polling)
Abstract interface for WebSocket client implementations.
OpenCallback open_callback_
CloseCallback close_callback_
std::function< void(const std::string &message)> MessageCallback
ErrorCallback error_callback_
std::function< void(const std::string &error)> ErrorCallback
std::function< void(const uint8_t *data, size_t length)> BinaryMessageCallback
BinaryMessageCallback binary_message_callback_
MessageCallback message_callback_
std::function< void()> OpenCallback
std::function< void(int code, const std::string &reason)> CloseCallback
WebSocketState
WebSocket connection states.