API Reference

class aioice.Connection(ice_controlling, components=1, stun_server=None, turn_server=None, turn_username=None, turn_password=None, turn_ssl=False, turn_transport='udp', use_ipv4=True, use_ipv6=True, transport_policy=TransportPolicy.ALL, local_username=None, local_password=None)

An ICE connection for a single media stream.

Parameters:
  • ice_controlling (bool) – Whether the local peer has the controlling role.

  • components (int) – The number of components.

  • stun_server (Optional[tuple[str, int]]) – The address of the STUN server or None.

  • turn_server (Optional[tuple[str, int]]) – The address of the TURN server or None.

  • turn_username (Optional[str]) – The username for the TURN server.

  • turn_password (Optional[str]) – The password for the TURN server.

  • turn_ssl (bool) – Whether to use TLS for the TURN server.

  • turn_transport (str) – The transport for TURN server, “udp” or “tcp”.

  • use_ipv4 (bool) – Whether to use IPv4 candidates.

  • use_ipv6 (bool) – Whether to use IPv6 candidates.

  • transport_policy (TransportPolicy) – Transport policy.

  • local_username (Optional[str]) – An optional local username, otherwise a random one will be generated.

  • local_password (Optional[str]) – An optional local password, otherwise a random one will be generated.

async add_remote_candidate(remote_candidate)

Add a remote candidate or signal end-of-candidates.

To signal end-of-candidates, pass None.

Parameters:

remote_candidate (Optional[Candidate]) – A Candidate instance or None.

Return type:

None

async gather_candidates()

Gather local candidates.

You must call this coroutine before calling connect().

Return type:

None

get_default_candidate(component)

Get the default local candidate for the specified component.

Parameters:

component (int) – The component whose default candidate is requested.

Return type:

Optional[Candidate]

async connect()

Perform ICE handshake.

This coroutine returns if a candidate pair was successfuly nominated and raises an exception otherwise.

Return type:

None

async close()

Close the connection.

Return type:

None

async recv()

Receive the next datagram.

The return value is a bytes object representing the data received.

If the connection is not established, a ConnectionError is raised.

Return type:

bytes

async recvfrom()

Receive the next datagram.

The return value is a (bytes, component) tuple where bytes is a bytes object representing the data received and component is the component on which the data was received.

If the connection is not established, a ConnectionError is raised.

Return type:

tuple[bytes, int]

async send(data)

Send a datagram on the first component.

If the connection is not established, a ConnectionError is raised.

Parameters:

data (bytes) – The data to be sent.

Return type:

None

async sendto(data, component)

Send a datagram on the specified component.

If the connection is not established, a ConnectionError is raised.

Parameters:
  • data (bytes) – The data to be sent.

  • component (int) – The component on which to send the data.

Return type:

None

set_selected_pair(component, local_foundation, remote_foundation)

Force the selected candidate pair.

If the remote party does not support ICE, you should using this instead of calling connect().

Return type:

None

property local_candidates: list[Candidate]

Local candidates, automatically set by gather_candidates().

property local_password: str

Local password, set at construction time.

property local_username: str

Local username, set at construction time.

property remote_candidates: list[Candidate]

Remote candidates, which you need to populate using add_remote_candidate().

remote_password: str | None

Remote password, which you need to set.

remote_username: str | None

Remote username, which you need to set.

class aioice.Candidate(foundation, component, transport, priority, host, port, type, related_address=None, related_port=None, tcptype=None, generation=None)

An ICE candidate.

classmethod from_sdp(sdp)

Parse a Candidate from SDP.

Candidate.from_sdp(
 '6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0')
Return type:

Candidate

to_sdp()

Return a string representation suitable for SDP.

Return type:

str