#pragma once #include "ProtobufMessages.hpp" #include "SendChatMessage.hpp" #include "ChatClientError.hpp" #include "models/ChatMessage.hpp" #include "message_protocol/MessageEndpoint.hpp" #include #include #include namespace tw::chat { class ChatClient { std::unique_ptr m_endpoint; msg::MessageConnection* m_server; ProtobufMessages m_messages; std::function m_on_message; std::function)> m_on_send_response; std::function)> m_on_join_response; std::function)> m_on_leave_response; public: ChatClient(const std::string& server_address, int16_t port); void update(); tl::expected send_mesg(SendChatMessage message); // Called for every broadcast message received on a subscribed channel. void set_on_message(std::function handler); // Called when the server responds to send/join/leave requests. // tl::expected holds void on success, ChatClientError on failure. void set_on_send_response(std::function)> handler); void set_on_join_response(std::function)> handler); void set_on_leave_response(std::function)> handler); }; }