mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix #442: HTTP API kickoff client.
This commit is contained in:
parent
0e3128d3e3
commit
e8c0ca7af0
10 changed files with 121 additions and 18 deletions
70
trunk/src/app/srs_app_http_api.cpp
Normal file → Executable file
70
trunk/src/app/srs_app_http_api.cpp
Normal file → Executable file
|
@ -26,6 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#ifdef SRS_AUTO_HTTP_API
|
||||
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
using namespace std;
|
||||
|
||||
#include <srs_kernel_log.hpp>
|
||||
|
@ -39,6 +40,7 @@ using namespace std;
|
|||
#include <srs_rtmp_stack.hpp>
|
||||
#include <srs_app_dvr.hpp>
|
||||
#include <srs_app_config.hpp>
|
||||
#include <srs_app_source.hpp>
|
||||
#include <srs_app_http_conn.hpp>
|
||||
|
||||
SrsGoApiRoot::SrsGoApiRoot()
|
||||
|
@ -459,21 +461,67 @@ SrsGoApiStreams::~SrsGoApiStreams()
|
|||
|
||||
int SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||
{
|
||||
std::stringstream data;
|
||||
int ret = ERROR_SUCCESS;
|
||||
SrsStatistic* stat = SrsStatistic::instance();
|
||||
int ret = stat->dumps_streams(data);
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
ss << SRS_JOBJECT_START
|
||||
<< SRS_JFIELD_ERROR(ret) << SRS_JFIELD_CONT
|
||||
<< SRS_JFIELD_ORG("server", stat->server_id()) << SRS_JFIELD_CONT
|
||||
<< SRS_JFIELD_ORG("streams", data.str())
|
||||
<< SRS_JOBJECT_END;
|
||||
|
||||
return srs_http_response_json(w, ss.str());
|
||||
|
||||
if (r->is_http_delete()) {
|
||||
// path: {pattern}{stream_id}
|
||||
// e.g. /api/v1/streams/100 pattern= /api/v1/streams/, stream_id=100
|
||||
string sid = r->path().substr((int)entry->pattern.length());
|
||||
if (sid.empty()) {
|
||||
ret = ERROR_REQUEST_DATA;
|
||||
srs_error("invalid param, stream_id=%s. ret=%d", sid.c_str(), ret);
|
||||
|
||||
ss << SRS_JOBJECT_START
|
||||
<< SRS_JFIELD_ERROR(ret)
|
||||
<< SRS_JOBJECT_END;
|
||||
|
||||
return srs_http_response_json(w, ss.str());
|
||||
}
|
||||
|
||||
int stream_id = ::atoi(sid.c_str());
|
||||
SrsStatisticStream* stream = stat->find_stream(stream_id);
|
||||
if (stream == NULL) {
|
||||
ret = ERROR_RTMP_STREAM_NOT_FOUND;
|
||||
srs_error("stream stream_id=%s not found. ret=%d", sid.c_str(), ret);
|
||||
|
||||
ss << SRS_JOBJECT_START
|
||||
<< SRS_JFIELD_ERROR(ret)
|
||||
<< SRS_JOBJECT_END;
|
||||
|
||||
return srs_http_response_json(w, ss.str());
|
||||
}
|
||||
|
||||
SrsSource* source = SrsSource::fetch(stream->vhost->vhost, stream->app, stream->stream);
|
||||
if (source) {
|
||||
source->set_expired();
|
||||
srs_warn("disconnent stream=%d successfully. vhost=%s, app=%s, stream=%s.",
|
||||
stream_id, stream->vhost->vhost.c_str(), stream->app.c_str(), stream->stream.c_str());
|
||||
} else {
|
||||
ret = ERROR_SOURCE_NOT_FOUND;
|
||||
}
|
||||
|
||||
ss << SRS_JOBJECT_START
|
||||
<< SRS_JFIELD_ERROR(ret)
|
||||
<< SRS_JOBJECT_END;
|
||||
|
||||
return srs_http_response_json(w, ss.str());
|
||||
} else {
|
||||
std::stringstream data;
|
||||
int ret = stat->dumps_streams(data);
|
||||
|
||||
ss << SRS_JOBJECT_START
|
||||
<< SRS_JFIELD_ERROR(ret) << SRS_JFIELD_CONT
|
||||
<< SRS_JFIELD_ORG("server", stat->server_id()) << SRS_JFIELD_CONT
|
||||
<< SRS_JFIELD_ORG("streams", data.str())
|
||||
<< SRS_JOBJECT_END;
|
||||
|
||||
return srs_http_response_json(w, ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SrsHttpApi::SrsHttpApi(IConnectionManager* cm, st_netfd_t fd, SrsHttpServeMux* m)
|
||||
: SrsConnection(cm, fd)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue