webRTC: Session establishment
A session consists of a peer connection on either end, with negotiated session parameters and an established bi-directional UDP connection.
The session parameters, or description, are specified as a Session Description Protocol message (SDP).
It's easiest to arrange things so that one peer, the caller, initiates the negotiations to the other perr, the caller:
- The caller produces and stores their local SDP, the offer, and sends that to the callee.
- The callee stores the offer as their remote SDP, generates and stores their local SDP, the answer, and sends that back to the caller.
Once both parties know each other's session parameters they independently come to the same conclusion about how the session should work. Note that this is done entirely via the signaling channel, and does not involve a peer to peer connection.
ICE tries to establish a UDP connection path between peers by identifying UDP address "candidates". These candidates are communicated via the signalling channel, and both sides attempt to connect to all the other peer's candidates.
- Peer already knows its local address, "host candidate"
- 👈 This enables direct connection within a network
- Peer optionally uses STUN server to discover its external address, "reflexive candidate"
- 👈 This enables UDP hole punching though Endpoint Independent Mapping NAT (EIM)
- As the peer is informed about the remote peer's candidates it initiates connectivity checks to them, thereby opening more addresses, "trickle ICE candidates"
- 👈 This enables UDP hole punching though Endpoint Dependent Mapping NAT (EDM)
- Peer optionally sets up an external relay address, "relay candidate"
- 👈 This enables connectivity even if direct UDP connection is impossible