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
RTCSessionDescriptionconstructor is deprecated; pass the plain init object directly tosetLocalDescription()/setRemoteDescription(). pc.localDescriptionandpc.remoteDescriptionreturn liveRTCSessionDescriptionobjects.sdpis text: serialize the whole object, never reconstruct the string by hand.typemust match the negotiation step: an offer is answered with an answer, not another offer.rollbackdiscards 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());
});