diff --git a/src/Services/WhipClient.h b/src/Services/WhipClient.h index 9ab9bd4..b6ceaae 100644 --- a/src/Services/WhipClient.h +++ b/src/Services/WhipClient.h @@ -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()(rng); @@ -106,7 +114,7 @@ namespace snoop std::lock_guard lk(m_mtx); if (!m_started) return; - m_trackOpen = false; + m_trackOpen = false; m_track.reset(); m_pc.reset(); @@ -185,12 +193,42 @@ namespace snoop return {answer, resourceUrl}; } + // std::pair 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 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") : ""); + + 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)