1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Refine RTC, reject when config disabled.

This commit is contained in:
winlin 2020-05-03 13:11:38 +08:00
parent f71b833520
commit ef64c5e2bd
7 changed files with 39 additions and 3 deletions

View file

@ -112,6 +112,9 @@
contentType:'application/json', dataType: 'json' contentType:'application/json', dataType: 'json'
}).done(function(data) { }).done(function(data) {
console.log("Got answer: ", data); console.log("Got answer: ", data);
if (data.code) {
reject(data); return;
}
resolve(data.sdp); resolve(data.sdp);
}).fail(function(reason){ }).fail(function(reason){
reject(reason); reject(reason);
@ -120,6 +123,7 @@
}).then(function(answer) { }).then(function(answer) {
return pc.setRemoteDescription(new RTCSessionDescription({type: 'answer', sdp: answer})); return pc.setRemoteDescription(new RTCSessionDescription({type: 'answer', sdp: answer}));
}).catch(function(reason) { }).catch(function(reason) {
pc.close(); $('#rtc_media_player').hide();
throw reason; throw reason;
}); });
}; };

View file

@ -124,6 +124,9 @@
contentType:'application/json', dataType: 'json' contentType:'application/json', dataType: 'json'
}).done(function(data) { }).done(function(data) {
console.log("Got answer: ", data); console.log("Got answer: ", data);
if (data.code) {
reject(data); return;
}
resolve(data.sdp); resolve(data.sdp);
}).fail(function(reason){ }).fail(function(reason){
reject(reason); reject(reason);
@ -132,6 +135,12 @@
}).then(function(answer) { }).then(function(answer) {
return pc.setRemoteDescription(new RTCSessionDescription({type: 'answer', sdp: answer})); return pc.setRemoteDescription(new RTCSessionDescription({type: 'answer', sdp: answer}));
}).catch(function(reason) { }).catch(function(reason) {
pc.getLocalStreams().forEach(function(stream){
stream.getTracks().forEach(function(track) {
track.stop();
});
});
pc.close(); $('#rtc_media_player').hide();
throw reason; throw reason;
}); });
}; };

View file

@ -4679,7 +4679,7 @@ srs_utime_t SrsConfig::get_stream_caster_gb28181_sip_query_catalog_interval(SrsC
return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_SECONDS); return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
} }
int SrsConfig::get_rtc_server_enabled() bool SrsConfig::get_rtc_server_enabled()
{ {
SrsConfDirective* conf = root->get("rtc_server"); SrsConfDirective* conf = root->get("rtc_server");
return get_rtc_server_enabled(conf); return get_rtc_server_enabled(conf);

View file

@ -521,7 +521,7 @@ public:
// rtc section // rtc section
public: public:
virtual int get_rtc_server_enabled(); virtual bool get_rtc_server_enabled();
virtual bool get_rtc_server_enabled(SrsConfDirective* conf); virtual bool get_rtc_server_enabled(SrsConfDirective* conf);
virtual int get_rtc_server_listen(); virtual int get_rtc_server_listen();
virtual std::string get_rtc_server_candidates(); virtual std::string get_rtc_server_candidates();

View file

@ -918,6 +918,17 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
request.vhost = parsed_vhost->arg0(); request.vhost = parsed_vhost->arg0();
} }
// Whether enabled.
bool server_enabled = _srs_config->get_rtc_server_enabled();
bool rtc_enabled = _srs_config->get_rtc_enabled(request.vhost);
if (server_enabled && !rtc_enabled) {
srs_warn("RTC disabled in vhost %s", request.vhost.c_str());
}
if (!server_enabled || !rtc_enabled) {
return srs_error_new(ERROR_RTC_DISABLED, "Disabled server=%d, rtc=%d, vhost=%s",
server_enabled, rtc_enabled, request.vhost.c_str());
}
// TODO: FIXME: Maybe need a better name? // TODO: FIXME: Maybe need a better name?
// TODO: FIXME: When server enabled, but vhost disabled, should report error. // TODO: FIXME: When server enabled, but vhost disabled, should report error.
SrsRtcSession* rtc_session = NULL; SrsRtcSession* rtc_session = NULL;
@ -1232,6 +1243,17 @@ srs_error_t SrsGoApiRtcPublish::do_serve_http(ISrsHttpResponseWriter* w, ISrsHtt
request.vhost = parsed_vhost->arg0(); request.vhost = parsed_vhost->arg0();
} }
// Whether enabled.
bool server_enabled = _srs_config->get_rtc_server_enabled();
bool rtc_enabled = _srs_config->get_rtc_enabled(request.vhost);
if (server_enabled && !rtc_enabled) {
srs_warn("RTC disabled in vhost %s", request.vhost.c_str());
}
if (!server_enabled || !rtc_enabled) {
return srs_error_new(ERROR_RTC_DISABLED, "Disabled server=%d, rtc=%d, vhost=%s",
server_enabled, rtc_enabled, request.vhost.c_str());
}
// TODO: FIXME: Maybe need a better name? // TODO: FIXME: Maybe need a better name?
// TODO: FIXME: When server enabled, but vhost disabled, should report error. // TODO: FIXME: When server enabled, but vhost disabled, should report error.
SrsRtcSession* rtc_session = NULL; SrsRtcSession* rtc_session = NULL;

View file

@ -528,7 +528,7 @@ srs_error_t SrsMediaDesc::parse_attr_mid(const std::string& value)
std::istringstream is(value); std::istringstream is(value);
// mid_ means m-line id // mid_ means m-line id
FETCH(is, mid_); FETCH(is, mid_);
srs_trace("mid=%s", mid_.c_str()); srs_verbose("mid=%s", mid_.c_str());
return err; return err;
} }

View file

@ -349,6 +349,7 @@
#define ERROR_RTC_SDP_EXCHANGE 5018 #define ERROR_RTC_SDP_EXCHANGE 5018
#define ERROR_RTC_API_BODY 5019 #define ERROR_RTC_API_BODY 5019
#define ERROR_RTC_SOURCE_BUSY 5020 #define ERROR_RTC_SOURCE_BUSY 5020
#define ERROR_RTC_DISABLED 5021
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
// GB28181 API error. // GB28181 API error.