Overview
TheSessionDescription 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-46Type 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
TheSDPType describes the type of a SessionDescription.
Source:
sdptype.go:11-39SDPTypeOffer
SDPType
Indicates that a description MUST be treated as an SDP offer.
SDPTypePranswer
SDPType
Indicates that a description MUST be treated as an SDP provisional answer, but not a final answer.
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.
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.
SDPType Methods
NewSDPType
Creates an SDPType from a string.Source:
sdptype.go:49-63string
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-78string
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-37ICETrickleCapability
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
Perfect Negotiation Pattern
Perfect Negotiation Pattern
Handle offer collisions gracefully:
SDP Manipulation
SDP Manipulation
Modify SDP before setting (advanced):
Renegotiation
Renegotiation
Handle mid-call changes:
Troubleshooting
SetRemoteDescription Fails
SetRemoteDescription Fails
Common causes:
- SDP format is invalid or corrupted
- Wrong SDPType for current signaling state
- Missing media sections that were in previous offer
Empty SDP String
Empty SDP String
According to JSEP 5.4, you can set an empty SDP string:
See Also
- PeerConnection - Creating and setting descriptions
- Configuration - Connection configuration
- SDP Specification - Session Description Protocol
- JSEP - JavaScript Session Establishment Protocol