WHIP: Improve HTTP DELETE for notifying server unpublish event (#3539)

This PR improves the functionality of the HTTP DELETE method used by WHIP to notify the server when the client stops publishing. The URL is parsed from the location header returned by SRS, and the URL is refined with the addition of the action=delete parameter to ensure more accurate identification of the DELETE request.

Furthermore, SRS will disconnect and close the session, enabling the client to publish the stream again quickly and easily. This update eliminates the approximately 30-second waiting period previously required for republishing the stream after an unpublish event.

Overall, this update provides a more effective and efficient method for notifying the server about unpublish events and will enhance the workflow experience for users of the WHIP platform.

-------

Co-authored-by: Haibo Chen <495810242@qq.com>
Co-authored-by: ChenGH <chengh_math@126.com>
pull/3538/head
Winlin 2 years ago committed by winlin
parent 26aabe413d
commit 7cf8c48157

@ -581,6 +581,7 @@ srs_error_t SrsGoApiRtcPublish::http_hooks_on_publish(SrsRequest* req)
SrsGoApiRtcWhip::SrsGoApiRtcWhip(SrsRtcServer* server)
{
server_ = server;
publish_ = new SrsGoApiRtcPublish(server);
play_ = new SrsGoApiRtcPlay(server);
}
@ -601,7 +602,12 @@ srs_error_t SrsGoApiRtcWhip::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
// Client stop publish.
// TODO: FIXME: Stop and cleanup the RTC session.
if (r->method() == SRS_CONSTS_HTTP_DELETE) {
srs_trace("WHIP: Delete stream %s", r->url().c_str());
string username = r->query_get("session");
SrsRtcConnection* session = server_->find_session_by_username(username);
if (session) session->expire();
srs_trace("WHIP: Delete session=%s, p=%p, url=%s", username.c_str(), session, r->url().c_str());
w->header()->set_content_length(0);
w->write_header(SRS_CONSTS_HTTP_OK);
return w->write(NULL, 0);
}
@ -620,7 +626,8 @@ srs_error_t SrsGoApiRtcWhip::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
// Setup the content type to SDP.
w->header()->set("Content-Type", "application/sdp");
// The location for DELETE resource, not required by SRS, but required by WHIP.
w->header()->set("Location", srs_fmt("/rtc/v1/whip/?app=%s&stream=%s", ruc.req_->app.c_str(), ruc.req_->stream.c_str()));
w->header()->set("Location", srs_fmt("/rtc/v1/whip/?action=delete&app=%s&stream=%s&session=%s",
ruc.req_->app.c_str(), ruc.req_->stream.c_str(), ruc.session_id_.c_str()));
w->header()->set_content_length((int64_t)sdp.length());
// Must be 201, see https://datatracker.ietf.org/doc/draft-ietf-wish-whip/
w->write_header(201);

@ -58,6 +58,7 @@ private:
class SrsGoApiRtcWhip : public ISrsHttpHandler
{
private:
SrsRtcServer* server_;
SrsGoApiRtcPublish* publish_;
SrsGoApiRtcPlay* play_;
public:

Loading…
Cancel
Save