Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add success and error callbacks to setLocalDescription and setRemoteDesc... #74

Closed
wants to merge 9 commits into from
20 changes: 16 additions & 4 deletions samples/web/content/constraints/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,24 @@ function createPeerConnection() {
};
localPeerConnection.createOffer(function (desc) {
console.log('localPeerConnection offering');
localPeerConnection.setLocalDescription(desc);
remotePeerConnection.setRemoteDescription(desc);
localPeerConnection.setLocalDescription(desc,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would prefer to keep these args on the same line, as long line is < 80 chars (here and below)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hitting 82 chars in some places... reduce it to a single line where possible and two lines elsewhere or two lines (putting webrtc.noop and webrtc.error on the second) everywhere?

(no preference, anything that makes jshint happy is fine with me :-)

webrtc.noop,
webrtc.error
);
remotePeerConnection.setRemoteDescription(desc,
webrtc.noop,
webrtc.error
);
remotePeerConnection.createAnswer(function (desc2) {
console.log('remotePeerConnection answering');
remotePeerConnection.setLocalDescription(desc2);
localPeerConnection.setRemoteDescription(desc2);
remotePeerConnection.setLocalDescription(desc2,
webrtc.noop,
webrtc.error
);
localPeerConnection.setRemoteDescription(desc2,
webrtc.noop,
webrtc.error
);
});
});
}
Expand Down
5 changes: 4 additions & 1 deletion samples/web/content/create-offer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ <h3>Constraints:</h3>
}

function gotDescription(desc) {
pc.setLocalDescription(desc);
pc.setLocalDescription(desc,
webrtc.noop,
webrtc.error
);
output.value = desc.sdp;
}
</script>
Expand Down
20 changes: 16 additions & 4 deletions samples/web/content/datachannel/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,28 @@ function closeDataChannels() {
}

function gotDescription1(desc) {
localConnection.setLocalDescription(desc);
localConnection.setLocalDescription(desc,
webrtc.noop,
webrtc.error
);
trace('Offer from localConnection \n' + desc.sdp);
remotePeerConnection.setRemoteDescription(desc);
remotePeerConnection.setRemoteDescription(desc,
webrtc.noop,
webrtc.error
);
remotePeerConnection.createAnswer(gotDescription2, onCreateSessionDescriptionError);
}

function gotDescription2(desc) {
remotePeerConnection.setLocalDescription(desc);
remotePeerConnection.setLocalDescription(desc,
webrtc.noop,
webrtc.error
);
trace('Answer from remotePeerConnection \n' + desc.sdp);
localConnection.setRemoteDescription(desc);
localConnection.setRemoteDescription(desc,
webrtc.noop,
webrtc.error
);
}

function iceCallback1(event) {
Expand Down
20 changes: 16 additions & 4 deletions samples/web/content/dtmf/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ function call() {
}

function gotDescription1(desc) {
pc1.setLocalDescription(desc);
pc1.setLocalDescription(desc,
webrtc.noop,
webrtc.error
);
trace('Offer from pc1 \n' + desc.sdp);
pc2.setRemoteDescription(desc);
pc2.setRemoteDescription(desc,
webrtc.noop,
webrtc.error
);
// 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.
Expand All @@ -104,9 +110,15 @@ function gotDescription2(desc) {
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,
webrtc.noop,
webrtc.error
);
trace('Answer from pc2: \n' + desc.sdp);
pc1.setRemoteDescription(desc);
pc1.setRemoteDescription(desc,
webrtc.noop,
webrtc.error
);
}

function hangup() {
Expand Down
40 changes: 32 additions & 8 deletions samples/web/content/multiple/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,15 @@
}

function gotDescription1Local(desc) {
pc1_local.setLocalDescription(desc);
pc1_local.setLocalDescription(desc,
webrtc.noop,
webrtc.error
);
trace("Offer from pc1_local \n" + desc.sdp);
pc1_remote.setRemoteDescription(desc);
pc1_remote.setRemoteDescription(desc,
webrtc.noop,
webrtc.error
);
// 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.
Expand All @@ -119,15 +125,27 @@
}

function gotDescription1Remote(desc) {
pc1_remote.setLocalDescription(desc);
pc1_remote.setLocalDescription(desc,
webrtc.noop,
webrtc.error
);
trace("Answer from pc1_remote \n" + desc.sdp);
pc1_local.setRemoteDescription(desc);
pc1_local.setRemoteDescription(desc,
webrtc.noop,
webrtc.error
);
}

function gotDescription2Local(desc) {
pc2_local.setLocalDescription(desc);
pc2_local.setLocalDescription(desc,
webrtc.noop,
webrtc.error
);
trace("Offer from pc2_local \n" + desc.sdp);
pc2_remote.setRemoteDescription(desc);
pc2_remote.setRemoteDescription(desc,
webrtc.noop,
webrtc.error
);
// 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.
Expand All @@ -136,9 +154,15 @@
}

function gotDescription2Remote(desc) {
pc2_remote.setLocalDescription(desc);
pc2_remote.setLocalDescription(desc,
webrtc.noop,
webrtc.error
);
trace("Answer from pc2_remote \n" + desc.sdp);
pc2_local.setRemoteDescription(desc);
pc2_local.setRemoteDescription(desc,
webrtc.noop,
webrtc.error
);
}

function hangup() {
Expand Down
20 changes: 16 additions & 4 deletions samples/web/content/peerconnection-audio/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ function call() {
}

function gotDescription1(desc) {
pc1.setLocalDescription(desc);
pc1.setLocalDescription(desc,
webrtc.noop,
webrtc.error
);
trace('Offer from pc1 \n' + desc.sdp);
pc2.setRemoteDescription(desc);
pc2.setRemoteDescription(desc,
webrtc.noop,
webrtc.error
);
// 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.
Expand All @@ -76,9 +82,15 @@ function gotDescription1(desc) {
}

function gotDescription2(desc) {
pc2.setLocalDescription(desc);
pc2.setLocalDescription(desc,
webrtc.noop,
webrtc.error
);
trace('Answer from pc2 \n' + desc.sdp);
pc1.setRemoteDescription(desc);
pc1.setRemoteDescription(desc,
webrtc.noop,
webrtc.error
);
}

function hangup() {
Expand Down
20 changes: 16 additions & 4 deletions samples/web/content/peerconnection-states/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,29 @@ function onCreateSessionDescriptionError(error) {
}

function gotDescription1(description) {
pc1.setLocalDescription(description);
pc1.setLocalDescription(description,
webrtc.noop,
webrtc.error
);
trace('Offer from pc1: \n' + description.sdp);
pc2.setRemoteDescription(description);
pc2.setRemoteDescription(description,
webrtc.noop,
webrtc.error
);
pc2.createAnswer(gotDescription2, onCreateSessionDescriptionError,
sdpConstraints);
}

function gotDescription2(description) {
pc2.setLocalDescription(description);
pc2.setLocalDescription(description,
webrtc.noop,
webrtc.error
);
trace('Answer from pc2 \n' + description.sdp);
pc1.setRemoteDescription(description);
pc1.setRemoteDescription(description,
webrtc.noop,
webrtc.error
);
}

function hangup() {
Expand Down
28 changes: 24 additions & 4 deletions samples/web/content/peerconnection/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,19 @@ function onCreateSessionDescriptionError(error) {
function onCreateOfferSuccess(desc) {
trace('Offer from pc1\n' + desc.sdp);
trace('pc1 setLocalDescription start');
pc1.setLocalDescription(desc, function() { onSetLocalSuccess(pc1); });
pc1.setLocalDescription(desc,
function() {
onSetLocalSuccess(pc1);
},
webrtc.error
);
trace('pc2 setRemoteDescription start');
pc2.setRemoteDescription(desc, function() { onSetRemoteSuccess(pc2); });
pc2.setRemoteDescription(desc,
function() {
onSetRemoteSuccess(pc2);
},
webrtc.error
);
trace('pc2 createAnswer start');
// Since the 'remote' side has no media stream we need
// to pass in the right constraints in order for it to
Expand All @@ -142,9 +152,19 @@ function gotRemoteStream(e) {
function onCreateAnswerSuccess(desc) {
trace('Answer from pc2:\n' + desc.sdp);
trace('pc2 setLocalDescription start');
pc2.setLocalDescription(desc, function() { onSetLocalSuccess(pc2); });
pc2.setLocalDescription(desc,
function() {
onSetLocalSuccess(pc2);
},
webrtc.error
);
trace('pc1 setRemoteDescription start');
pc1.setRemoteDescription(desc, function() { onSetRemoteSuccess(pc1); });
pc1.setRemoteDescription(desc,
function() {
onSetRemoteSuccess(pc1);
},
webrtc.error
);
}


Expand Down
30 changes: 24 additions & 6 deletions samples/web/content/pr-answer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@
}

function gotDescription1(desc) {
pc1.setLocalDescription(desc);
pc1.setLocalDescription(desc,
webrtc.noop,
webrtc.error
);
trace("Offer from pc1 \n" + desc.sdp);
pc2.setRemoteDescription(desc);
pc2.setRemoteDescription(desc,
webrtc.noop,
webrtc.error
);
// 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.
Expand All @@ -95,18 +101,30 @@
// 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);
pc2.setLocalDescription(desc,
webrtc.noop,
webrtc.error
);
trace("Pranswer from pc2 \n" + desc.sdp);
pc1.setRemoteDescription(desc);
pc1.setRemoteDescription(desc,
webrtc.noop,
webrtc.error
);
}

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);
pc2.setLocalDescription(desc,
webrtc.noop,
webrtc.error
);
trace("Answer from pc2 \n" + desc.sdp);
pc1.setRemoteDescription(desc);
pc1.setRemoteDescription(desc,
webrtc.noop,
webrtc.error
);
}

function accept() {
Expand Down
5 changes: 4 additions & 1 deletion samples/web/content/trickle-ice/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ function start() {

function gotDescription(desc) {
begin = window.performance.now();
pc.setLocalDescription(desc);
pc.setLocalDescription(desc,
webrtc.noop,
webrtc.error
);
}

function noDescription(error) {
Expand Down
22 changes: 17 additions & 5 deletions samples/web/content/webaudio-input/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,28 @@
console.log('Offer from pc1 \n' + desc.sdp);
var modifiedOffer = new RTCSessionDescription({type: 'offer',
sdp: forceOpus(desc.sdp)});
pc1.setLocalDescription(modifiedOffer);
pc1.setLocalDescription(modifiedOffer,
webrtc.noop,
webrtc.error
);
console.log('Offer from pc1 \n' + modifiedOffer.sdp);
pc2.setRemoteDescription(modifiedOffer);
pc2.createAnswer(gotDescription2);
pc2.setRemoteDescription(modifiedOffer,
webrtc.noop,
webrtc.error
);
pc2.createAnswer(gotDescription2, webrtc.error);
}

function gotDescription2(desc){
pc2.setLocalDescription(desc);
pc2.setLocalDescription(desc,
webrtc.noop,
webrtc.error
);
console.log('Answer from pc2 \n' + desc.sdp);
pc1.setRemoteDescription(desc);
pc1.setRemoteDescription(desc,
webrtc.noop,
webrtc.error
);
}

function gotRemoteStream(e){
Expand Down
Loading