The SDP Offer/Answer Rules That Bite During WebRTC Renegotiation

WebRTC developers do not normally bother about an SDP blob. It just works in the initial negotiation, media streams are exchanged, and the details of the format are irrelevant. But once renegotiation happens — adding a track, starting a screen share, performing ICE restart — things break, and you get an error message as if it was meant for somebody else. Failed to set remote answer sdp: The order of m-lines in answer doesn't match order in offer. Rejecting answer. There are some rules which generate these errors and they are quite simple but they remain hidden until you violate them. Here are a few of them which you should know in advance. Media sections are positional, and their order is
…