Enqueue eventLog messages.

This commit is contained in:
casey langen 2022-03-25 22:46:28 -07:00
parent 0a32f99fbd
commit ca0023eef6
3 changed files with 24 additions and 3 deletions

View File

@ -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<int> 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)

View File

@ -143,4 +143,5 @@ void RawWebSocketClient::Run() {
else if (mode == Mode::TLS) {
tlsClient->run();
}
}
}

View File

@ -38,6 +38,22 @@
using namespace musik;
static inline std::shared_ptr<nlohmann::json> 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<nlohmann::json>(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));
}