Skip to main content

Overview

The ConnectionState enum represents the state of an ICE connection as defined in RFC 5245. The agent transitions through these states as it establishes and maintains a peer-to-peer connection.

Type Definition

States

ConnectionStateNew

The ICE agent is gathering local candidates and has not started connectivity checks.

ConnectionStateChecking

The agent has local and remote candidates and is attempting to find a working pair through connectivity checks.

ConnectionStateConnected

The agent has found a working candidate pair, but may still be checking other pairs for better connectivity.

ConnectionStateCompleted

The agent has finished all connectivity checks and selected the best candidate pair.
In practice, most implementations transition directly from Connected to other states without using Completed.

ConnectionStateFailed

The agent could not establish a connection. All candidate pairs failed connectivity checks or timed out.

ConnectionStateDisconnected

The agent was previously connected but has lost connectivity. This is typically triggered after the disconnected timeout expires without receiving packets.

ConnectionStateClosed

The agent has been closed and is no longer processing requests.

ConnectionStateUnknown

Represents an unknown or uninitialized state.

Methods

String

Returns the string representation of the connection state. Returns:
  • "New" for ConnectionStateNew
  • "Checking" for ConnectionStateChecking
  • "Connected" for ConnectionStateConnected
  • "Completed" for ConnectionStateCompleted
  • "Failed" for ConnectionStateFailed
  • "Disconnected" for ConnectionStateDisconnected
  • "Closed" for ConnectionStateClosed
  • "Invalid" for unknown states

State Transitions

Common Transitions:
  1. New → Checking: When remote credentials are set and connectivity checks begin
  2. Checking → Connected: When a candidate pair succeeds
  3. Connected → Disconnected: When no packets received within DisconnectedTimeout
  4. Disconnected → Connected: When connectivity is restored
  5. Disconnected → Failed: When disconnected for longer than FailedTimeout
  6. Checking → Failed: When all pairs fail or checking times out
  7. Any → Closed: When Close() or GracefulClose() is called

Usage Example

Timeout Configuration

You can configure state transition timeouts:
Default Values:
  • DisconnectedTimeout: 5 seconds
  • FailedTimeout: 25 seconds (after disconnected)
Setting a timeout to 0 disables that state transition.