Skip to content

Commit

Permalink
Support api to specify the WebRTC API port. v4.0.225
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jan 13, 2022
1 parent c6c2e97 commit 73d0ce1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion trunk/research/api-server/static-dir/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ <h3><a href="https://github.com/ossrs/srs">SRS</a> works!</h3>
const prefix = `players/?schema=${window.location.protocol.replace(':', '')}`;
const httpPort = window.location.port || (window.location.protocol === 'http:' ? 80 : 443);
// If not 8080, user should proxy both stream and API to the default port.
const query = parseInt(window.location.port) === 8080 ? '' : `&port=${httpPort}&api_port=${httpPort}`;
const query = parseInt(window.location.port) === 8080 ? '' : `&port=${httpPort}&api=${httpPort}`;
document.getElementById("enPlayer").setAttribute('href', `${prefix}${query}`);
document.getElementById("cnPlayer").setAttribute('href', `${prefix}${query}`);
}
Expand Down
6 changes: 1 addition & 5 deletions trunk/research/players/js/srs.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ function user_extra_params(query, params, rtc) {
continue;
}

if (!rtc && key === 'api_port') {
continue;
}

if (query[key]) {
queries.push(key + '=' + query[key]);
}
Expand Down Expand Up @@ -94,7 +90,7 @@ function build_default_flv_url() {
function build_default_rtc_url(query) {
// The format for query string to overwrite configs of server.
console.log('?eip=x.x.x.x to overwrite candidate. 覆盖服务器candidate(外网IP)配置');
console.log('?api_port=x to overwrite WebRTC API(1985).');
console.log('?api=x to overwrite WebRTC API(1985).');
console.log('?schema=http|https to overwrite WebRTC API protocol.');

var server = (!query.server)? window.location.hostname:query.server;
Expand Down
20 changes: 15 additions & 5 deletions trunk/research/players/js/srs.sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ function SrsRtcPublisherAsync() {

var port = a.port;
if (!port) {
// Finger out by webrtc url, if contains http or https port, to overwrite default 1985.
if (schema === 'webrtc' && url.indexOf(`webrtc://${a.host}:`) === 0) {
port = (url.indexOf(`webrtc://${a.host}:80`) === 0) ? 80 : 443;
}

// Guess by schema.
if (schema === 'http') {
port = 80;
} else if (schema === 'https') {
Expand All @@ -210,9 +216,8 @@ function SrsRtcPublisherAsync() {
} else if (window.location.href.indexOf('https://') === 0) {
ret.port = 443;
} else {
// Allow use api_port to specify the WebRTC API port.
// For WebRTC, SRS use 1985 as default API port.
ret.port = ret.user_query.api_port || 1985;
ret.port = 1985;
}
}
}
Expand Down Expand Up @@ -268,7 +273,7 @@ function SrsRtcPlayerAsync() {
// webrtc://r.ossrs.net/live/livestream
// or specifies the API port:
// webrtc://r.ossrs.net:11985/live/livestream
// webrtc://r.ossrs.net/live/livestream?api_port=11985
// webrtc://r.ossrs.net:80/live/livestream
// or autostart the play:
// webrtc://r.ossrs.net/live/livestream?autostart=true
// or change the app from live to myapp:
Expand Down Expand Up @@ -415,6 +420,12 @@ function SrsRtcPlayerAsync() {

var port = a.port;
if (!port) {
// Finger out by webrtc url, if contains http or https port, to overwrite default 1985.
if (schema === 'webrtc' && url.indexOf(`webrtc://${a.host}:`) === 0) {
port = (url.indexOf(`webrtc://${a.host}:80`) === 0) ? 80 : 443;
}

// Guess by schema.
if (schema === 'http') {
port = 80;
} else if (schema === 'https') {
Expand All @@ -440,9 +451,8 @@ function SrsRtcPlayerAsync() {
} else if (window.location.href.indexOf('https://') === 0) {
ret.port = 443;
} else {
// Allow use api_port to specify the WebRTC API port.
// For WebRTC, SRS use 1985 as default API port.
ret.port = ret.user_query.api_port || 1985;
ret.port = 1985;
}
}
}
Expand Down

0 comments on commit 73d0ce1

Please sign in to comment.