listStreamProxy与listStreamPusherProxy支持key筛选参数
Some checks are pending
Android / build (push) Waiting to run
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Docker / build (push) Waiting to run
Linux / build (push) Waiting to run
Linux_Python / build (push) Waiting to run
macOS / build (push) Waiting to run
macOS_Python / build (push) Waiting to run
Windows / build (push) Waiting to run
Windows_Python / build (push) Waiting to run

This commit is contained in:
xia-chu 2026-03-18 11:23:22 +08:00
parent 22a8a9a2ec
commit fa7b0639d8
2 changed files with 17 additions and 9 deletions

View File

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

View File

@ -295,12 +295,20 @@ public:
return it->second;
}
void for_each(const std::function<void(const std::string&, const Pointer&)>& cb) {
void for_each(const std::function<void(const std::string &, const Pointer &)> &cb, const std::string &key = {}) {
std::lock_guard<std::recursive_mutex> 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);
}
}