From 73d0ce1ceeaeaf4b2fe2deb78aa0a337eb2533a9 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 13 Jan 2022 13:32:14 +0800 Subject: [PATCH] Support api to specify the WebRTC API port. v4.0.225 --- .../research/api-server/static-dir/index.html | 2 +- trunk/research/players/js/srs.page.js | 6 +----- trunk/research/players/js/srs.sdk.js | 20 ++++++++++++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/trunk/research/api-server/static-dir/index.html b/trunk/research/api-server/static-dir/index.html index 684848da3..8d92fc12c 100755 --- a/trunk/research/api-server/static-dir/index.html +++ b/trunk/research/api-server/static-dir/index.html @@ -64,7 +64,7 @@ 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}`); } diff --git a/trunk/research/players/js/srs.page.js b/trunk/research/players/js/srs.page.js index ffc88cdfa..d680f3cbd 100755 --- a/trunk/research/players/js/srs.page.js +++ b/trunk/research/players/js/srs.page.js @@ -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]); } @@ -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; diff --git a/trunk/research/players/js/srs.sdk.js b/trunk/research/players/js/srs.sdk.js index 5673aa045..5cda7947c 100644 --- a/trunk/research/players/js/srs.sdk.js +++ b/trunk/research/players/js/srs.sdk.js @@ -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') { @@ -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; } } } @@ -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: @@ -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') { @@ -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; } } }