diff options
author | Michael Jurkoic <mjjurkoic@gmail.com> | 2024-03-19 09:12:00 -0500 |
---|---|---|
committer | Michael Jurkoic <mjjurkoic@gmail.com> | 2024-03-19 09:12:00 -0500 |
commit | 8dbce9cd5aab9129e66a0c04e31467d172344f19 (patch) | |
tree | a5f76cebf5af6928ca4c6778920a8b09b7e96bec /src/client/websocketpp_client.cpp | |
parent | 6dde23e6c66e846c64d49c5258f0dbf44e3d0374 (diff) |
Move relay payload parsing into NostrService
Preserve separation of concerns.
Diffstat (limited to 'src/client/websocketpp_client.cpp')
-rw-r--r-- | src/client/websocketpp_client.cpp | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/src/client/websocketpp_client.cpp b/src/client/websocketpp_client.cpp index 5199343..981d4ec 100644 --- a/src/client/websocketpp_client.cpp +++ b/src/client/websocketpp_client.cpp @@ -1,10 +1,8 @@ -#include <nlohmann/json.hpp> #include <websocketpp/client.hpp> #include <websocketpp/config/asio_client.hpp> #include "web_socket_client.hpp" -using nlohmann::json; using std::error_code; using std::function; using std::lock_guard; @@ -86,26 +84,17 @@ public: return make_tuple(uri, true); }; - void receive(string uri, function<void(const string&, const string&)> messageHandler) override + void receive(string uri, function<void(const string&)> messageHandler) override { - this->_client.set_message_handler([this, messageHandler]( + 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) { - json jarr = json::array(); - string payload = message->get_payload(); - - jarr.parse(payload); - string messageType = jarr[0]; - - if (messageType == "EVENT") - { - string subscriptionId = jarr[1]; - string messageContents = jarr[2].dump(); - messageHandler(subscriptionId, messageContents); - }; - - // TODO: Add support for other message types. + messageHandler(message->get_payload()); }); }; |