1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00

support multiple http hooks for a event.

This commit is contained in:
winlin 2013-12-08 10:46:15 +08:00
parent 260bde69d9
commit 30099dfa09
5 changed files with 2003 additions and 1990 deletions

View file

@ -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/> * nginx v1.5.0: 139524 lines <br/>
### History ### 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 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, 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. * v0.8, 2013-12-07, update http/hls/rtmp load test tool [st_load](https://github.com/winlinvip/st-load), use srs rtmp sdk.

View file

@ -87,12 +87,14 @@ vhost dev {
hls_window 30; hls_window 30;
#forward 127.0.0.1:19350; #forward 127.0.0.1:19350;
#forward 127.0.0.1:1936; #forward 127.0.0.1:1936;
on_connect http://127.0.0.1:8085/api/v1/clients; http_hooks {
on_close http://127.0.0.1:8085/api/v1/clients; on_connect http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;
on_publish http://127.0.0.1:8085/api/v1/streams; on_close http://127.0.0.1:8085/api/v1/clients;
on_unpublish http://127.0.0.1:8085/api/v1/streams; on_publish http://127.0.0.1:8085/api/v1/streams;
on_play http://127.0.0.1:8085/api/v1/sessions; on_unpublish http://127.0.0.1:8085/api/v1/streams;
on_stop http://127.0.0.1:8085/api/v1/sessions; on_play http://127.0.0.1:8085/api/v1/sessions;
on_stop http://127.0.0.1:8085/api/v1/sessions;
}
transcode { transcode {
enabled off; enabled off;
ffmpeg ./objs/ffmpeg/bin/ffmpeg; ffmpeg ./objs/ffmpeg/bin/ffmpeg;
@ -133,16 +135,20 @@ vhost dev {
} }
# the http hook callback vhost, srs will invoke the hooks for specified events. # the http hook callback vhost, srs will invoke the hooks for specified events.
vhost hooks.callback.vhost.com { vhost hooks.callback.vhost.com {
# when client connect to vhost/app, call the hook, http_hooks {
# the request in the POST data string is a object encode by json: # when client connect to vhost/app, call the hook,
# { # the request in the POST data string is a object encode by json:
# "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", # {
# "pageUrl": "http://www.test.com/live.html" # "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",
# } # "pageUrl": "http://www.test.com/live.html"
# if valid, the hook must return HTTP code 200(Stauts OK) and response # }
# an int value specifies the error code(0 corresponding to success): # if valid, the hook must return HTTP code 200(Stauts OK) and response
# 0 # an int value specifies the error code(0 corresponding to success):
on_connect http://127.0.0.1:8085/api/v1/clients; # 0
# 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 # the mirror filter of ffmpeg, @see: http://ffmpeg.org/ffmpeg-filters.html#Filtering-Introduction
vhost mirror.transcode.vhost.com { vhost mirror.transcode.vhost.com {

13
trunk/src/core/srs_core_client.cpp Normal file → Executable file
View file

@ -251,15 +251,18 @@ int SrsClient::check_vhost()
#ifdef SRS_HTTP #ifdef SRS_HTTP
// HTTP: on_connect // HTTP: on_connect
std::string on_connect = config->get_vhost_on_connect(req->vhost); SrsConfDirective* on_connect = config->get_vhost_on_connect(req->vhost);
if (on_connect.empty()) { if (!on_connect) {
srs_info("ignore the empty http callback: on_connect"); srs_info("ignore the empty http callback: on_connect");
return ret; return ret;
} }
if ((ret = http_hooks->on_connect(on_connect, ip, req)) != ERROR_SUCCESS) { for (int i = 0; i < (int)on_connect->args.size(); i++) {
srs_error("hook client failed. ret=%d", ret); std::string url = on_connect->args.at(i);
return ret; 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 #endif

23
trunk/src/core/srs_core_config.cpp Normal file → Executable file
View file

@ -344,7 +344,10 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<std::string>
memcpy(word, pstart, len); memcpy(word, pstart, len);
word[len - 1] = 0; 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); srs_freepa(word);
if (ch == ';') { if (ch == ';') {
@ -559,20 +562,20 @@ SrsConfDirective* SrsConfig::get_vhost(std::string vhost)
return NULL; 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) { 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) bool SrsConfig::get_vhost_enabled(std::string vhost)

2
trunk/src/core/srs_core_config.hpp Normal file → Executable file
View file

@ -119,7 +119,7 @@ public:
public: public:
virtual SrsConfDirective* get_vhost(std::string vhost); virtual SrsConfDirective* get_vhost(std::string vhost);
virtual bool get_vhost_enabled(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 SrsConfDirective* get_transcode(std::string vhost, std::string scope);
virtual bool get_transcode_enabled(SrsConfDirective* transcode); virtual bool get_transcode_enabled(SrsConfDirective* transcode);
virtual std::string get_transcode_ffmpeg(SrsConfDirective* transcode); virtual std::string get_transcode_ffmpeg(SrsConfDirective* transcode);