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