1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

For #1638, #307, define webrtc:// url for play

This commit is contained in:
winlin 2020-03-14 22:48:02 +08:00
parent 12e99f1897
commit c2916acd92
3 changed files with 24 additions and 10 deletions

View file

@ -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) {
@ -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));