AI: API: Add clients field to on_play/on_stop webhooks and total field to HTTP API. v7.0.107 (#4147)

This commit is contained in:
OSSRS-AI 2025-10-26 16:28:20 -04:00 committed by winlin
parent 1d9105396d
commit 5fc1f2d2e5
5 changed files with 34 additions and 3 deletions

View File

@ -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

View File

@ -7,6 +7,7 @@ The changelog for SRS.
<a name="v7-changes"></a>
## 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)

View File

@ -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);

View File

@ -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();

View File

@ -9,6 +9,6 @@
#define VERSION_MAJOR 7
#define VERSION_MINOR 0
#define VERSION_REVISION 106
#define VERSION_REVISION 107
#endif