VoiceHeartbeatMessage and VoiceIdentifyMessage now uses yyjson

This commit is contained in:
celisej567
2024-05-12 23:31:15 +03:00
parent 3b57ff03b4
commit 5f25aff969
4 changed files with 49 additions and 2 deletions

View File

@@ -364,7 +364,7 @@ void DiscordVoiceClient::Identify() {
msg.Token = m_token;
msg.Video = true;
m_ws.Send(msg);
m_ws.Send(msg.BuildJson());
}
void DiscordVoiceClient::Discovery() {
@@ -442,7 +442,7 @@ void DiscordVoiceClient::HeartbeatThread() {
VoiceHeartbeatMessage msg;
msg.Nonce = ms;
m_ws.Send(msg);
m_ws.Send(msg.BuildJson());
}
}

View File

@@ -61,6 +61,16 @@ struct VoiceHelloData {
struct VoiceHeartbeatMessage {
uint64_t Nonce;
std::string BuildJson() const
{
YYJsonDocument yyjsn;
yyjsn.CreateDoc();
yyjsn.AddInt("op", (int)GatewayOp::Heartbeat);
yyjsn.AddUInt64("d", Nonce);
return yyjsn.BuildJson();
}
friend void to_json(nlohmann::json &j, const VoiceHeartbeatMessage &m);
};
@@ -72,6 +82,34 @@ struct VoiceIdentifyMessage {
bool Video;
// todo streams i guess?
std::string BuildJson() const
{
YYJsonDocument yyjsn;
yyjsn.CreateDoc();
yyjsn.AddInt("op", (int)VoiceGatewayOp::Identify);
yyjsn.CreateBlock();
std::string* str = new std::string(std::to_string(ServerID));
yyjsn.AddString("server_id", str->c_str());
std::string* str2 = new std::string(std::to_string(UserID));
yyjsn.AddString("user_id", str2->c_str());
yyjsn.AddString("session_id", SessionID.c_str());
yyjsn.AddString("token", Token.c_str());
yyjsn.AddBool("video", Video);
YYJsonArray yyjsnarr;
YYJsonDocument yyjsn2;
yyjsn2.CreateDoc();
yyjsn2.AddString("type", "video");
yyjsn2.AddString("rid", "100");
yyjsn2.AddInt("quality", 100);
yyjsnarr.AddBlock(yyjsn2.GetMutableRoot());
yyjsn.AddArray("streams", yyjsnarr.GetArray());
yyjsn.PushBlock("d");
return yyjsn.BuildJson();
}
friend void to_json(nlohmann::json &j, const VoiceIdentifyMessage &m);
};

View File

@@ -95,6 +95,14 @@ void YYJsonDocument::AddInt(const char* name, std::optional<int> value)
}
void YYJsonDocument::AddUInt64(const char* name, uint64_t value)
{
if(BuildingMode)
{
yyjson_mut_obj_add_uint(mutdoc,DataBlocks[currentBlockIndex],name,value);
}
}
//void YYJsonDocument::AddBool(const char* name, bool value)
//{
// if(BuildingMode)

View File

@@ -70,6 +70,7 @@ public:
void AddString(const char* name, std::optional<std::string> value);
//void AddInt(const char* name, int value);
void AddInt(const char* name, std::optional<int> value);
void AddUInt64(const char* name, uint64_t value);
//void AddBool(const char* name, bool value);
void AddBool(const char* name, std::optional<bool> value);
void AddBlock(const char* name, yyjson_mut_val* block);