How to modify SDP before setting local description?

271 views
Skip to first unread message

fragrant corn

unread,
Jul 11, 2013, 7:52:31 AM7/11/13
to discuss...@googlegroups.com
Hi!
I want to know how to modify SDP before setting local description. 
After create offer, can i get the body, modify it and then set to local description? 
What API should i use?
Thank you!

Vikas

unread,
Jul 11, 2013, 4:08:25 PM7/11/13
to discuss...@googlegroups.com
Hi,

You should take a look at pc1 demo source. Basically when you call createOffer api, you get a callback with sessiondescription. For e,g, In below code gotdescription1 is the callback function & desc.sdp is the sdp that you can modify before calling SetLocalDescription.:-

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);
}

/Vikas

fragrant corn

unread,
Jul 11, 2013, 9:31:03 PM7/11/13
to discuss...@googlegroups.com
Hi, thank you for your help.

Besides what you have provided, i also have a doubt.
Since desc.sdp is not structurized, it is very easy to make mistakes when modify the value of desc.sdp. I want to know what method is best if i want to change "a=sendrecv" to "a:recvonly".

fragrant corn

unread,
Jul 12, 2013, 2:19:50 AM7/12/13
to discuss...@googlegroups.com
Hi, thank you for your help.
I want to modify desc.sdp, but since the value of it belongs to no data struct, when modifying it (for example change a:sendrecv to a:recvonly), it is easy to make mistakes. So i want to know is there any proper API or method i can use to modify it.

Vikas

unread,
Jul 12, 2013, 6:15:39 PM7/12/13
to discuss...@googlegroups.com
Hi,

You can use the replace method. Something like below:

desc.sdp = desc.sdp.replace(/a=sendrecv/g, "a=recvonly");

/Vikas
Reply all
Reply to author
Forward
0 new messages