RTCSessionDescription

Signature

// Read from the connection (modern usage):
const desc = pc.localDescription; // RTCSessionDescription

// Sent and received as a plain init object:
// { type: 'offer' | 'answer' | 'pranswer' | 'rollback', sdp: '...' }

What it does

Holds the SDP for one side of a negotiation: the media, codecs, and transport parameters a peer proposes or accepts. Offers and answers are exchanged over signaling to align both ends.

Key members

Member Kind Purpose
type property offer, answer, pranswer, or rollback.
sdp property The Session Description Protocol string.
toJSON() method Returns a plain { type, sdp } object for transport.

Behaviour & constraints

  • The RTCSessionDescription constructor is deprecated; pass the plain init object directly to setLocalDescription() / setRemoteDescription().
  • pc.localDescription and pc.remoteDescription return live RTCSessionDescription objects.
  • sdp is text: serialize the whole object, never reconstruct the string by hand.
  • type must match the negotiation step: an offer is answered with an answer, not another offer.
  • rollback discards a local pending offer to recover from glare.

Example

const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
signalingSend(pc.localDescription.toJSON());

// remote side
signalingOn('sdp', async (desc) => {
  await pc.setRemoteDescription(desc);
  const answer = await pc.createAnswer();
  await pc.setLocalDescription(answer);
  signalingSend(pc.localDescription.toJSON());
});

See also