mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Free rtc publish. Refactor TAB to spaces
This commit is contained in:
parent
cd3c15ec4e
commit
ebdc03416a
6 changed files with 46 additions and 155 deletions
|
@ -149,111 +149,4 @@
|
|||
</body>
|
||||
</html>
|
||||
|
||||
<script>
|
||||
/*
|
||||
var PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
|
||||
var SessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription;
|
||||
|
||||
var url = document.location.protocol + "//" + document.domain + ":1985/rtc/v1/publish/";
|
||||
|
||||
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();
|
||||
|
||||
var sendViewerOfferFn = function(desc) {
|
||||
console.log('sendViewerOfferFn:', desc);
|
||||
|
||||
pc.setLocalDescription(desc);
|
||||
|
||||
var sdp_json = {"sdp":desc.sdp, "app":"live", "stream":"livestream", "streamurl":"webrtc://localhost/live/livestream"};
|
||||
request.send(JSON.stringify(sdp_json));
|
||||
};
|
||||
|
||||
pc.addTransceiver("audio", {
|
||||
direction: "sendonly"
|
||||
}
|
||||
);
|
||||
|
||||
pc.addTransceiver("video", {
|
||||
direction: "sendonly"
|
||||
}
|
||||
);
|
||||
|
||||
var constraints = {
|
||||
"audio": true,
|
||||
"video": {
|
||||
"width": {
|
||||
"min": "480",
|
||||
"max": "1920"
|
||||
},
|
||||
"height": {
|
||||
"min": "320",
|
||||
"max": "1080"
|
||||
},
|
||||
"frameRate": {
|
||||
"min": "15",
|
||||
"max": "60"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
navigator.mediaDevices.getUserMedia(constraints).then(
|
||||
function(mediaStream) {
|
||||
var video = document.getElementById('rtc_media_player');
|
||||
video.srcObject = mediaStream;
|
||||
video.onloadedmetadata = function(e) {
|
||||
console.log('play');
|
||||
video.play();
|
||||
};
|
||||
|
||||
pc.addStream(mediaStream);
|
||||
pc.createOffer(sendViewerOfferFn,
|
||||
function(error) {
|
||||
console.log('sendViewerOfferFn error:' + error);
|
||||
},
|
||||
);
|
||||
}).catch(
|
||||
function(err) {
|
||||
console.log(err);
|
||||
console.log(err.name + ": " + err.message);
|
||||
}
|
||||
);
|
||||
|
||||
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