Skip to main content

Overview

The GatheringState enum describes the current state of the ICE candidate gathering process. It tracks whether the agent is discovering local network addresses and querying STUN/TURN servers.

Type Definition

States

GatheringStateNew

Candidate gathering has not yet started. The agent has been created but GatherCandidates() has not been called.

GatheringStateGathering

The agent is actively gathering candidates. This includes:
  • Discovering local network interfaces
  • Creating host candidates
  • Querying STUN servers for server reflexive candidates
  • Allocating TURN relays for relay candidates

GatheringStateComplete

Candidate gathering has completed. All local addresses have been discovered and all STUN/TURN queries have finished or timed out.

GatheringStateUnknown

Represents an unknown or uninitialized gathering state.

Methods

String

Returns the string representation of the gathering state. Returns:
  • "new" for GatheringStateNew
  • "gathering" for GatheringStateGathering
  • "complete" for GatheringStateComplete
  • Error string for unknown states

State Transitions

Transitions:
  1. New → Gathering: When GatherCandidates() is called
  2. Gathering → Complete: When all gathering operations finish
  3. Complete → Gathering: When using continual gathering and new interfaces appear

Usage Example

Continual Gathering

When continual gathering is enabled, the state can transition back from Complete to Gathering when new network interfaces are detected:

Gathering Timeout

You can configure how long to wait for STUN server responses:

Gathering Complete Signal

The agent signals gathering completion by calling the OnCandidate handler with a nil candidate:

Continual Gathering Policy

GatherOnce (Default)

Gathering completes after the initial phase and stops monitoring for new interfaces.

GatherContinually

The agent continuously monitors network interfaces and gathers new candidates when changes are detected.