Updated pranswer, dtmf demos & deleted pc1-deprecated.html.

Review URL: https://webrtc-codereview.appspot.com/1287007

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3783 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
vikasmarwaha@webrtc.org 2013-04-08 21:23:58 +00:00
parent 6ff76c7404
commit 4c44fe0561
4 changed files with 91 additions and 213 deletions

View File

@ -98,6 +98,10 @@ function gotDescription1(desc){
} }
function gotDescription2(desc){ function gotDescription2(desc){
// Setting PCMU as the preferred codec.
desc.sdp = desc.sdp.replace(/m=.*\r\n/, "m=audio 1 RTP/SAVPF 0 126\r\n");
// Workaround for issue 1603.
desc.sdp = desc.sdp.replace(/.*fmtp.*\r\n/g, "");
pc2.setLocalDescription(desc); pc2.setLocalDescription(desc);
trace("Answer from pc2 \n" + desc.sdp); trace("Answer from pc2 \n" + desc.sdp);
pc1.setRemoteDescription(desc); pc1.setRemoteDescription(desc);

View File

@ -1,133 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>PeerConnection Demo 1</title>
<style>
video {
border:5px solid black;
width:480px;
height:360px;
}
button {
font: 18px sans-serif;
padding: 8px;
}
textarea {
font-family: monospace;
margin: 2px;
width:480px;
height:640px;
}
</style>
</head>
<body>
<video id="vid1" autoplay></video>
<video id="vid2" autoplay></video>
<br>
<button id="btn1" onclick="start()">Start</button>
<button id="btn2" onclick="call()">Call</button>
<button id="btn3" onclick="hangup()">Hang Up</button>
<br>
<xtextarea id="ta1"></textarea>
<xtextarea id="ta2"></textarea>
<script>
//var vid1 = document.getElementById("vid1");
//var vid2 = document.getElementById("vid2");
btn1.disabled = false;
btn2.disabled = true;
btn3.disabled = true;
var pc1,pc2;
var localstream;
function trace(text) {
// This function is used for logging.
if (text[text.length - 1] == '\n') {
text = text.substring(0, text.length - 1);
}
console.log((performance.now() / 1000).toFixed(3) + ": " + text);
}
function gotStream(stream){
trace("Received local stream");
vid1.src = webkitURL.createObjectURL(stream);
localstream = stream;
btn2.disabled = false;
}
function start() {
trace("Requesting local stream");
btn1.disabled = true;
navigator.webkitGetUserMedia({audio:true, video:true},
gotStream, function() {});
}
function call() {
btn2.disabled = true;
btn3.disabled = false;
trace("Starting call");
if (localstream.videoTracks.length > 0)
trace('Using Video device: ' + localstream.videoTracks[0].label);
if (localstream.audioTracks.length > 0)
trace('Using Audio device: ' + localstream.audioTracks[0].label);
pc1 = new webkitPeerConnection00(null, iceCallback1);
trace("Created local peer connection object pc1");
pc2 = new webkitPeerConnection00(null, iceCallback2);
trace("Created remote peer connection object pc2");
pc2.onaddstream = gotRemoteStream;
pc1.addStream(localstream);
trace("Adding Local Stream to peer connection");
var offer = pc1.createOffer(null);
trace("Created offer:\n" + offer.toSdp());
pc1.setLocalDescription(pc1.SDP_OFFER, offer);
trace("SetLocalDesc1");
pc2.setRemoteDescription(pc2.SDP_OFFER, offer);
trace("SetRemoteDesc2");
//ta1.value = offer.toSdp();
var answer = pc2.createAnswer(offer.toSdp(),
{has_audio:true, has_video:true});
trace("Created answer:\n" + answer.toSdp());
pc2.setLocalDescription(pc2.SDP_ANSWER, answer);
trace("SetLocalDesc2");
pc1.setRemoteDescription(pc1.SDP_ANSWER, answer);
trace("SetRemoteDesc1");
//ta2.value = answer.toSdp();
pc1.startIce();
pc2.startIce();
trace("Started ICE for both local & remote");
}
function hangup() {
trace("Ending call");
pc1.close();
pc2.close();
pc1 = null;
pc2 = null;
btn3.disabled = true;
btn2.disabled = false;
}
function gotRemoteStream(e){
vid2.src = webkitURL.createObjectURL(e.stream);
trace("Received remote stream");
}
function iceCallback1(candidate,bMore){
if (candidate) {
pc2.processIceMessage(candidate);
trace("Local ICE candidate: " + candidate.toSdp());
}
}
function iceCallback2(candidate,bMore){
if (candidate) {
pc1.processIceMessage(candidate);
trace("Remote ICE candidate: " + candidate.toSdp());
}
}
</script>
</body>
</html>

View File

@ -1,93 +1,106 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>PeerConnection PRANSWER Demo</title> <title>PeerConnection PRANSWER Demo</title>
<style> <!-- Load the polyfill to switch-hit between Chrome and Firefox -->
video { <script src="../../base/adapter.js"></script>
border:5px solid black; <style>
width:320px; video {
height:240px; border:5px solid black;
} width:320px;
</style> height:240px;
</head> }
<body> </style>
<video id="vid1" autoplay="true" muted="true"></video> </head>
<video id="vid2" autoplay></video> <body>
<br> <video id="vid1" autoplay="true" muted="true"></video>
<button id="btn1" onclick="start()">Call</button> <video id="vid2" autoplay></video>
<button id="btn15" onclick="accept()">Accept</button> <br>
<button id="btn2" onclick="stop()">Hang Up</button> <button id="btn1" onclick="start()">Call</button>
<script> <button id="btn2" onclick="accept()">Accept</button>
<button id="btn3" onclick="stop()">Hang Up</button>
<script>
//var vid1 = document.getElementById("vid1"); //var vid1 = document.getElementById("vid1");
//var vid2 = document.getElementById("vid2"); //var vid2 = document.getElementById("vid2");
btn1.disabled = true; btn1.disabled = true;
btn2.disabled = true; btn2.disabled = true;
btn3.disabled = true;
var pc1,pc2; var pc1,pc2;
var localstream; var localstream;
var sdpConstraints = {'mandatory': {
function trace(txt) { 'OfferToReceiveAudio':true,
// This function is used for logging. 'OfferToReceiveVideo':true }};
console.log(txt);
} function gotStream(stream) {
function traceCandidate(kind, cand) {
trace("Candidate(" + kind + "): " + cand.label + ": " +
cand.toSdp().replace("\n", ""));
}
function gotStream(stream){
trace("Received local stream"); trace("Received local stream");
vid1.src = webkitURL.createObjectURL(stream); // Call the polyfill wrapper to attach the media stream to this element.
attachMediaStream(vid1, stream);
localstream = stream; localstream = stream;
btn1.disabled = false; btn1.disabled = false;
} }
navigator.webkitGetUserMedia({audio:true, video:true}, gotStream, function() {}); getUserMedia({audio:true, video:true}, gotStream, function() {});
function start() { function start() {
btn1.disabled = true; btn1.disabled = true;
btn2.disabled = false; btn2.disabled = false;
btn3.disabled = false;
trace("Starting Call"); trace("Starting Call");
if (localstream.videoTracks.length > 0) videoTracks = localstream.getVideoTracks();
trace('Using Video device: ' + localstream.videoTracks[0].label); // Prints audio & video device names audioTracks = localstream.getAudioTracks();
if (localstream.audioTracks.length > 0) if (videoTracks.length > 0)
trace('Using Audio device: ' + localstream.audioTracks[0].label); trace('Using Video device: ' + videoTracks[0].label);
if (audioTracks.length > 0)
trace('Using Audio device: ' + audioTracks[0].label);
pc1 = new webkitPeerConnection00(null,iceCallback1); var servers = null;
trace("Created local peer connection object pc1"); pc1 = new RTCPeerConnection(servers);
pc2 = new webkitPeerConnection00(null,iceCallback2); trace("Created local peer connection object pc1");
pc1.onicecandidate = iceCallback1;
pc2 = new RTCPeerConnection(servers);
trace("Created remote peer connection object pc2"); trace("Created remote peer connection object pc2");
pc2.onicecandidate = iceCallback2;
pc2.onaddstream = gotRemoteStream; pc2.onaddstream = gotRemoteStream;
pc1.addStream(localstream); pc1.addStream(localstream);
trace("Adding Local Stream to peer connection"); trace("Adding Local Stream to peer connection");
var offer = pc1.createOffer(null);
trace("Created offer:\n" + offer.toSdp()); pc1.createOffer(gotDescription1);
pc1.setLocalDescription(pc1.SDP_OFFER, offer);
trace("SetLocalDesc1"); }
pc2.setRemoteDescription(pc2.SDP_OFFER, offer);
trace("SetRemoteDesc2"); function gotDescription1(desc) {
var answer = pc2.createAnswer(offer.toSdp(), {has_audio:true, has_video:true}); pc1.setLocalDescription(desc);
var sdp = answer.toSdp(); trace("Offer from pc1 \n" + desc.sdp);
sdp = sdp.replace(/a=sendrecv/g, "a=inactive"); pc2.setRemoteDescription(desc);
answer = new SessionDescription(sdp); // Since the "remote" side has no media stream we need
trace("Created answer:\n" + answer.toSdp()); // to pass in the right constraints in order for it to
pc2.setLocalDescription(pc2.SDP_PRANSWER, answer); // accept the incoming offer of audio and video.
trace("SetLocalDesc2"); pc2.createAnswer(gotDescription2, null, sdpConstraints);
pc1.setRemoteDescription(pc1.SDP_PRANSWER, answer); }
trace("SetRemoteDesc1");
pc1.startIce(); // Start finding local ice candidates. Once it finds candidates it will call icecallback function gotDescription2(desc) {
pc2.startIce(); //Starts finding remote ice candidates. Once it finds candidates it will call iceCallback2 // Provisional answer, set a=inactive & set sdp type to pranswer.
trace("Start ICE for both local & remote"); desc.sdp = desc.sdp.replace(/a=recvonly/g, "a=inactive");
desc.type = "pranswer";
pc2.setLocalDescription(desc);
trace("Pranswer from pc2 \n" + desc.sdp);
pc1.setRemoteDescription(desc);
}
function gotDescription3(desc) {
// Final answer, setting a=recvonly & sdp type to answer.
desc.sdp = desc.sdp.replace(/a=inactive/g, "a=recvonly");
desc.type = "answer";
pc2.setLocalDescription(desc);
trace("Answer from pc2 \n" + desc.sdp);
pc1.setRemoteDescription(desc);
} }
function accept() { function accept() {
var sdp = pc1.remoteDescription.toSdp(); pc2.createAnswer(gotDescription3, null, sdpConstraints);
sdp = sdp.replace(/a=inactive/g, "a=sendrecv"); btn2.disabled = true;
var answer = new SessionDescription(sdp); btn1.disabled = false;
pc2.setLocalDescription(pc1.SDP_ANSWER, answer);
pc1.setRemoteDescription(pc2.SDP_ANSWER, answer);
trace("Set final answer:" + sdp);
} }
function stop() { function stop() {
@ -98,28 +111,28 @@ function stop() {
pc2=null; pc2=null;
btn2.disabled = true; btn2.disabled = true;
btn1.disabled = false; btn1.disabled = false;
btn3.disabled = true;
} }
function gotRemoteStream(e){ function gotRemoteStream(e) {
vid2.src = webkitURL.createObjectURL(e.stream); vid2.src = webkitURL.createObjectURL(e.stream);
trace("Received Remote Stream"); trace("Received remote stream");
} }
function iceCallback1(candidate,bMore){ function iceCallback1(event) {
if (candidate) { if (event.candidate) {
pc2.processIceMessage(candidate); pc2.addIceCandidate(new RTCIceCandidate(event.candidate));
traceCandidate("local", candidate); trace("Local ICE candidate: \n" + event.candidate.candidate);
} }
} }
function iceCallback2(candidate,bMore){ function iceCallback2(event) {
if (candidate) { if (event.candidate) {
pc1.processIceMessage(candidate); pc1.addIceCandidate(new RTCIceCandidate(event.candidate));
traceCandidate("remote", candidate); trace("Remote ICE candidate: \n " + event.candidate.candidate);
} }
} }
</script> </script>
</body> </body>
</html> </html>

View File

@ -56,12 +56,6 @@
<td> <td>
Shows how to set up a simple 1:1 audio only call.</td> Shows how to set up a simple 1:1 audio only call.</td>
</tr> </tr>
<tr>
<td>
<a href="html/pc1-deprecated.html">pc1-deprecated.html</a></td>
<td>
Like pc1.html, but uses PeerConnection00 instead of RTCPeerConnection.</td>
</tr>
<tr> <tr>
<td> <td>
<a href="html/multiple.html">multiple.html</a></td> <a href="html/multiple.html">multiple.html</a></td>