mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
support http hooks for rtc: on_play/stop/publish/unpublish (#2509)
* support http hooks for rtc: on_play/stop/publish/unpublish * Update srs_app_rtc_conn.cpp * Update srs_app_rtc_conn.cpp
This commit is contained in:
parent
9bf5005bdd
commit
345b691895
4 changed files with 148 additions and 1 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <srs_protocol_utility.hpp>
|
||||
#include <srs_app_config.hpp>
|
||||
#include <srs_app_statistic.hpp>
|
||||
#include <srs_app_http_hooks.hpp>
|
||||
#include <srs_app_utility.hpp>
|
||||
#include <unistd.h>
|
||||
#include <deque>
|
||||
|
@ -128,6 +129,10 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
|
|||
ruc.req_->vhost = parsed_vhost->arg0();
|
||||
}
|
||||
|
||||
if ((err = http_hooks_on_play(ruc.req_)) != srs_success) {
|
||||
return srs_error_wrap(err, "RTC: http_hooks_on_play");
|
||||
}
|
||||
|
||||
// For client to specifies the candidate(EIP) of server.
|
||||
string eip = r->query_get("eip");
|
||||
if (eip.empty()) {
|
||||
|
@ -242,6 +247,39 @@ srs_error_t SrsGoApiRtcPlay::check_remote_sdp(const SrsSdp& remote_sdp)
|
|||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiRtcPlay::http_hooks_on_play(SrsRequest* req)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// the http hooks will cause context switch,
|
||||
// so we must copy all hooks for the on_connect may freed.
|
||||
// @see https://github.com/ossrs/srs/issues/475
|
||||
vector<string> hooks;
|
||||
|
||||
if (true) {
|
||||
SrsConfDirective* conf = _srs_config->get_vhost_on_play(req->vhost);
|
||||
|
||||
if (!conf) {
|
||||
return err;
|
||||
}
|
||||
|
||||
hooks = conf->args;
|
||||
}
|
||||
|
||||
for (int i = 0; i < (int)hooks.size(); i++) {
|
||||
std::string url = hooks.at(i);
|
||||
if ((err = SrsHttpHooks::on_play(url, req)) != srs_success) {
|
||||
return srs_error_wrap(err, "on_play %s", url.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
SrsGoApiRtcPublish::SrsGoApiRtcPublish(SrsRtcServer* server)
|
||||
{
|
||||
server_ = server;
|
||||
|
@ -351,6 +389,10 @@ srs_error_t SrsGoApiRtcPublish::do_serve_http(ISrsHttpResponseWriter* w, ISrsHtt
|
|||
ruc.req_->vhost = parsed_vhost->arg0();
|
||||
}
|
||||
|
||||
if ((err = http_hooks_on_publish(ruc.req_)) != srs_success) {
|
||||
return srs_error_wrap(err, "RTC: http_hooks_on_publish");
|
||||
}
|
||||
|
||||
// For client to specifies the candidate(EIP) of server.
|
||||
string eip = r->query_get("eip");
|
||||
if (eip.empty()) {
|
||||
|
@ -457,6 +499,39 @@ srs_error_t SrsGoApiRtcPublish::check_remote_sdp(const SrsSdp& remote_sdp)
|
|||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiRtcPublish::http_hooks_on_publish(SrsRequest* req)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (!_srs_config->get_vhost_http_hooks_enabled(req->vhost)) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// the http hooks will cause context switch,
|
||||
// so we must copy all hooks for the on_connect may freed.
|
||||
// @see https://github.com/ossrs/srs/issues/475
|
||||
vector<string> hooks;
|
||||
|
||||
if (true) {
|
||||
SrsConfDirective* conf = _srs_config->get_vhost_on_publish(req->vhost);
|
||||
|
||||
if (!conf) {
|
||||
return err;
|
||||
}
|
||||
|
||||
hooks = conf->args;
|
||||
}
|
||||
|
||||
for (int i = 0; i < (int)hooks.size(); i++) {
|
||||
std::string url = hooks.at(i);
|
||||
if ((err = SrsHttpHooks::on_publish(url, req)) != srs_success) {
|
||||
return srs_error_wrap(err, "rtmp on_publish %s", url.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
SrsGoApiRtcNACK::SrsGoApiRtcNACK(SrsRtcServer* server)
|
||||
{
|
||||
server_ = server;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue