diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 9498dcbd8..7d4de2a11 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -1152,8 +1152,12 @@ vhost hooks.callback.srs.com { # "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", # "stream": "livestream", "param":"?token=xxx&salt=yyy", # "pageUrl": "http://www.test.com/live.html", "server_id": "vid-werty", - # "stream_url": "video.test.com/live/livestream", "stream_id": "vid-124q9y3" + # "stream_url": "video.test.com/live/livestream", "stream_id": "vid-124q9y3", + # "clients": 3 # } + # Note: The "clients" field indicates the current number of clients playing this stream + # (including the client that just started playing). This is useful for on-demand streaming + # scenarios where you want to start a publisher when the first client connects (clients=1). # if valid, the hook must return HTTP code 200(Status OK) and response # an int value specifies the error code(0 corresponding to success): # 0 @@ -1172,8 +1176,12 @@ vhost hooks.callback.srs.com { # "client_id": "9308h583", # "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", # "stream": "livestream", "param":"?token=xxx&salt=yyy", "server_id": "vid-werty", - # "stream_url": "video.test.com/live/livestream", "stream_id": "vid-124q9y3" + # "stream_url": "video.test.com/live/livestream", "stream_id": "vid-124q9y3", + # "clients": 2 # } + # Note: The "clients" field indicates the current number of clients still playing this stream + # (after the client has stopped). This is useful for on-demand streaming scenarios where you + # want to stop a publisher when the last client disconnects (clients=0). # if valid, the hook must return HTTP code 200(Status OK) and response # an int value specifies the error code(0 corresponding to success): # 0 diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 9ce73d2d3..659408d62 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -7,6 +7,7 @@ The changelog for SRS. ## SRS 7.0 Changelog +* v7.0, 2025-10-26, AI: API: Add clients field to on_play/on_stop webhooks and total field to HTTP API. v7.0.107 (#4147) * v7.0, 2025-10-26, AI: WebRTC: Fix camera/microphone not released after closing publisher. v7.0.106 (#4261) * v7.0, 2025-10-26, AI: Build: Improve dependency checking to report all missing dependencies at once. v7.0.105 (#4293) * v7.0, 2025-10-26, AI: HLS: Support hls_master_m3u8_path_relative for reverse proxy compatibility. v7.0.104 (#4338) diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index cf39aaea9..72f414b15 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -781,6 +781,16 @@ srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa if (r->is_http_get()) { if (!stream) { + // Add total count of streams + int64_t send_bytes = 0, recv_bytes = 0, nstreams = 0, nclients = 0, total_nclients = 0, nerrs = 0; + if ((err = stat_->dumps_metrics(send_bytes, recv_bytes, nstreams, nclients, total_nclients, nerrs)) != srs_success) { + int code = srs_error_code(err); + srs_freep(err); + return srs_api_response_code(w, r, code); + } + obj->set("total", SrsJsonAny::integer(nstreams)); + + // Add streams SrsJsonArray *data = SrsJsonAny::array(); obj->set("streams", data); @@ -843,6 +853,16 @@ srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa if (r->is_http_get()) { if (!client) { + // Add total count of clients + int64_t send_bytes = 0, recv_bytes = 0, nstreams = 0, nclients = 0, total_nclients = 0, nerrs = 0; + if ((err = stat_->dumps_metrics(send_bytes, recv_bytes, nstreams, nclients, total_nclients, nerrs)) != srs_success) { + int code = srs_error_code(err); + srs_freep(err); + return srs_api_response_code(w, r, code); + } + obj->set("total", SrsJsonAny::integer(nclients)); + + // Add clients SrsJsonArray *data = SrsJsonAny::array(); obj->set("clients", data); diff --git a/trunk/src/app/srs_app_http_hooks.cpp b/trunk/src/app/srs_app_http_hooks.cpp index 69af6de0b..2e2e26eff 100644 --- a/trunk/src/app/srs_app_http_hooks.cpp +++ b/trunk/src/app/srs_app_http_hooks.cpp @@ -241,6 +241,7 @@ srs_error_t SrsHttpHooks::on_play(string url, ISrsRequest *req) SrsStatisticStream *stream = stat->find_stream_by_url(req->get_stream_url()); if (stream) { obj->set("stream_id", SrsJsonAny::str(stream->id_.c_str())); + obj->set("clients", SrsJsonAny::integer(stream->nb_clients_)); } std::string data = obj->dumps(); @@ -282,6 +283,7 @@ void SrsHttpHooks::on_stop(string url, ISrsRequest *req) SrsStatisticStream *stream = stat->find_stream_by_url(req->get_stream_url()); if (stream) { obj->set("stream_id", SrsJsonAny::str(stream->id_.c_str())); + obj->set("clients", SrsJsonAny::integer(stream->nb_clients_)); } std::string data = obj->dumps(); diff --git a/trunk/src/core/srs_core_version7.hpp b/trunk/src/core/srs_core_version7.hpp index 23b1ffe90..ccc01c635 100644 --- a/trunk/src/core/srs_core_version7.hpp +++ b/trunk/src/core/srs_core_version7.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 7 #define VERSION_MINOR 0 -#define VERSION_REVISION 106 +#define VERSION_REVISION 107 #endif \ No newline at end of file