diff options
author | buttercat1791 <mjjurkoic@gmail.com> | 2024-05-26 12:31:12 -0500 |
---|---|---|
committer | buttercat1791 <mjjurkoic@gmail.com> | 2024-05-26 12:31:12 -0500 |
commit | 1d6b704c15ee289037447fb566e7583962496650 (patch) | |
tree | e1cd3322d4f30746c32e7f46e58060a66c5abc23 /include/client/websocketpp_client.hpp | |
parent | a7d3e3d2ce1797fc2b7fc918684777ae75adb822 (diff) |
Refactor to separate interface from implementation
Diffstat (limited to 'include/client/websocketpp_client.hpp')
-rw-r--r-- | include/client/websocketpp_client.hpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/include/client/websocketpp_client.hpp b/include/client/websocketpp_client.hpp new file mode 100644 index 0000000..becf4fa --- /dev/null +++ b/include/client/websocketpp_client.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include "web_socket_client.hpp" + +namespace nostr +{ +namespace client +{ +/** + * @brief An implementation of the `IWebSocketClient` interface that uses the WebSocket++ library. + */ +class WebsocketppClient : public IWebSocketClient +{ +public: + void start() override; + + void stop() override; + + void openConnection(std::string uri) override; + + bool isConnected(std::string uri) override; + + std::tuple<std::string, bool> send(std::string message, std::string uri) override; + + std::tuple<std::string, bool> send( + std::string message, + std::string uri, + std::function<void(const std::string&)> messageHandler) override; + + void receive(std::string uri, std::function<void(const std::string&)> messageHandler) override; + + void closeConnection(std::string uri) override; + +private: + typedef websocketpp::client<websocketpp::config::asio_client> websocketpp_client; + typedef std::unordered_map<std::string, websocketpp::connection_hdl>::iterator connection_hdl_iterator; + + websocketpp_client _client; + std::unordered_map<std::string, websocketpp::connection_hdl> _connectionHandles; + std::mutex _propertyMutex; +}; +} // namespace client +} // namespace nostr + |