Tweaked fillActive to have both now and historic modes
Made streams no longer show as active for ~10m after being active.
This commit is contained in:
parent
56232c1fba
commit
2029b35361
3 changed files with 35 additions and 6 deletions
|
@ -554,7 +554,10 @@ int Controller::handleAPIConnection(Socket::Connection & conn){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Request.isMember("active_streams")){
|
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();
|
Controller::writeConfig();
|
||||||
|
|
|
@ -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.
|
/// This takes a "active_streams" request, and fills in the response data.
|
||||||
///
|
///
|
||||||
/// \api
|
/// \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}
|
/// ~~~~~~~~~~~~~~~{.js}
|
||||||
/// [
|
/// [
|
||||||
/// //Array of stream names
|
/// //Array of stream names
|
||||||
|
@ -610,17 +610,43 @@ void Controller::fillClients(JSON::Value & req, JSON::Value & rep){
|
||||||
/// "streamC"
|
/// "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.
|
/// 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
|
//collect the data first
|
||||||
std::set<std::string> streams;
|
std::set<std::string> streams;
|
||||||
std::map<std::string, unsigned long> clients;
|
std::map<std::string, unsigned long> clients;
|
||||||
unsigned int t = Util::epoch() - 5;
|
unsigned int t = Util::epoch() - 2;
|
||||||
//check all sessions
|
//check all sessions
|
||||||
if (sessions.size()){
|
if (sessions.size()){
|
||||||
for (std::map<sessIndex, statSession>::iterator it = sessions.begin(); it != sessions.end(); it++){
|
for (std::map<sessIndex, statSession>::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)){
|
if (it->second.hasDataFor(t)){
|
||||||
|
streams.insert(it->first.streamName);
|
||||||
clients[it->first.streamName]++;
|
clients[it->first.streamName]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ namespace Controller {
|
||||||
void parseStatistics(char * data, size_t len, unsigned int id);
|
void parseStatistics(char * data, size_t len, unsigned int id);
|
||||||
void killStatistics(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 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 fillTotals(JSON::Value & req, JSON::Value & rep);
|
||||||
void SharedMemStats(void * config);
|
void SharedMemStats(void * config);
|
||||||
bool hasViewers(std::string streamName);
|
bool hasViewers(std::string streamName);
|
||||||
|
|
Loading…
Add table
Reference in a new issue