mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
parent
d21ef106a0
commit
51af2b4779
10 changed files with 68 additions and 227 deletions
|
@ -306,6 +306,25 @@ srt_server {
|
||||||
default_app live;
|
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
|
# Kafka sections
|
||||||
#############################################################################################
|
#############################################################################################
|
||||||
|
|
|
@ -1,40 +1,32 @@
|
||||||
# main config for srs.
|
|
||||||
# @see full.conf for detail config.
|
|
||||||
|
|
||||||
listen 1935;
|
listen 1935;
|
||||||
max_connections 1000;
|
max_connections 1000;
|
||||||
srs_log_tank file;
|
srs_log_tank console;
|
||||||
srs_log_file ./objs/srs.log;
|
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 {
|
http_server {
|
||||||
enabled on;
|
enabled on;
|
||||||
listen 8080;
|
listen 8080;
|
||||||
dir ./objs/nginx/html;
|
dir ./objs/nginx/html;
|
||||||
}
|
}
|
||||||
rtc {
|
|
||||||
|
http_api {
|
||||||
enabled on;
|
enabled on;
|
||||||
listen 9527;
|
listen 1985;
|
||||||
# candidate device ip: *(all interface), 192.168.1.1 ...
|
|
||||||
candidate *;
|
|
||||||
}
|
}
|
||||||
stats {
|
stats {
|
||||||
network 0;
|
network 0;
|
||||||
disk sda sdb xvda xvdb;
|
|
||||||
}
|
}
|
||||||
|
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__ {
|
vhost __defaultVhost__ {
|
||||||
http_remux {
|
|
||||||
enabled on;
|
|
||||||
mount [vhost]/[app]/[stream].flv;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
rtc_media_player: <br>
|
rtc_media_player: <br>
|
||||||
<video id = "rtc_media_player" autoplay></video>
|
<video id = "rtc_media_player" autoplay controls></video>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ rtc_media_player: <br>
|
||||||
var PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
|
var PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
|
||||||
var SessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription;
|
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 method = "POST";
|
||||||
var shouldBeAsync = true;
|
var shouldBeAsync = true;
|
||||||
|
@ -40,7 +40,7 @@ var sendViewerOfferFn = function(desc) {
|
||||||
|
|
||||||
pc.setLocalDescription(desc);
|
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));
|
request.send(JSON.stringify(sdp_json));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,97 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="zh-cmn-Hans">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<br>local_media_player: <br>
|
|
||||||
<video id = "local_media_player" autoplay></video>
|
|
||||||
<br>rtc_media_player: <br>
|
|
||||||
<video id = "rtc_media_player" autoplay></video>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
|
|
||||||
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 method = "POST";
|
|
||||||
var shouldBeAsync = true;
|
|
||||||
|
|
||||||
var request = new XMLHttpRequest();
|
|
||||||
|
|
||||||
request.open(method, url, shouldBeAsync);
|
|
||||||
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
||||||
|
|
||||||
var pc = new PeerConnection(null);
|
|
||||||
|
|
||||||
var sendSdpOffer = function(desc) {
|
|
||||||
console.log('sendSdpOffer:', desc);
|
|
||||||
|
|
||||||
pc.setLocalDescription(desc);
|
|
||||||
|
|
||||||
var sdp_json = {"sdp":desc.sdp, "app":"webrtc", "stream":"test"};
|
|
||||||
request.send(JSON.stringify(sdp_json));
|
|
||||||
};
|
|
||||||
|
|
||||||
pc.onaddstream = function(event) {
|
|
||||||
console.log('onaddstream');
|
|
||||||
document.getElementById('rtc_media_player').srcObject = event.stream;
|
|
||||||
rtc_media_player.load();
|
|
||||||
};
|
|
||||||
|
|
||||||
pc.onicecandidate = function(event) {
|
|
||||||
console.log('onicecandidate');
|
|
||||||
};
|
|
||||||
|
|
||||||
pc.onconnectionstatechange = function(event) {
|
|
||||||
console.log('onconnectionstatechange');
|
|
||||||
};
|
|
||||||
|
|
||||||
pc.onicegatheringstatechange = function(event) {
|
|
||||||
console.log('onicegatheringstatechange');
|
|
||||||
};
|
|
||||||
|
|
||||||
pc.onsignalingstatechange = function(event) {
|
|
||||||
console.log('onsignalingstatechange');
|
|
||||||
};
|
|
||||||
|
|
||||||
navigator.webkitGetUserMedia({
|
|
||||||
"audio": true,
|
|
||||||
"video": {
|
|
||||||
width: 800,
|
|
||||||
height:600,
|
|
||||||
frameRate:30,
|
|
||||||
bitRate:8000,
|
|
||||||
}
|
|
||||||
}, function(stream){
|
|
||||||
document.getElementById('local_media_player').srcObject = stream;
|
|
||||||
pc.addStream(stream);
|
|
||||||
pc.createOffer(sendSdpOffer, function (error) {
|
|
||||||
console.log('Failure callback: ' + error);
|
|
||||||
});
|
|
||||||
}, function(error){
|
|
||||||
//处理媒体流创建失败错误
|
|
||||||
console.log('getUserMedia error: ' + error);
|
|
||||||
});
|
|
||||||
|
|
||||||
request.onerror = function(event) {
|
|
||||||
console.log('http error');
|
|
||||||
};
|
|
||||||
|
|
||||||
request.onload = function () {
|
|
||||||
console.log('onload,' , request.responseText);
|
|
||||||
var json = JSON.parse(request.responseText);
|
|
||||||
console.log('onmessage viewerResponse:', json.sdp);
|
|
||||||
|
|
||||||
pc.setRemoteDescription(new SessionDescription({type:'answer', sdp:json.sdp}));
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
|
@ -1,90 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="zh-cmn-Hans">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
|
|
||||||
rtc_media_player: <br>
|
|
||||||
<video id = "rtc_media_player" autoplay></video>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
|
|
||||||
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 method = "POST";
|
|
||||||
var shouldBeAsync = true;
|
|
||||||
|
|
||||||
var request = new XMLHttpRequest();
|
|
||||||
|
|
||||||
request.open(method, url, shouldBeAsync);
|
|
||||||
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
||||||
|
|
||||||
var pc = new PeerConnection(null);
|
|
||||||
|
|
||||||
var constraints = {
|
|
||||||
mandatory: {
|
|
||||||
OfferToReceiveAudio: true,
|
|
||||||
OfferToReceiveVideo: true
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var sendViewerOfferFn = function(desc) {
|
|
||||||
console.log('sendViewerOfferFn:', desc);
|
|
||||||
|
|
||||||
pc.setLocalDescription(desc);
|
|
||||||
|
|
||||||
var sdp_json = {"sdp":desc.sdp, "app":"webrtc", "stream":"test"};
|
|
||||||
request.send(JSON.stringify(sdp_json));
|
|
||||||
};
|
|
||||||
|
|
||||||
pc.createOffer(sendViewerOfferFn,
|
|
||||||
function(error) {
|
|
||||||
console.log('sendViewerOfferFn error:' + error);
|
|
||||||
},
|
|
||||||
constraints
|
|
||||||
);
|
|
||||||
|
|
||||||
pc.onaddstream = function(event) {
|
|
||||||
console.log('onaddstream');
|
|
||||||
document.getElementById('rtc_media_player').srcObject = event.stream;
|
|
||||||
rtc_media_player.load();
|
|
||||||
};
|
|
||||||
|
|
||||||
pc.onicecandidate = function(event) {
|
|
||||||
console.log('onicecandidate');
|
|
||||||
};
|
|
||||||
|
|
||||||
pc.onconnectionstatechange = function(event) {
|
|
||||||
console.log('onconnectionstatechange');
|
|
||||||
};
|
|
||||||
|
|
||||||
pc.onicegatheringstatechange = function(event) {
|
|
||||||
console.log('onicegatheringstatechange');
|
|
||||||
};
|
|
||||||
|
|
||||||
pc.onsignalingstatechange = function(event) {
|
|
||||||
console.log('onsignalingstatechange');
|
|
||||||
};
|
|
||||||
|
|
||||||
request.onerror = function(event) {
|
|
||||||
console.log('http error');
|
|
||||||
};
|
|
||||||
|
|
||||||
request.onload = function () {
|
|
||||||
console.log('onload,' , request.responseText);
|
|
||||||
var json = JSON.parse(request.responseText);
|
|
||||||
console.log('onmessage viewerResponse:', json.sdp);
|
|
||||||
|
|
||||||
pc.setRemoteDescription(new SessionDescription({type:'answer', sdp:json.sdp}));
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</html>
|
|
|
@ -4290,7 +4290,7 @@ bool SrsConfig::get_rtc_enabled(SrsConfDirective* conf)
|
||||||
|
|
||||||
int SrsConfig::get_rtc_listen()
|
int SrsConfig::get_rtc_listen()
|
||||||
{
|
{
|
||||||
static int DEFAULT = 9527;
|
static int DEFAULT = 8000;
|
||||||
|
|
||||||
SrsConfDirective* conf = root->get("rtc");
|
SrsConfDirective* conf = root->get("rtc");
|
||||||
if (!conf) {
|
if (!conf) {
|
||||||
|
@ -4318,6 +4318,11 @@ std::string SrsConfig::get_rtc_candidates()
|
||||||
if (!conf || conf->arg0().empty()) {
|
if (!conf || conf->arg0().empty()) {
|
||||||
return DEFAULT;
|
return DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string eip = srs_getenv(conf->arg0());
|
||||||
|
if (!eip.empty()) {
|
||||||
|
return eip;
|
||||||
|
}
|
||||||
|
|
||||||
return (conf->arg0().c_str());
|
return (conf->arg0().c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -851,7 +851,7 @@ srs_error_t SrsGoApiSdp::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
|
||||||
obj->set("server", SrsJsonAny::integer(stat->server_id()));
|
obj->set("server", SrsJsonAny::integer(stat->server_id()));
|
||||||
|
|
||||||
// XXX: ice candidate
|
// 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";
|
// + local_sdp.get_ice_ufrag() + "netwrok-cost 50";
|
||||||
|
|
||||||
//SrsJsonObject* candidate_obj = SrsJsonAny::object();
|
//SrsJsonObject* candidate_obj = SrsJsonAny::object();
|
||||||
|
|
|
@ -1227,3 +1227,23 @@ string dump_string_hex(const char* buf, const int nb_buf, const int& max_len)
|
||||||
return ret;
|
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 "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 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);
|
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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,6 @@ using namespace std;
|
||||||
srs_error_t run_directly_or_daemon();
|
srs_error_t run_directly_or_daemon();
|
||||||
srs_error_t run_hybrid_server();
|
srs_error_t run_hybrid_server();
|
||||||
void show_macro_features();
|
void show_macro_features();
|
||||||
string srs_getenv(const char* name);
|
|
||||||
|
|
||||||
// @global log and context.
|
// @global log and context.
|
||||||
ISrsLog* _srs_log = new SrsFastLog();
|
ISrsLog* _srs_log = new SrsFastLog();
|
||||||
|
@ -344,17 +343,6 @@ void show_macro_features()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
string srs_getenv(const char* name)
|
|
||||||
{
|
|
||||||
char* cv = ::getenv(name);
|
|
||||||
|
|
||||||
if (cv) {
|
|
||||||
return cv;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detect docker by https://stackoverflow.com/a/41559867
|
// Detect docker by https://stackoverflow.com/a/41559867
|
||||||
bool _srs_in_docker = false;
|
bool _srs_in_docker = false;
|
||||||
srs_error_t srs_detect_docker()
|
srs_error_t srs_detect_docker()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue