mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
support multiple http hooks for a event.
This commit is contained in:
parent
260bde69d9
commit
30099dfa09
5 changed files with 2003 additions and 1990 deletions
|
@ -190,6 +190,7 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw
|
|||
* nginx v1.5.0: 139524 lines <br/>
|
||||
|
||||
### History
|
||||
* v0.8, 2013-12-08, support multiple http hooks for a event.
|
||||
* v0.8, 2013-12-07, support http callback hooks, on_connect.
|
||||
* v0.8, 2013-12-07, support network based cli and json result, add CherryPy 3.2.4.
|
||||
* v0.8, 2013-12-07, update http/hls/rtmp load test tool [st_load](https://github.com/winlinvip/st-load), use srs rtmp sdk.
|
||||
|
|
|
@ -87,12 +87,14 @@ vhost dev {
|
|||
hls_window 30;
|
||||
#forward 127.0.0.1:19350;
|
||||
#forward 127.0.0.1:1936;
|
||||
on_connect http://127.0.0.1:8085/api/v1/clients;
|
||||
http_hooks {
|
||||
on_connect http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;
|
||||
on_close http://127.0.0.1:8085/api/v1/clients;
|
||||
on_publish http://127.0.0.1:8085/api/v1/streams;
|
||||
on_unpublish http://127.0.0.1:8085/api/v1/streams;
|
||||
on_play http://127.0.0.1:8085/api/v1/sessions;
|
||||
on_stop http://127.0.0.1:8085/api/v1/sessions;
|
||||
}
|
||||
transcode {
|
||||
enabled off;
|
||||
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
|
||||
|
@ -133,6 +135,7 @@ vhost dev {
|
|||
}
|
||||
# the http hook callback vhost, srs will invoke the hooks for specified events.
|
||||
vhost hooks.callback.vhost.com {
|
||||
http_hooks {
|
||||
# when client connect to vhost/app, call the hook,
|
||||
# the request in the POST data string is a object encode by json:
|
||||
# {
|
||||
|
@ -142,7 +145,10 @@ vhost hooks.callback.vhost.com {
|
|||
# if valid, the hook must return HTTP code 200(Stauts OK) and response
|
||||
# an int value specifies the error code(0 corresponding to success):
|
||||
# 0
|
||||
on_connect http://127.0.0.1:8085/api/v1/clients;
|
||||
# support multiple api hooks, format:
|
||||
# on_connect http://xxx/api0 http://xxx/api1 http://xxx/apiN
|
||||
on_connect http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;
|
||||
}
|
||||
}
|
||||
# the mirror filter of ffmpeg, @see: http://ffmpeg.org/ffmpeg-filters.html#Filtering-Introduction
|
||||
vhost mirror.transcode.vhost.com {
|
||||
|
|
11
trunk/src/core/srs_core_client.cpp
Normal file → Executable file
11
trunk/src/core/srs_core_client.cpp
Normal file → Executable file
|
@ -251,16 +251,19 @@ int SrsClient::check_vhost()
|
|||
|
||||
#ifdef SRS_HTTP
|
||||
// HTTP: on_connect
|
||||
std::string on_connect = config->get_vhost_on_connect(req->vhost);
|
||||
if (on_connect.empty()) {
|
||||
SrsConfDirective* on_connect = config->get_vhost_on_connect(req->vhost);
|
||||
if (!on_connect) {
|
||||
srs_info("ignore the empty http callback: on_connect");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = http_hooks->on_connect(on_connect, ip, req)) != ERROR_SUCCESS) {
|
||||
srs_error("hook client failed. ret=%d", ret);
|
||||
for (int i = 0; i < (int)on_connect->args.size(); i++) {
|
||||
std::string url = on_connect->args.at(i);
|
||||
if ((ret = http_hooks->on_connect(url, ip, req)) != ERROR_SUCCESS) {
|
||||
srs_error("hook client failed. url=%s, ret=%d", url.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
|
|
23
trunk/src/core/srs_core_config.cpp
Normal file → Executable file
23
trunk/src/core/srs_core_config.cpp
Normal file → Executable file
|
@ -344,7 +344,10 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<std::string>
|
|||
memcpy(word, pstart, len);
|
||||
word[len - 1] = 0;
|
||||
|
||||
args.push_back(word);
|
||||
std::string word_str = word;
|
||||
if (!word_str.empty()) {
|
||||
args.push_back(word_str);
|
||||
}
|
||||
srs_freepa(word);
|
||||
|
||||
if (ch == ';') {
|
||||
|
@ -559,20 +562,20 @@ SrsConfDirective* SrsConfig::get_vhost(std::string vhost)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
std::string SrsConfig::get_vhost_on_connect(std::string vhost)
|
||||
SrsConfDirective* SrsConfig::get_vhost_on_connect(std::string vhost)
|
||||
{
|
||||
SrsConfDirective* vhost_conf = get_vhost(vhost);
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
|
||||
if (!vhost_conf) {
|
||||
return "";
|
||||
}
|
||||
|
||||
SrsConfDirective* conf = vhost_conf->get("on_connect");
|
||||
if (!conf) {
|
||||
return "";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return conf->arg0();
|
||||
conf = conf->get("http_hooks");
|
||||
if (!conf) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return conf->get("on_connect");
|
||||
}
|
||||
|
||||
bool SrsConfig::get_vhost_enabled(std::string vhost)
|
||||
|
|
2
trunk/src/core/srs_core_config.hpp
Normal file → Executable file
2
trunk/src/core/srs_core_config.hpp
Normal file → Executable file
|
@ -119,7 +119,7 @@ public:
|
|||
public:
|
||||
virtual SrsConfDirective* get_vhost(std::string vhost);
|
||||
virtual bool get_vhost_enabled(std::string vhost);
|
||||
virtual std::string get_vhost_on_connect(std::string vhost);
|
||||
virtual SrsConfDirective* get_vhost_on_connect(std::string vhost);
|
||||
virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope);
|
||||
virtual bool get_transcode_enabled(SrsConfDirective* transcode);
|
||||
virtual std::string get_transcode_ffmpeg(SrsConfDirective* transcode);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue