Skip to main content

Overview

A Configuration defines how peer-to-peer communication via PeerConnection is established or re-established. Configurations may be set up once and reused across multiple connections.
Source: configuration.go:9-59
Configurations are treated as readonly. As long as they are unmodified, they are safe for concurrent use.

Type Definition

Fields

ICEServers

[]ICEServer
Defines a slice describing servers available to be used by ICE, such as STUN and TURN servers.
Source: configuration.go:15-17
ICE servers help with NAT traversal and relay traffic when direct peer-to-peer connections aren’t possible.
STUN servers help discover your public IP address, while TURN servers relay traffic when direct connections fail.

ICETransportPolicy

ICETransportPolicy
Indicates which candidates the ICEAgent is allowed to use.
Source: configuration.go:19-21
Possible values:
  • ICETransportPolicyAll (default) - All candidates may be used
  • ICETransportPolicyRelay - Only relay candidates (TURN) may be used
Using ICETransportPolicyRelay requires a TURN server and prevents direct peer-to-peer connections.

BundlePolicy

BundlePolicy
Indicates which media-bundling policy to use when gathering ICE candidates.
Source: configuration.go:23-25
Possible values:
  • BundlePolicyBalanced (default)
  • BundlePolicyMaxBundle - Bundle all media on a single transport
  • BundlePolicyMaxCompat - Use separate transports for each media type

RTCPMuxPolicy

RTCPMuxPolicy
Indicates which RTCP-mux policy to use when gathering ICE candidates.
Source: configuration.go:27-29
Possible values:
  • RTCPMuxPolicyRequire (default) - Only gather RTCP candidates for multiplexed RTCP
  • RTCPMuxPolicyNegotiate - Gather ICE candidates for both RTP and RTCP
Modern WebRTC implementations typically use RTCPMuxPolicyRequire to multiplex RTP and RTCP on the same port.

PeerIdentity

string
Sets the target peer identity for the PeerConnection. The PeerConnection will not establish a connection to a remote peer unless it can be successfully authenticated with the provided name.
Source: configuration.go:31-34

Certificates

[]Certificate
Describes a set of certificates that the PeerConnection uses to authenticate.
Source: configuration.go:36-47
Valid values are created through calls to the GenerateCertificate function. If this value is absent, a default set of certificates is generated for each PeerConnection instance.
Although any given DTLS connection will use only one certificate, this attribute allows multiple certificates that support different algorithms. Certificates cannot be modified after the PeerConnection is created.

ICECandidatePoolSize

uint8
Describes the size of the prefetched ICE pool.
Source: configuration.go:49-50
Setting this to a non-zero value allows ICE candidates to be gathered before calling CreateOffer() or CreateAnswer().
Currently, pool sizes greater than 1 are not supported and will result in an error.

SDPSemantics

SDPSemantics
Controls the type of SDP offers accepted by and SDP answers generated by the PeerConnection.
Source: configuration.go:52-54
Possible values:
  • SDPSemanticsUnifiedPlan (default) - Modern standard
  • SDPSemanticsPlanB - Legacy Google Plan B
  • SDPSemanticsUnifiedPlanWithFallback - Try Unified Plan, fall back to Plan B
Use SDPSemanticsUnifiedPlan for new applications. Plan B is deprecated but may be needed for compatibility with older implementations.

AlwaysNegotiateDataChannels

bool
Specifies whether the application prefers to always negotiate data channels in the initial SDP offer.
Source: configuration.go:56-58
When set to true, a data channel section will be included in the SDP even if no data channels have been created yet.

Usage Examples

Minimal configuration with a public STUN server:
Configuration including TURN for relay:
Force all traffic through TURN (no direct connections):
Full configuration with all options:

Modifying Configuration

After creating a PeerConnection, you can update certain configuration properties:
Immutable Properties: The following cannot be modified after creation:
  • Certificates
  • BundlePolicy
  • RTCPMuxPolicy
  • ICECandidatePoolSize (after SetLocalDescription)
  • PeerIdentity

Best Practices

Use STUN for Discovery

Always include at least one STUN server to discover your public IP address for NAT traversal.

Include TURN for Reliability

Add a TURN server for scenarios where direct connections fail (strict firewalls, symmetric NATs).

Reuse Configurations

Create one configuration and reuse it across multiple PeerConnections to save resources.

Test Relay-Only

Test with ICETransportPolicyRelay to verify your TURN server works before production.

Common Patterns

Environment-Based Configuration

Configuration Validation

See Also