WebRTC samples Perfect Negotiation

This sample shows how to setup a connection between two peers using RTCPeerConnection with the Perfect Negotiation usage pattern.

Perfect Negotiation supports both endpoints sending offers. The pattern intelligently handles the situation of "glare" (both peers making an offer at the same time, causing a collision) by having one peer be "polite" and the other peer be "impolite". In the event of an offer collision, the polite peer rolls back its offer in order to process the impolite peer's incoming offer. Once back to the stable signaling state, the polite peer's onnegotiationneeded fires again and a follow-up O/A is completed.

Click both peers' Start button to create local streams. Then press the Swap Sending Track button to modify which transceiver is sending; this will be negotiated and displayed as a remote track on the other peer's iframe.

The JavaScript console shows logs for the negotiation steps.

For more information about RTCPeerConnection, see Getting Started With WebRTC.

View source on GitHub