Henrik Boström
unread,6:55 AM (8 hours ago) 6:55 AMSign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to blink-dev, Alex Russell, philipp...@googlemail.com, blink-dev, PhistucK, Robert Flack, Harald Alvestrand, Rick Byers, Henrik Boström, Yoav Weiss
I'll also shime in to try to explain how this works, example:
const pc = new RTCPeerConnection({alwaysNegotiateDataChannels:true});
pc.addTransceiver('video');
await pc.setLocalDescription(); // Creates SDP offer
console.log(pc.localDescription.sdp); // Prints the resulting SDP
This will print SDP with the following m= sections and in the following order (note that real SDP contains more text, but this is the relevant part of it all):
m=application
m=video
The benefit of negotiating the m=application first like this is that upon completing the offer-answer dance with a remote endpoint, it is possible for either endpoint to perform pc.createDataChannel() and for that data channel to show up on the other side (via the pc.ondatachannel event handler). Once the m-line is negotiated, we can create any data channels without having to re-negotiate the SDP. This does not happen if SDP was negotiated without the m=application line.
Today, to force the m=application line to show up, you have to createDataChannel *before* creating the SDP offer. E.g.
const pc = new RTCPeerConnection();
pc.createDataChannel(...);
pc.addTransceiver('video');
await pc.setLocalDescription();
Here the order, while well define, is less predictable to the web application, and the result is - mostly for historical reasons - surprisingly reversed from the API call order:
m=video
So if you want the m=application line to not depend on how many transceivers you happened to have had at the time when you created the initial offer, you'd have to actually may two separate SDP offer-answer exchanges, adding both complexity and another round-trip time to your call setup just for the sake of locking in an order that shouldn't really matter, but due to its unpredictable nature could cause application bugs (Google Meet being an example of who had a bug here).
const pc = new RTCPeerConnection();
pc.createDataChannel(...);
await pc.setLocalDescription(); // Lock in m= application first
/* ... complete negotiation to remote endpoint */
pc.addTransceiver('video');
await pc.setLocalDescription(); // Follow-up offer...
Note that this headache is just for the local endpoint that is creating the SDP offer. The remote endpoint (whether they support alwaysNegotiateDataChannels or not) is able to process SDP regardless of the m-line order, which is why I don't think there are any backwards/cross compatibility issues with this beyond the usual of having to feature detect with pc.getConfiguration(). And once the order is "locked in", it stays that way for both endpoints, regardless of who creates the next offer.
So in short, this API makes life a little less complex, saying you're interested in data channels whether or not you want to create that data channel now or later (without re-negotiating).