Overview
TheDTLSTransport allows an application access to information about the DTLS transport over which RTP and RTCP packets are sent and received by RTPSender and RTPReceiver, as well as other data such as SCTP packets sent and received by data channels.
This is part of the ORTC API. It is not meant to be used together with the basic WebRTC API.
Type Definition
dtlstransport.go
Constructor
NewDTLSTransport
Creates a new DTLSTransport over an ICE transport.dtlstransport.go
*ICETransport
required
The underlying ICE transport to use
[]Certificate
List of certificates to use for DTLS. If empty, a certificate will be generated automatically.
*DTLSTransport, error
Returns a new DTLSTransport instance or an error if creation fails
Methods
Start
Starts DTLS transport negotiation with the parameters of the remote DTLS transport.dtlstransport.go
DTLSParameters
required
Remote DTLS parameters including fingerprints and role
error
Returns nil on success, or an error if the transport cannot be started
Stop
Stops and closes the DTLSTransport.dtlstransport.go
error
Returns nil on success, or an error if stopping fails
State
Returns the current DTLS transport state.dtlstransport.go
DTLSTransportState
The current state (New, Connecting, Connected, Closed, Failed)
ICETransport
Returns the currently-configured ICETransport.dtlstransport.go
*ICETransport
Returns the underlying ICE transport or nil if not configured
GetLocalParameters
Returns the DTLS parameters of the local DTLSTransport.dtlstransport.go
DTLSParameters, error
Returns the local DTLS parameters or an error
GetRemoteCertificate
Returns the certificate chain in use by the remote side.dtlstransport.go
[]byte
Returns the raw DER-encoded remote certificate, or an empty slice if not yet selected
OnStateChange
Sets a handler that fires when the DTLS connection state changes.dtlstransport.go
func(DTLSTransportState)
required
Callback function that receives state change notifications
WriteRTCP
Sends user-provided RTCP packets to the connected peer.dtlstransport.go
[]rtcp.Packet
required
RTCP packets to send
int, error
Returns the number of bytes written and any error that occurred
States
The DTLSTransport can be in one of the following states:- DTLSTransportStateNew: Initial state
- DTLSTransportStateConnecting: DTLS handshake in progress
- DTLSTransportStateConnected: DTLS handshake completed successfully
- DTLSTransportStateClosed: Transport has been closed
- DTLSTransportStateFailed: DTLS handshake or connection failed
DTLS Roles
The DTLSTransport can operate in different roles:- DTLSRoleAuto: Role is determined automatically based on ICE role
- DTLSRoleClient: Acts as DTLS client (initiates handshake)
- DTLSRoleServer: Acts as DTLS server (responds to handshake)
Usage Example
Security Considerations
Fingerprint Verification
The DTLS handshake includes automatic verification of the remote certificate’s fingerprint against the fingerprints provided in the remote parameters. This prevents man-in-the-middle attacks.Certificate Lifetime
By default, auto-generated certificates are valid for 1 month. For production use, consider:- Using longer-lived certificates
- Implementing certificate rotation
- Monitoring certificate expiration
See Also
- ICETransport - Underlying ICE transport
- Certificate - DTLS certificate management
- PeerConnection - High-level WebRTC API
- SRTP - Secure RTP specification