Skip to main content

Overview

Agent options provide a flexible, forward-compatible way to configure ICE agents using the functional options pattern. Each option is a function that modifies agent configuration.

Type Definition

Network Configuration

WithUrls

Sets the STUN/TURN server URLs. Can be updated at runtime via UpdateOptions.

WithPortRange

Sets the UDP port range for host candidates. Use 0 for both to let the OS choose ports.

WithNetworkTypes

Enables specific network types. See NetworkType.

WithCandidateTypes

Enables specific candidate types. See CandidateType.

Timeout Configuration

WithDisconnectedTimeout

Sets duration before transitioning to disconnected state. Use 0 to disable.

WithFailedTimeout

Sets duration after disconnected before transitioning to failed. Use 0 to disable.

WithKeepaliveInterval

Sets how often to send keepalive packets. Use 0 to disable.

WithCheckInterval

Sets how often to run connectivity checks while connecting.

WithSTUNGatherTimeout

Sets STUN server response timeout during gathering.

Candidate Acceptance Timing

WithHostAcceptanceMinWait

Minimum wait before selecting host candidates (default: 0).

WithSrflxAcceptanceMinWait

Minimum wait before selecting server reflexive candidates (default: 500ms).

WithPrflxAcceptanceMinWait

Minimum wait before selecting peer reflexive candidates (default: 1s).

WithRelayAcceptanceMinWait

Minimum wait before selecting relay candidates (default: 2s).

Address Rewriting

WithAddressRewriteRules

Adds address rewrite rules for 1:1 NAT mapping. See AddressRewriteRule.

ICE Configuration

WithICELite

Enables ICE-lite mode. Lite agents only gather host candidates.

WithMaxBindingRequests

Sets maximum binding requests before marking a pair as failed (default: 7).

WithEnableUseCandidateCheckPriority

For lite agents, checks priority before switching pairs on USE-CANDIDATE.

Multicast DNS

WithMulticastDNSMode

Configures mDNS behavior.

WithMulticastDNSHostName

Sets mDNS hostname (must end with “.local”).

Credentials

WithLocalCredentials

Sets local ICE credentials. Empty strings trigger auto-generation.
Credentials must meet minimum entropy: ufrag >= 24 bits, pwd >= 128 bits.

Renomination

WithRenomination

Enables ICE renomination (draft-thatcher-ice-renomination-01).

WithNominationAttribute

Sets the STUN attribute type for renomination (default: 0x0030).

WithAutomaticRenomination

Enables automatic renomination when better pairs become available.

Continual Gathering

WithContinualGatheringPolicy

Sets continual gathering behavior.

WithNetworkMonitorInterval

Sets network interface monitoring interval (requires GatherContinually).

TCP Configuration

WithTCPPriorityOffset

Value subtracted from TCP candidate priorities (default: 27).

WithDisableActiveTCP

Disables active TCP candidate creation.

Multiplexing

WithTCPMux

Sets TCP multiplexer for ICE-TCP.

WithUDPMux

Sets UDP multiplexer for host candidates.

WithUDPMuxSrflx

Sets UDP multiplexer for server reflexive candidates.

Filtering

WithInterfaceFilter

Filters network interfaces by name.

WithIPFilter

Filters IP addresses during gathering.

WithIncludeLoopback

Includes loopback addresses in candidates.

Advanced Options

WithNet

Sets custom network implementation (testing/virtual networks).

WithProxyDialer

Sets proxy dialer for TURN connections.

WithBindingRequestHandler

Sets custom STUN binding request handler.

WithLoggerFactory

Sets logger factory for structured logging.

Helper Functions

DefaultNominationValueGenerator

Returns a generator that produces incrementing nomination values starting at 1.