From ddf351d35008899896075b72e6542c9d1d3a8c43 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Mon, 18 Nov 2019 10:46:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0close=5Fstreams=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebApi.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 1c7eab29..f4a998ca 100644 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -445,6 +445,39 @@ void installWebApi() { } }); + //批量主动关断流,包括关断拉流、推流 + //测试url http://127.0.0.1/index/api/close_streams?schema=rtsp&vhost=__defaultVhost__&app=live&stream=obs&force=1 + API_REGIST(api,close_streams,{ + CHECK_SECRET(); + //筛选命中个数 + int count_hit = 0; + int count_closed = 0; + MediaSource::for_each_media([&](const string &schema, + const string &vhost, + const string &app, + const string &stream, + const MediaSource::Ptr &media){ + if(!allArgs["schema"].empty() && allArgs["schema"] != schema){ + return; + } + if(!allArgs["vhost"].empty() && allArgs["vhost"] != vhost){ + return; + } + if(!allArgs["app"].empty() && allArgs["app"] != app){ + return; + } + if(!allArgs["stream"].empty() && allArgs["stream"] != stream){ + return; + } + ++count_hit; + if(media->close(allArgs["force"].as())){ + ++count_closed; + } + }); + val["count_hit"] = count_hit; + val["count_closed"] = count_closed; + }); + //获取所有TcpSession列表信息 //可以根据本地端口和远端ip来筛选 //测试url(筛选某端口下的tcp会话) http://127.0.0.1/index/api/getAllSession?local_port=1935