mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix gb28281 html rtc player stop
This commit is contained in:
parent
33b91cd6f2
commit
b391ed6206
1 changed files with 71 additions and 69 deletions
|
@ -123,8 +123,9 @@
|
|||
<div>
|
||||
<textarea class="span6" id="txt_rtc_url" rows="2"></textarea>
|
||||
<button class="btn btn-primary" id="btn_rtc_play">RTC播放</button>
|
||||
需要后台配置rtc功能才能正常启用, rtc配置请参考如下
|
||||
https://github.com/ossrs/srs/issues/307#issuecomment-602193458
|
||||
<div>RTC播放,需要后台启用RTC功能才能正常播放,
|
||||
<a href='https://github.com/ossrs/srs/wiki/v4_CN_RTCWiki'>RTC配置参考</a>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<pre id="gb28181ChannelMessage" style="overflow:scroll; height:300px"></pre>
|
||||
|
@ -1090,82 +1091,83 @@
|
|||
startPlay($("#txt_rtc_url").val());
|
||||
});
|
||||
|
||||
|
||||
$("#rtc_player_modal").on("hide", function(){
|
||||
console.log("rtc stop");
|
||||
if (pc) {
|
||||
pc.close();
|
||||
}
|
||||
});
|
||||
|
||||
var startPlay = function(url) {
|
||||
$('#rtc_media_player').show();
|
||||
var urlObject = parse_rtmp_url(url);
|
||||
var schema = window.location.protocol;
|
||||
$('#rtc_media_player').show();
|
||||
var urlObject = parse_rtmp_url(url);
|
||||
var schema = window.location.protocol;
|
||||
|
||||
// Close PC when user replay.
|
||||
if (pc) {
|
||||
pc.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
pc = new RTCPeerConnection(null);
|
||||
pc.onaddstream = function (event) {
|
||||
console.debug(event.stream);
|
||||
$('#rtc_media_player').prop('srcObject', event.stream);
|
||||
};
|
||||
new Promise(function(resolve, reject) {
|
||||
pc.addTransceiver("audio", {direction: "recvonly"});
|
||||
pc.addTransceiver("video", {direction: "recvonly"});
|
||||
|
||||
pc.createOffer(function(offer){
|
||||
resolve(offer);
|
||||
},function(reason){
|
||||
reject(reason);
|
||||
});
|
||||
}).then(function(offer) {
|
||||
return pc.setLocalDescription(offer).then(function(){ return offer; });
|
||||
}).then(function(offer) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var port = urlObject.port || 1985;
|
||||
|
||||
// @see https://github.com/rtcdn/rtcdn-draft
|
||||
var api = urlObject.user_query.play || '/rtc/v1/play/';
|
||||
if (api.lastIndexOf('/') != api.length - 1) {
|
||||
api += '/';
|
||||
// Close PC when user replay.
|
||||
if (pc) {
|
||||
pc.close();
|
||||
}
|
||||
|
||||
var url = schema + '//' + urlObject.server + ':' + port + api;
|
||||
for (var key in urlObject.user_query) {
|
||||
if (key != 'api' && key != 'play') {
|
||||
url += '&' + key + '=' + urlObject.user_query[key];
|
||||
}
|
||||
}
|
||||
// Replace /rtc/v1/play/&k=v to /rtc/v1/play/?k=v
|
||||
url = url.replace(api + '&', api + '?');
|
||||
|
||||
// @see https://github.com/rtcdn/rtcdn-draft
|
||||
var data = {
|
||||
api: url, streamurl: urlObject.url, clientip: null, sdp: offer.sdp
|
||||
pc = new RTCPeerConnection(null);
|
||||
pc.onaddstream = function (event) {
|
||||
console.debug(event.stream);
|
||||
$('#rtc_media_player').prop('srcObject', event.stream);
|
||||
};
|
||||
console.log("offer: " + JSON.stringify(data));
|
||||
new Promise(function(resolve, reject) {
|
||||
pc.addTransceiver("audio", {direction: "recvonly"});
|
||||
pc.addTransceiver("video", {direction: "recvonly"});
|
||||
|
||||
$.ajax({
|
||||
type: "POST", url: url, data: JSON.stringify(data),
|
||||
contentType:'application/json', dataType: 'json'
|
||||
}).done(function(data) {
|
||||
console.log("answer: " + JSON.stringify(data));
|
||||
resolve(data.sdp);
|
||||
}).fail(function(reason){
|
||||
reject(reason);
|
||||
pc.createOffer(function(offer){
|
||||
resolve(offer);
|
||||
},function(reason){
|
||||
reject(reason);
|
||||
});
|
||||
}).then(function(offer) {
|
||||
return pc.setLocalDescription(offer).then(function(){ return offer; });
|
||||
}).then(function(offer) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var port = urlObject.port || 1985;
|
||||
|
||||
// @see https://github.com/rtcdn/rtcdn-draft
|
||||
var api = urlObject.user_query.play || '/rtc/v1/play/';
|
||||
if (api.lastIndexOf('/') != api.length - 1) {
|
||||
api += '/';
|
||||
}
|
||||
|
||||
var url = schema + '//' + urlObject.server + ':' + port + api;
|
||||
for (var key in urlObject.user_query) {
|
||||
if (key != 'api' && key != 'play') {
|
||||
url += '&' + key + '=' + urlObject.user_query[key];
|
||||
}
|
||||
}
|
||||
// Replace /rtc/v1/play/&k=v to /rtc/v1/play/?k=v
|
||||
url = url.replace(api + '&', api + '?');
|
||||
|
||||
// @see https://github.com/rtcdn/rtcdn-draft
|
||||
var data = {
|
||||
api: url, streamurl: urlObject.url, clientip: null, sdp: offer.sdp
|
||||
};
|
||||
console.log("offer: " + JSON.stringify(data));
|
||||
|
||||
$.ajax({
|
||||
type: "POST", url: url, data: JSON.stringify(data),
|
||||
contentType:'application/json', dataType: 'json'
|
||||
}).done(function(data) {
|
||||
console.log("answer: " + JSON.stringify(data));
|
||||
resolve(data.sdp);
|
||||
}).fail(function(reason){
|
||||
reject(reason);
|
||||
});
|
||||
});
|
||||
}).then(function(answer) {
|
||||
return pc.setRemoteDescription(new RTCSessionDescription({type: 'answer', sdp: answer}));
|
||||
}).catch(function(reason) {
|
||||
throw reason;
|
||||
});
|
||||
});
|
||||
}).then(function(answer) {
|
||||
return pc.setRemoteDescription(new RTCSessionDescription({type: 'answer', sdp: answer}));
|
||||
}).catch(function(reason) {
|
||||
throw reason;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
apply_url_change();
|
||||
};
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue