diff options
author | Michael J <37635304+buttercat1791@users.noreply.github.com> | 2024-05-09 08:28:50 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-09 08:28:50 -0500 |
commit | 663fb4e7199e1b4318a5bc107096f6a529823e02 (patch) | |
tree | 7d92570de852f97550f84140bd794fa5d64c567b /src/client | |
parent | 0d87b4053983ec8edaff5b73491b717866876586 (diff) | |
parent | d6faf6c815611450d1b61045b53525d7f25ac5c9 (diff) |
Merge pull request #3 from buttercat1791/relay-readv0.0.2
Full Relay Read/Write Support
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/websocketpp_client.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/client/websocketpp_client.cpp b/src/client/websocketpp_client.cpp index 1386e1a..baae054 100644 --- a/src/client/websocketpp_client.cpp +++ b/src/client/websocketpp_client.cpp @@ -1,9 +1,7 @@ -#include <websocketpp/client.hpp> -#include <websocketpp/config/asio_client.hpp> - #include "web_socket_client.hpp" using std::error_code; +using std::function; using std::lock_guard; using std::make_tuple; using std::mutex; @@ -76,13 +74,33 @@ public: if (error.value() == -1) { - // PLOG_ERROR << "Error publishing event to relay " << relay << ": " << error.message(); return make_tuple(uri, false); } return make_tuple(uri, true); }; + tuple<string, bool> send(string message, string uri, function<void(const string&)> messageHandler) override + { + auto successes = this->send(message, uri); + this->receive(uri, messageHandler); + return successes; + }; + + void receive(string uri, function<void(const string&)> messageHandler) override + { + lock_guard<mutex> lock(this->_propertyMutex); + auto connectionHandle = this->_connectionHandles[uri]; + auto connection = this->_client.get_con_from_hdl(connectionHandle); + + connection->set_message_handler([messageHandler]( + websocketpp::connection_hdl connectionHandle, + websocketpp_client::message_ptr message) + { + messageHandler(message->get_payload()); + }); + }; + void closeConnection(string uri) override { lock_guard<mutex> lock(this->_propertyMutex); @@ -103,5 +121,9 @@ private: websocketpp_client _client; unordered_map<string, websocketpp::connection_hdl> _connectionHandles; mutex _propertyMutex; + + void onMessage(websocketpp::connection_hdl handle, websocketpp_client::message_ptr message) + { + }; }; } // namespace client |