Skip to content

Commit

Permalink
Refactor CA object fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmit799 committed Apr 8, 2024
1 parent e680885 commit c5c8cb5
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/clientagent/client_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,7 @@ void ClientAgent::HandleWeb(ws28::Client *client, nlohmann::json &data) {
nlohmann::json clientInfo = nlohmann::json::array();
for (const auto &participant : _participants) {
clientInfo.push_back({
// We have to do this terribleness because JavaScript doesn't support
// uint64's (see handling 'client' messages below.)
{"channelHi", (participant->GetChannel() >> 32) & 0xFFFFFFFF},
{"channelLo", participant->GetChannel() & 0xFFFFFFFF},
{"channel", std::to_string(participant->GetChannel())},
{"ip", participant->GetRemoteAddress().ip},
{"port", participant->GetRemoteAddress().port},
{"state", participant->GetAuthState()},
Expand All @@ -389,8 +386,7 @@ void ClientAgent::HandleWeb(ws28::Client *client, nlohmann::json &data) {
} else if (data["msg"] == "client") {
// We have to do this terribleness because JavaScript doesn't support
// uint64's.
auto channel = (uint64_t)data["channelHi"].template get<uint32_t>() << 32 |
data["channelLo"].template get<uint32_t>();
auto channel = std::stoull(data["channel"].template get<std::string>());

// Try to find a matching client for the provided channel.
auto participant =
Expand Down Expand Up @@ -429,19 +425,22 @@ void ClientAgent::HandleWeb(ws28::Client *client, nlohmann::json &data) {
{"zones", interest.second.zones}});
}

WebPanel::Send(client,
{
{"type", "ca:client"},
{"success", true},
{"ip", (*participant)->GetRemoteAddress().ip},
{"port", (*participant)->GetRemoteAddress().port},
{"state", (*participant)->GetAuthState()},
{"channels", (*participant)->GetLocalChannels().size()},
{"postRemoves", (*participant)->GetPostRemoves().size()},
{"owned", ownedObjs},
{"session", sessionObjs},
{"interests", interests},
});
WebPanel::Send(
client,
{
{"type", "ca:client"},
{"success", true},
{"ip", (*participant)->GetRemoteAddress().ip},
{"port", (*participant)->GetRemoteAddress().port},
{"state", (*participant)->GetAuthState()},
{"channelHi", ((*participant)->GetChannel() >> 32) & 0xFFFFFFFF},
{"channelLo", (*participant)->GetChannel() & 0xFFFFFFFF},
{"channels", (*participant)->GetLocalChannels().size()},
{"postRemoves", (*participant)->GetPostRemoves().size()},
{"owned", ownedObjs},
{"session", sessionObjs},
{"interests", interests},
});
}
}

Expand Down

0 comments on commit c5c8cb5

Please sign in to comment.