diff --git a/src/controller/controller_api.cpp b/src/controller/controller_api.cpp index 6515e7e1..4a6ec4ed 100644 --- a/src/controller/controller_api.cpp +++ b/src/controller/controller_api.cpp @@ -554,7 +554,10 @@ int Controller::handleAPIConnection(Socket::Connection & conn){ } } if (Request.isMember("active_streams")){ - Controller::fillActive(Request["active_streams"], Response["active_streams"]); + Controller::fillActive(Request["active_streams"], Response["active_streams"], true); + } + if (Request.isMember("stats_streams")){ + Controller::fillActive(Request["stats_streams"], Response["stats_streams"]); } Controller::writeConfig(); diff --git a/src/controller/controller_statistics.cpp b/src/controller/controller_statistics.cpp index 24b45300..03a6d05f 100644 --- a/src/controller/controller_statistics.cpp +++ b/src/controller/controller_statistics.cpp @@ -601,7 +601,7 @@ void Controller::fillClients(JSON::Value & req, JSON::Value & rep){ /// This takes a "active_streams" request, and fills in the response data. /// /// \api -/// `"active_streams"` requests are always empty (passed data is ignored), and are responded to as: +/// `"active_streams"` and `"stats_streams"` requests may either be empty, in which case the response looks like this: /// ~~~~~~~~~~~~~~~{.js} /// [ /// //Array of stream names @@ -610,17 +610,43 @@ void Controller::fillClients(JSON::Value & req, JSON::Value & rep){ /// "streamC" /// ] /// ~~~~~~~~~~~~~~~ +/// `"stats_streams"` will list all streams that any statistics data is available for, and only those. `"active_streams"` only lists streams that are currently active, and only those. +/// If the request is an array, which may contain any of the following elements: +/// ~~~~~~~~~~~~~~~{.js} +/// [ +/// //Array of requested data types +/// "clients", //Current viewer count +/// "lastms" //Current position in the live buffer, if live +/// ] +/// ~~~~~~~~~~~~~~~ +/// In which case the response is changed into this format: +/// ~~~~~~~~~~~~~~~{.js} +/// { +/// //Object of stream names, containing arrays in the same order as the request, with the same data +/// "streamA":[ +/// 0, +/// 60000 +/// ] +/// "streamB":[ +/// //.... +/// ] +/// //... +/// } +/// ~~~~~~~~~~~~~~~ /// All streams that any statistics data is available for are listed, and only those streams. -void Controller::fillActive(JSON::Value & req, JSON::Value & rep){ +void Controller::fillActive(JSON::Value & req, JSON::Value & rep, bool onlyNow){ //collect the data first std::set streams; std::map clients; - unsigned int t = Util::epoch() - 5; + unsigned int t = Util::epoch() - 2; //check all sessions if (sessions.size()){ for (std::map::iterator it = sessions.begin(); it != sessions.end(); it++){ - streams.insert(it->first.streamName); + if (onlyNow || it->second.hasDataFor(t)){ + streams.insert(it->first.streamName); + } if (it->second.hasDataFor(t)){ + streams.insert(it->first.streamName); clients[it->first.streamName]++; } } diff --git a/src/controller/controller_statistics.h b/src/controller/controller_statistics.h index 02ad1350..0a5d8972 100644 --- a/src/controller/controller_statistics.h +++ b/src/controller/controller_statistics.h @@ -86,7 +86,7 @@ namespace Controller { void parseStatistics(char * data, size_t len, unsigned int id); void killStatistics(char * data, size_t len, unsigned int id); void fillClients(JSON::Value & req, JSON::Value & rep); - void fillActive(JSON::Value & req, JSON::Value & rep); + void fillActive(JSON::Value & req, JSON::Value & rep, bool onlyNow = false); void fillTotals(JSON::Value & req, JSON::Value & rep); void SharedMemStats(void * config); bool hasViewers(std::string streamName);