mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
parent
d21ef106a0
commit
51af2b4779
10 changed files with 68 additions and 227 deletions
|
@ -7,7 +7,7 @@
|
|||
<body>
|
||||
|
||||
rtc_media_player: <br>
|
||||
<video id = "rtc_media_player" autoplay></video>
|
||||
<video id = "rtc_media_player" autoplay controls></video>
|
||||
|
||||
</body>
|
||||
|
||||
|
@ -16,7 +16,7 @@ rtc_media_player: <br>
|
|||
var PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
|
||||
var SessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription;
|
||||
|
||||
var url = "http://hw.com:1985/api/v1/sdp/";
|
||||
var url = "http://localhost:1985/api/v1/sdp/";
|
||||
|
||||
var method = "POST";
|
||||
var shouldBeAsync = true;
|
||||
|
@ -40,7 +40,7 @@ var sendViewerOfferFn = function(desc) {
|
|||
|
||||
pc.setLocalDescription(desc);
|
||||
|
||||
var sdp_json = {"sdp":desc.sdp, "app":"webrtc", "stream":"test"};
|
||||
var sdp_json = {"sdp":desc.sdp, "app":"live", "stream":"livestream"};
|
||||
request.send(JSON.stringify(sdp_json));
|
||||
};
|
||||
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh-cmn-Hans">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<br>local_media_player: <br>
|
||||
<video id = "local_media_player" autoplay></video>
|
||||
<br>rtc_media_player: <br>
|
||||
<video id = "rtc_media_player" autoplay></video>
|
||||
|
||||
<script>
|
||||
|
||||
var PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
|
||||
var SessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription;
|
||||
|
||||
var url = "http://hw.com:1985/api/v1/sdp/";
|
||||
|
||||
var method = "POST";
|
||||
var shouldBeAsync = true;
|
||||
|
||||
var request = new XMLHttpRequest();
|
||||
|
||||
request.open(method, url, shouldBeAsync);
|
||||
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
|
||||
var pc = new PeerConnection(null);
|
||||
|
||||
var sendSdpOffer = function(desc) {
|
||||
console.log('sendSdpOffer:', desc);
|
||||
|
||||
pc.setLocalDescription(desc);
|
||||
|
||||
var sdp_json = {"sdp":desc.sdp, "app":"webrtc", "stream":"test"};
|
||||
request.send(JSON.stringify(sdp_json));
|
||||
};
|
||||
|
||||
pc.onaddstream = function(event) {
|
||||
console.log('onaddstream');
|
||||
document.getElementById('rtc_media_player').srcObject = event.stream;
|
||||
rtc_media_player.load();
|
||||
};
|
||||
|
||||
pc.onicecandidate = function(event) {
|
||||
console.log('onicecandidate');
|
||||
};
|
||||
|
||||
pc.onconnectionstatechange = function(event) {
|
||||
console.log('onconnectionstatechange');
|
||||
};
|
||||
|
||||
pc.onicegatheringstatechange = function(event) {
|
||||
console.log('onicegatheringstatechange');
|
||||
};
|
||||
|
||||
pc.onsignalingstatechange = function(event) {
|
||||
console.log('onsignalingstatechange');
|
||||
};
|
||||
|
||||
navigator.webkitGetUserMedia({
|
||||
"audio": true,
|
||||
"video": {
|
||||
width: 800,
|
||||
height:600,
|
||||
frameRate:30,
|
||||
bitRate:8000,
|
||||
}
|
||||
}, function(stream){
|
||||
document.getElementById('local_media_player').srcObject = stream;
|
||||
pc.addStream(stream);
|
||||
pc.createOffer(sendSdpOffer, function (error) {
|
||||
console.log('Failure callback: ' + error);
|
||||
});
|
||||
}, function(error){
|
||||
//处理媒体流创建失败错误
|
||||
console.log('getUserMedia error: ' + error);
|
||||
});
|
||||
|
||||
request.onerror = function(event) {
|
||||
console.log('http error');
|
||||
};
|
||||
|
||||
request.onload = function () {
|
||||
console.log('onload,' , request.responseText);
|
||||
var json = JSON.parse(request.responseText);
|
||||
console.log('onmessage viewerResponse:', json.sdp);
|
||||
|
||||
pc.setRemoteDescription(new SessionDescription({type:'answer', sdp:json.sdp}));
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,90 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh-cmn-Hans">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
rtc_media_player: <br>
|
||||
<video id = "rtc_media_player" autoplay></video>
|
||||
|
||||
</body>
|
||||
|
||||
<script>
|
||||
|
||||
var PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
|
||||
var SessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription;
|
||||
|
||||
var url = "http://hw.com:1985/api/v1/sdp/";
|
||||
|
||||
var method = "POST";
|
||||
var shouldBeAsync = true;
|
||||
|
||||
var request = new XMLHttpRequest();
|
||||
|
||||
request.open(method, url, shouldBeAsync);
|
||||
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
|
||||
var pc = new PeerConnection(null);
|
||||
|
||||
var constraints = {
|
||||
mandatory: {
|
||||
OfferToReceiveAudio: true,
|
||||
OfferToReceiveVideo: true
|
||||
}
|
||||
};
|
||||
|
||||
var sendViewerOfferFn = function(desc) {
|
||||
console.log('sendViewerOfferFn:', desc);
|
||||
|
||||
pc.setLocalDescription(desc);
|
||||
|
||||
var sdp_json = {"sdp":desc.sdp, "app":"webrtc", "stream":"test"};
|
||||
request.send(JSON.stringify(sdp_json));
|
||||
};
|
||||
|
||||
pc.createOffer(sendViewerOfferFn,
|
||||
function(error) {
|
||||
console.log('sendViewerOfferFn error:' + error);
|
||||
},
|
||||
constraints
|
||||
);
|
||||
|
||||
pc.onaddstream = function(event) {
|
||||
console.log('onaddstream');
|
||||
document.getElementById('rtc_media_player').srcObject = event.stream;
|
||||
rtc_media_player.load();
|
||||
};
|
||||
|
||||
pc.onicecandidate = function(event) {
|
||||
console.log('onicecandidate');
|
||||
};
|
||||
|
||||
pc.onconnectionstatechange = function(event) {
|
||||
console.log('onconnectionstatechange');
|
||||
};
|
||||
|
||||
pc.onicegatheringstatechange = function(event) {
|
||||
console.log('onicegatheringstatechange');
|
||||
};
|
||||
|
||||
pc.onsignalingstatechange = function(event) {
|
||||
console.log('onsignalingstatechange');
|
||||
};
|
||||
|
||||
request.onerror = function(event) {
|
||||
console.log('http error');
|
||||
};
|
||||
|
||||
request.onload = function () {
|
||||
console.log('onload,' , request.responseText);
|
||||
var json = JSON.parse(request.responseText);
|
||||
console.log('onmessage viewerResponse:', json.sdp);
|
||||
|
||||
pc.setRemoteDescription(new SessionDescription({type:'answer', sdp:json.sdp}));
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue