From ca0023eef63fbe7f3fbaf21d0c80f6a907b0c1ec Mon Sep 17 00:00:00 2001 From: casey langen Date: Fri, 25 Mar 2022 22:46:28 -0700 Subject: [PATCH] Enqueue eventLog messages. --- src/musikcore/net/PiggyWebSocketClient.cpp | 4 ++-- src/musikcore/net/RawWebSocketClient.cpp | 3 ++- src/musikcore/support/PiggyDebugBackend.cpp | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/musikcore/net/PiggyWebSocketClient.cpp b/src/musikcore/net/PiggyWebSocketClient.cpp index a4f2c94ee..460cbaf2e 100644 --- a/src/musikcore/net/PiggyWebSocketClient.cpp +++ b/src/musikcore/net/PiggyWebSocketClient.cpp @@ -51,7 +51,7 @@ using Message = PiggyWebSocketClient::Message; static const int64_t kLatencyTimeoutMs = 30000; static const int64_t kPingIntervalMs = 10000; static const int kPingMessage = 6000; -static const bool kDisableOfflineQueue = true; +static const bool kDisableOfflineQueue = false; static std::atomic nextMessageId(0); static inline std::string generateSessionId() { @@ -143,7 +143,7 @@ void PiggyWebSocketClient::EnqueueMessage(Message message) { } void PiggyWebSocketClient::Connect(const std::string& host, unsigned short port, bool useTls) { - auto newUri = "ws://" + host + ":" + std::to_string(port); + auto newUri = "ws://" + host + ":" + std::to_string(port) + "?deviceId=musikcube&type=native"; if (newUri != this->uri || useTls != this->useTls || this->state != State::Connected) diff --git a/src/musikcore/net/RawWebSocketClient.cpp b/src/musikcore/net/RawWebSocketClient.cpp index 08c54e88f..19f6893e8 100644 --- a/src/musikcore/net/RawWebSocketClient.cpp +++ b/src/musikcore/net/RawWebSocketClient.cpp @@ -143,4 +143,5 @@ void RawWebSocketClient::Run() { else if (mode == Mode::TLS) { tlsClient->run(); } -} \ No newline at end of file +} + diff --git a/src/musikcore/support/PiggyDebugBackend.cpp b/src/musikcore/support/PiggyDebugBackend.cpp index 584c205db..66a44c4e6 100644 --- a/src/musikcore/support/PiggyDebugBackend.cpp +++ b/src/musikcore/support/PiggyDebugBackend.cpp @@ -38,6 +38,22 @@ using namespace musik; +static inline std::shared_ptr createMessage( + const std::string& level, const std::string& tag, const std::string message) +{ + const nlohmann::json json = { + { "name", "/eventLog/send" }, + { "data", { + { "type", "console" }, + { "level", level }, + { "timestamp", 0 }, + { "tag", tag }, + { "data", nlohmann::json::array({message}) } + } } + }; + return std::make_shared(json); +} + PiggyDebugBackend::PiggyDebugBackend(Client client): client(client) { } @@ -45,14 +61,18 @@ PiggyDebugBackend::~PiggyDebugBackend() { } void PiggyDebugBackend::verbose(const std::string& tag, const std::string& string) { + client->EnqueueMessage(createMessage("verbose", tag, string)); } void PiggyDebugBackend::info(const std::string& tag, const std::string& string) { + client->EnqueueMessage(createMessage("info", tag, string)); } void PiggyDebugBackend::warning(const std::string& tag, const std::string& string) { + client->EnqueueMessage(createMessage("warn", tag, string)); } void PiggyDebugBackend::error(const std::string& tag, const std::string& string) { + client->EnqueueMessage(createMessage("error", tag, string)); }