Skip to content

Commit

Permalink
For #1638, #307, define webrtc:// url for play
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Mar 14, 2020
1 parent 12e99f1 commit c2916ac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
8 changes: 3 additions & 5 deletions trunk/research/players/js/srs.page.js
Expand Up @@ -58,7 +58,7 @@ function user_extra_params(query, params) {
|| key === 'filename' || key === 'host' || key === 'hostname'
|| key === 'http_port' || key === 'pathname' || key === 'port'
|| key === 'server' || key === 'stream' || key === 'buffer'
|| key === 'schema' || key === 'vhost' || key === 'api_port'
|| key === 'schema' || key === 'vhost'
) {
continue;
}
Expand Down Expand Up @@ -207,9 +207,7 @@ function build_default_hls_url() {
}

function build_default_rtc_url(query) {
var schema = (!query.schema)? "http":query.schema;
var server = (!query.server)? window.location.hostname:query.server;
var port = (!query.api_port)? 1985:query.api_port;
var vhost = (!query.vhost)? window.location.hostname:query.vhost;
var app = (!query.app)? "live":query.app;
var stream = (!query.stream)? "livestream":query.stream;
Expand All @@ -229,8 +227,8 @@ function build_default_rtc_url(query) {
}
queries = user_extra_params(query, queries);

var uri = schema + "://" + server + ":" + port + "/api/v1/sdp/?app=" + app + "&stream=" + stream + "&" + queries.join('&');
while (uri.lastIndexOf("&") == uri.length - 1) {
var uri = "webrtc://" + server + "/" + app + "/" + stream + "?" + queries.join('&');
while (uri.lastIndexOf("?") == uri.length - 1) {
uri = uri.substr(0, uri.length - 1);
}

Expand Down
6 changes: 3 additions & 3 deletions trunk/research/players/js/winlin.utility.js
Expand Up @@ -3,9 +3,9 @@
/**
* common utilities
* depends: jquery1.10
* https://code.csdn.net/snippets/147103
* https://gitee.com/winlinvip/codes/rpn0c2ewbomj81augzk4y59
* @see: http://blog.csdn.net/win_lin/article/details/17994347
* v 1.0.17
* v 1.0.19
*/

/**
Expand Down Expand Up @@ -293,7 +293,7 @@ function __fill_query(query_string, obj) {
function parse_rtmp_url(rtmp_url) {
// @see: http://stackoverflow.com/questions/10469575/how-to-use-location-object-to-parse-url-without-redirecting-the-page-in-javascri
var a = document.createElement("a");
a.href = rtmp_url.replace("rtmp://", "http://");
a.href = rtmp_url.replace("rtmp://", "http://").replace("webrtc://", "http://");

var vhost = a.hostname;
var app = a.pathname.substr(1, a.pathname.lastIndexOf("/") - 1);
Expand Down
20 changes: 18 additions & 2 deletions trunk/research/players/rtc_player.html
Expand Up @@ -61,6 +61,7 @@
$("#btn_play").click(function(){
$('#rtc_media_player').show();
var urlObject = parse_rtmp_url($("#txt_url").val());
var schame = window.location.protocol;

var pc = new RTCPeerConnection(null);
pc.onaddstream = function (event) {
Expand All @@ -82,14 +83,29 @@
return pc.setLocalDescription(offer).then(function(){ return offer; });
}).then(function(offer) {
return new Promise(function(resolve, reject) {
var port = urlObject.user_query.api || 1985;
var api = urlObject.user_query.play || '/api/v1/sdp/';
if (api.lastIndexOf('/') != api.length - 1) {
api += '/';
}

var url = schame + '//' + urlObject.server + ':' + port + api
+ '?app=' + urlObject.app + '&stream=' + urlObject.stream;
for (var key in urlObject.user_query) {
if (key != 'api' && key != 'play') {
url += '&' + key + '=' + urlObject.user_query[key];
}
}

var data = {
"url": urlObject.url, "app": urlObject.app, "stream": urlObject.stream,
"url": url, "streamurl": urlObject.url,
"app": urlObject.app, "stream": urlObject.stream,
"sdp": offer.sdp
};
console.log("offer: " + JSON.stringify(data));

$.ajax({
type: "POST", url: urlObject.url, data: JSON.stringify(data),
type: "POST", url: url, data: JSON.stringify(data),
contentType:'application/json', dataType: 'json'
}).done(function(data) {
console.log("answer: " + JSON.stringify(data));
Expand Down

0 comments on commit c2916ac

Please sign in to comment.