W3C home > Mailing lists > Public > public-webrtc@w3.org > June 2012

Suggestion: Less verbose syntax for offer/answer handling

From: Adam Bergkvist <adam.bergkvist@ericsson.com>
Date: Tue, 5 Jun 2012 15:58:14 +0200
Message-ID: <4FCE1076.1070106@ericsson.com>
To: "public-webrtc@w3.org" <public-webrtc@w3.org>
Hi

This suggestion uses the SdpType attribute of SessionDescription 
(discussed in:
http://lists.w3.org/Archives/Public/public-webrtc/2012May/0047.html) to 
include type information in the SessionDescription object. By doing so, 
we can have a less verbose syntax where the JavaScript developer can 
work with self-contained objects that are generated and understood by 
PeerConnection.

This doesn't reduce flexibility since the application can reset the type 
of, e.g., an "answer" to an "pranswer" to make PeerConnection interpret 
it as such.

Example of creating an offer:

--- Current syntax:

pc.createOffer(function (offer) {
     pc.setLocalDescription("offer", offer);
     sendMessage(JSON.stringify({ "type": "offer", "sdp": offer }));
});

--- Less verbose syntax:

pc.createOffer(function (offer) {
     pc.updateLocalDescription(offer);
     sendMessage(offer);
});

Example of handling an incoming signaling message:

--- Current syntax:

signalingChannel.onmessage = function (evt) {
     var msg = JSON.parse(evt.data);
     switch (msg.type) {
     case "offer":
         createPeerConnection();
         pc.setRemoteDescription(msg.type,
                                 new SessionDescription(msg.sdp));
         break;
     case "answer":
     case "pranswer":
         pc.setRemoteDescription(msg.type,
                                 new SessionDescription(msg.sdp));
         break;
     case "candidate":
         pc.addIceCandidate(new IceCandidate(msg.sdp));
         break;
     }
};

--- Less verbose syntax:

signalingChannel.onmessage = function (evt) {
     if (!pc)
         createPeerConnection();

     pc.updateRemoteDescription(evt.data);
};

/Adam
Received on Tuesday, 5 June 2012 14:46:39 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 5 June 2012 14:46:53 GMT