From aa74b5d69091d2c0972cfd111e43983a2a022112 Mon Sep 17 00:00:00 2001 From: "wu@webrtc.org" Date: Sat, 23 Nov 2013 00:37:50 +0000 Subject: [PATCH] Add success/error callback to set sdp calls. Add a workaround for crbug/322756 to append a line break to the end of sdp if needed. R=juberti@webrtc.org, vikasmarwaha@webrtc.org Review URL: https://webrtc-codereview.appspot.com/4299004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5167 4adac7df-926f-26a2-2b94-8c16560cd09d --- samples/js/demos/html/pc1_sdp_munge.html | 35 +++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/samples/js/demos/html/pc1_sdp_munge.html b/samples/js/demos/html/pc1_sdp_munge.html index 7caf68e39..07fc0dfa5 100644 --- a/samples/js/demos/html/pc1_sdp_munge.html +++ b/samples/js/demos/html/pc1_sdp_munge.html @@ -197,16 +197,38 @@ function createPC() { trace("Adding Local Stream to peer connection"); } +function onSetSessionDescriptionSuccess() { + trace('Set session description success.'); +} + +function onSetSessionDescriptionError(error) { + trace('Failed to set session description: ' + error.toString()); +} + +// Workaround for crbug/322756. +function maybeAddLineBreakToEnd(sdp) { + var endWithLineBreak = new RegExp(/\n$/); + if (!endWithLineBreak.test(sdp)) { + return sdp + '\n'; + } + return sdp; +} + function createOffer(){ pc1.createOffer(gotDescription1,null,null); } function setOffer(){ var sdp = document.getElementById("offerSdp").value; + sdp = maybeAddLineBreakToEnd(sdp); var offer = new RTCSessionDescription({type:'offer',sdp:sdp}); - pc1.setLocalDescription(offer); + pc1.setLocalDescription(offer, + onSetSessionDescriptionSuccess, + onSetSessionDescriptionError); trace("Modified Offer from pc1 \n" + sdp); - pc2.setRemoteDescription(offer); + pc2.setRemoteDescription(offer, + onSetSessionDescriptionSuccess, + onSetSessionDescriptionError); } function gotDescription1(desc) { @@ -223,10 +245,15 @@ function createAnswer(){ function setAnswer(){ var sdp = document.getElementById("answerSdp").value; + sdp = maybeAddLineBreakToEnd(sdp); var answer = new RTCSessionDescription({type:'answer',sdp:sdp}); - pc2.setLocalDescription(answer); + pc2.setLocalDescription(answer, + onSetSessionDescriptionSuccess, + onSetSessionDescriptionError); trace("Modified Answer from pc2 \n" + sdp); - pc1.setRemoteDescription(answer); + pc1.setRemoteDescription(answer, + onSetSessionDescriptionSuccess, + onSetSessionDescriptionError); } function gotDescription2(desc) {