Skip to main content

Overview

The CandidateType enum represents the type of ICE candidate as defined in RFC 5245. Each type indicates how the candidate address was obtained and affects its priority in the connection establishment process.

Type Definition

Types

CandidateTypeHost

A host candidate represents a local network address obtained directly from a network interface. Characteristics:
  • Highest priority (preference: 126)
  • No STUN/TURN servers required
  • Direct peer-to-peer connection
  • Best latency and bandwidth

CandidateTypeServerReflexive

A server reflexive (srflx) candidate is discovered by sending a STUN Binding Request to a STUN server, which returns the public address as seen from the Internet. Characteristics:
  • Medium-high priority (preference: 100)
  • Requires STUN server
  • Reveals public NAT address
  • Good for NAT traversal
Short form: "srflx"

CandidateTypePeerReflexive

A peer reflexive (prflx) candidate is discovered from the source address of a STUN Binding Request received from the peer. Characteristics:
  • Medium priority (preference: 110)
  • Discovered during connectivity checks
  • Created automatically by the ICE agent
  • Not gathered explicitly
Short form: "prflx"

CandidateTypeRelay

A relay candidate is obtained by allocating an address on a TURN relay server. All media flows through the relay. Characteristics:
  • Lowest priority (preference: 0)
  • Requires TURN server
  • Guaranteed connectivity
  • Higher latency and bandwidth cost
  • Most reliable for restrictive NATs

CandidateTypeUnspecified

Represents an unspecified or unknown candidate type.

Methods

String

Returns the string representation of the candidate type. Returns:
  • "host" for CandidateTypeHost
  • "srflx" for CandidateTypeServerReflexive
  • "prflx" for CandidateTypePeerReflexive
  • "relay" for CandidateTypeRelay
  • "Unknown candidate type" for CandidateTypeUnspecified or invalid values

Preference

Returns the RFC 5245 recommended preference weight for the candidate type. Higher values indicate higher priority. Returns:
  • 126 for CandidateTypeHost
  • 110 for CandidateTypePeerReflexive
  • 100 for CandidateTypeServerReflexive
  • 0 for CandidateTypeRelay and CandidateTypeUnspecified

Priority Order

Usage Examples

Default Behavior

When no candidate types are specified, all three gatherable types are enabled:
Peer reflexive candidates are never explicitly gathered. They are discovered automatically during connectivity checks and don’t need to be specified in the candidate types list.

Server Requirements

NAT Traversal

Best case (Direct connection):
Good case (NAT traversal with STUN):
Fallback case (TURN relay):

Address Rewrite Rules

You can specify which candidate type to use for address rewriting:

Acceptance Timing

You can configure minimum wait times before accepting each candidate type:
This allows the agent to wait for potentially better candidates before settling on a relay connection.