Skip to content

Commit

Permalink
For #1638, #307, rtc conf support ENV.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Mar 14, 2020
1 parent d21ef10 commit 51af2b4
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 227 deletions.
19 changes: 19 additions & 0 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,25 @@ srt_server {
default_app live;
}

#############################################################################################
# WebRTC server section
#############################################################################################
rtc {
# Whether enable WebRTC server.
# default: off
enabled on;
# The udp listen port, we will reuse it for connections.
# default: 8080
listen 8000;
# The exposed candidate IP, response in SDP candidate line.
# It can be:
# * Retrieve server IP automatically, specified by stats.network for multiple networks.
# $CANDIDATE Read the IP from ENV variable $EIP, see https://github.com/ossrs/srs/issues/307#issuecomment-599028124
# x.x.x.x A specified IP address or DNS name, which can be access by client such as Chrome.
# default: *
candidate *;
}

#############################################################################################
# Kafka sections
#############################################################################################
Expand Down
38 changes: 15 additions & 23 deletions trunk/conf/rtc.conf
Original file line number Diff line number Diff line change
@@ -1,40 +1,32 @@
# main config for srs.
# @see full.conf for detail config.

listen 1935;
max_connections 1000;
srs_log_tank file;
srs_log_tank console;
srs_log_file ./objs/srs.log;
http_api {
enabled on;
listen 1985;
raw_api {
enabled on;
allow_reload on;
allow_query on;
allow_update on;
}
}

http_server {
enabled on;
listen 8080;
dir ./objs/nginx/html;
}
rtc {

http_api {
enabled on;
listen 9527;
# candidate device ip: *(all interface), 192.168.1.1 ...
candidate *;
listen 1985;
}
stats {
network 0;
disk sda sdb xvda xvdb;
}
vhost __defaultVhost__ {
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
}
rtc {
enabled on;
# Listen at udp://8000
listen 8000;
# The * means using IP of network interface stats.network,
# For example, if stats.network=0, then use IP of eth0 as candidate.
# @see https://github.com/ossrs/srs/issues/307#issuecomment-599028124
candidate *;
}

vhost __defaultVhost__ {
}

6 changes: 3 additions & 3 deletions trunk/research/players/rtc.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<body>

rtc_media_player: <br>
<video id = "rtc_media_player" autoplay></video>
<video id = "rtc_media_player" autoplay controls></video>

</body>

Expand All @@ -16,7 +16,7 @@
var PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
var SessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription;

var url = "http://hw.com:1985/api/v1/sdp/";
var url = "http://localhost:1985/api/v1/sdp/";

var method = "POST";
var shouldBeAsync = true;
Expand All @@ -40,7 +40,7 @@

pc.setLocalDescription(desc);

var sdp_json = {"sdp":desc.sdp, "app":"webrtc", "stream":"test"};
var sdp_json = {"sdp":desc.sdp, "app":"live", "stream":"livestream"};
request.send(JSON.stringify(sdp_json));
};

Expand Down
97 changes: 0 additions & 97 deletions trunk/research/players/rtc_upload.html

This file was deleted.

90 changes: 0 additions & 90 deletions trunk/research/players/srs_rtc_player.html

This file was deleted.

7 changes: 6 additions & 1 deletion trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4290,7 +4290,7 @@ bool SrsConfig::get_rtc_enabled(SrsConfDirective* conf)

int SrsConfig::get_rtc_listen()
{
static int DEFAULT = 9527;
static int DEFAULT = 8000;

SrsConfDirective* conf = root->get("rtc");
if (!conf) {
Expand Down Expand Up @@ -4318,6 +4318,11 @@ std::string SrsConfig::get_rtc_candidates()
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}

string eip = srs_getenv(conf->arg0());
if (!eip.empty()) {
return eip;
}

return (conf->arg0().c_str());
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ srs_error_t SrsGoApiSdp::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
obj->set("server", SrsJsonAny::integer(stat->server_id()));

// XXX: ice candidate
//string candidate_str = "candidate:1 1 udp 2115783679 192.168.170.129:9527 typ host generation 0 ufrag "
//string candidate_str = "candidate:1 1 udp 2115783679 192.168.170.129:8000 typ host generation 0 ufrag "
// + local_sdp.get_ice_ufrag() + "netwrok-cost 50";

//SrsJsonObject* candidate_obj = SrsJsonAny::object();
Expand Down
20 changes: 20 additions & 0 deletions trunk/src/app/srs_app_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1227,3 +1227,23 @@ string dump_string_hex(const char* buf, const int nb_buf, const int& max_len)
return ret;

}

string srs_getenv(string key)
{
string ekey = key;
if (srs_string_starts_with(key, "$")) {
ekey = key.substr(1);
}

if (ekey.empty()) {
return "";
}

char* value = ::getenv(ekey.c_str());
if (value) {
return value;
}

return "";
}

4 changes: 4 additions & 0 deletions trunk/src/app/srs_app_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,5 +653,9 @@ extern void srs_api_dump_summaries(SrsJsonObject* obj);
extern std::string dump_string_hex(const std::string& str, const int& max_len = INT_MAX);
extern std::string dump_string_hex(const char* buf, const int nb_buf, const int& max_len = INT_MAX);

// Get ENV variable, which may starts with $.
// srs_getenv("EIP") === srs_getenv("$EIP")
extern std::string srs_getenv(std::string key);

#endif

12 changes: 0 additions & 12 deletions trunk/src/main/srs_main_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ using namespace std;
srs_error_t run_directly_or_daemon();
srs_error_t run_hybrid_server();
void show_macro_features();
string srs_getenv(const char* name);

// @global log and context.
ISrsLog* _srs_log = new SrsFastLog();
Expand Down Expand Up @@ -344,17 +343,6 @@ void show_macro_features()
#endif
}

string srs_getenv(const char* name)
{
char* cv = ::getenv(name);

if (cv) {
return cv;
}

return "";
}

// Detect docker by https://stackoverflow.com/a/41559867
bool _srs_in_docker = false;
srs_error_t srs_detect_docker()
Expand Down

0 comments on commit 51af2b4

Please sign in to comment.