added debug steps for whipclient

This commit is contained in:
tdv
2025-10-21 19:29:41 +03:00
parent 6bfee40029
commit aec6a51ae6

View File

@@ -62,6 +62,14 @@ namespace snoop
{
try {
const std::string offer = std::string(desc);
spdlog::info("Local SDP (first 8 lines):");
{
std::istringstream is(offer);
for (int i=0; i<8 && is; ++i) {
std::string line; std::getline(is, line);
spdlog::info(" {}", line);
}
}
auto [answer, resourceUrl] = PostOfferWHIP(offer);
m_resourceUrl = resourceUrl;
m_pc->setRemoteDescription(rtc::Description(answer, "answer"));
@@ -81,14 +89,14 @@ namespace snoop
m_track = m_pc->addTrack(audioDesc);
// IMPORTANT: wait for SRTP sender to be ready
m_track->onOpen([this] {
m_track->onOpen([this]
{
spdlog::info("WHIP track opened");
m_trackOpen = true;
});
m_track->onClosed([this] {
m_trackOpen = true; });
m_track->onClosed([this]
{
spdlog::info("WHIP track closed");
m_trackOpen = false;
});
m_trackOpen = false; });
// Initialize RTP state (random SSRC/seq)
std::mt19937 rng{std::random_device{}()};
m_ssrc = std::uniform_int_distribution<uint32_t>()(rng);
@@ -185,12 +193,42 @@ namespace snoop
return {answer, resourceUrl};
}
// std::pair<std::string, std::string> PostOfferWHIP(const std::string &sdpOffer)
// {
// auto [cli, path] = MakeClientForUrl(sdpOffer, m_p.whipUrl);
// auto res = cli->Post(path.c_str(), sdpOffer, "application/sdp");
// auto [answer, resUrl] = ExtractAnswerAndLocation(res);
// return {answer, resUrl};
// }
std::pair<std::string, std::string> PostOfferWHIP(const std::string &sdpOffer)
{
auto [cli, path] = MakeClientForUrl(sdpOffer, m_p.whipUrl);
auto res = cli->Post(path.c_str(), sdpOffer, "application/sdp");
auto [answer, resUrl] = ExtractAnswerAndLocation(res);
return {answer, resUrl};
httplib::Headers hs{
{"Content-Type", "application/sdp"},
{"Accept", "application/sdp"}};
spdlog::info("WHIP POST url='{}' path='{}' offer-bytes={}", m_p.whipUrl, path, sdpOffer.size());
auto res = cli->Post(path.c_str(), hs, sdpOffer, "application/sdp");
if (!res)
throw std::runtime_error("No HTTP result (network?)");
spdlog::info("WHIP POST -> status={} len={} location='{}'",
res->status, res->body.size(),
res->has_header("Location") ? res->get_header_value("Location") : "<none>");
if (res->status != 201 && res->status != 200)
{
spdlog::error("WHIP POST body:\n{}", res->body);
throw std::runtime_error("Unexpected WHIP status: " + std::to_string(res->status));
}
std::string answer = res->body;
std::string resourceUrl;
if (res->has_header("Location"))
resourceUrl = res->get_header_value("Location");
return {answer, resourceUrl};
}
void PatchCandidateWHIP(const rtc::Candidate &cand)