Skip to main content

Overview

The SessionDescription type is used to expose local and remote session descriptions. It encapsulates the Session Description Protocol (SDP) information exchanged between peers during connection establishment.
Source: sessiondescription.go:39-46

Type Definition

SDPType
The type of session description (offer, answer, pranswer, or rollback)
string
The SDP string content
*sdp.SessionDescription
Internal parsed representation (not initialized by callers)

SDPType Enumeration

The SDPType describes the type of a SessionDescription.
Source: sdptype.go:11-39

SDPTypeOffer

SDPType
Indicates that a description MUST be treated as an SDP offer.
Used when initiating a connection or renegotiating.

SDPTypePranswer

SDPType
Indicates that a description MUST be treated as an SDP provisional answer, but not a final answer.
A pranswer may be applied as a response to an SDP offer, or an update to a previously sent SDP pranswer.
Provisional answers are rarely used in practice. Most applications use immediate final answers.

SDPTypeAnswer

SDPType
Indicates that a description MUST be treated as an SDP final answer, and the offer-answer exchange MUST be considered complete.
Used to respond to an offer or update a previously sent pranswer.

SDPTypeRollback

SDPType
Indicates that a description MUST be treated as canceling the current SDP negotiation and moving the SDP offer and answer back to what it was in the previous stable state.
Used to abort a negotiation in progress.

SDPType Methods

NewSDPType

Creates an SDPType from a string.
Source: sdptype.go:49-63
string
String representation (“offer”, “pranswer”, “answer”, or “rollback”)
SDPType
The corresponding SDPType, or SDPTypeUnknown if invalid

String

Returns the string representation of an SDPType.
Source: sdptype.go:65-78
string
String representation of the SDPType

SessionDescription Methods

Unmarshal

A helper to deserialize the SDP.
Source: sessiondescription.go:48-57
*sdp.SessionDescription
Parsed SDP structure
error
Error if unmarshaling fails
This method is typically used internally. Most application code doesn’t need to call it directly.

Usage with PeerConnection

Creating an Offer

Handling a Remote Offer

Creating an Answer

ICE Trickle Support

The SessionDescription type works with ICE trickle capability detection.
Source: sessiondescription.go:14-37

ICETrickleCapability

int
No remote peer has been established
int
Remote peer can accept trickled ICE candidates
int
Remote peer didn’t state that it can accept trickle ICE candidates

Complete Signaling Example

Best Practices

Always Set Locally First

Always call SetLocalDescription with the offer/answer you created before sending it to the remote peer.

Error Handling

Check errors from CreateOffer, CreateAnswer, and SetLocalDescription/SetRemoteDescription - they can fail.

Signaling Independence

SessionDescriptions are just data - you choose how to exchange them (WebSocket, HTTP, etc.).

JSON Serialization

SessionDescription has JSON tags and can be marshaled/unmarshaled directly.

Common Patterns

Handle offer collisions gracefully:
Modify SDP before setting (advanced):
Handle mid-call changes:

Troubleshooting

Common causes:
  • SDP format is invalid or corrupted
  • Wrong SDPType for current signaling state
  • Missing media sections that were in previous offer
According to JSEP 5.4, you can set an empty SDP string:

See Also