diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 96a2201b..fffffe24 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -1243,19 +1243,19 @@ void installWebApi() { }); api_regist("/index/api/listStreamPusherProxy", [](API_ARGS_MAP) { CHECK_SECRET(); - s_pusher_proxy.for_each([&val](const std::string& key, const PusherProxy::Ptr& p) { + s_pusher_proxy.for_each([&val](const std::string &key, const PusherProxy::Ptr &p) { Json::Value item = ToJson(p); item["key"] = key; val["data"].append(item); - }); + }, allArgs["key"]); }); api_regist("/index/api/listStreamProxy", [](API_ARGS_MAP) { CHECK_SECRET(); - s_player_proxy.for_each([&val](const std::string& key, const PlayerProxy::Ptr& p) { + s_player_proxy.for_each([&val](const std::string &key, const PlayerProxy::Ptr &p) { Json::Value item = ToJson(p); item["key"] = key; val["data"].append(item); - }); + }, allArgs["key"]); }); // 动态添加rtsp/rtmp拉流代理 [AUTO-TRANSLATED:2616537c] // Dynamically add rtsp/rtmp pull stream proxy diff --git a/server/WebApi.h b/server/WebApi.h index 7881aff9..c0eea389 100755 --- a/server/WebApi.h +++ b/server/WebApi.h @@ -295,12 +295,20 @@ public: return it->second; } - void for_each(const std::function& cb) { + void for_each(const std::function &cb, const std::string &key = {}) { std::lock_guard lck(_mtx); - auto it = _map.begin(); - while (it != _map.end()) { - cb(it->first, it->second); - it++; + if (key.empty()) { + auto it = _map.begin(); + while (it != _map.end()) { + cb(it->first, it->second); + ++it; + } + } else { + auto it = _map.find(key); + if (it == _map.end()) { + throw std::invalid_argument("key not found: " + key); + } + cb(key, it->second); } }