Skip to main content

What is Signaling?

Signaling is the process of coordinating communication between two peers. In WebRTC, this involves exchanging session information (SDP) and network connectivity information (ICE candidates) before a peer-to-peer connection can be established.
WebRTC does not specify a signaling protocol - you can use WebSockets, HTTP, MQTT, or any other mechanism to exchange signaling messages between peers.

Session Description Protocol (SDP)

SDP is a text format that describes multimedia sessions. In Pion WebRTC, SDP is represented by the SessionDescription type:
sessiondescription.go

SDP Types

There are four types of SDP messages:

Offer

Initial proposal from the caller with supported codecs, media tracks, and capabilities.

Answer

Response from the callee with its own capabilities, negotiated with the offer.

Pranswer

Provisional answer - a partial answer that may be updated later.

Rollback

Cancel a previous offer/answer and return to the stable state.

The Offer/Answer Exchange

The signaling process follows a well-defined sequence:

Creating an Offer

The caller creates an offer describing its capabilities:
From the source code, here’s how offers are created:
peerconnection.go
Add all your tracks and data channels before calling CreateOffer() to include them in the initial negotiation.

Creating an Answer

The callee receives the offer and creates an answer:
The answer creation logic:
peerconnection.go
You must set the remote description before creating an answer. The answer is generated based on the received offer.

Setting Descriptions

Local Description

Setting the local description commits your offer or answer:
peerconnection.go

Remote Description

peerconnection.go

ICE Trickle

ICE trickle allows sending candidates incrementally rather than waiting for all candidates:
sessiondescription.go
Implementing trickle ICE:
Trickle ICE significantly reduces connection setup time by allowing ICE candidate exchange to happen in parallel with the offer/answer exchange.

Perfect Negotiation

Perfect negotiation is a pattern that eliminates glare (both sides creating offers simultaneously):

Signaling Server Examples

WebSocket Signaling

HTTP Polling

SDP Manipulation

Sometimes you need to modify SDP before setting it:
Be careful when modifying SDP. Invalid modifications can cause connection failures or incompatibilities.

Renegotiation

Renegotiation updates an existing connection:

Next Steps

ICE & Connectivity

Learn about ICE candidates and NAT traversal

Media Streams

Working with audio and video tracks