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)¶
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.
- async add_remote_candidate(remote_candidate)¶
Add a remote candidate or signal end-of-candidates.
To signal end-of-candidates, pass 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()
.
- local_password¶
Local password, automatically set to a random value.
- local_username¶
Local username, automatically set to a random value.
- property remote_candidates: List[Candidate]¶
Remote candidates, which you need to populate using
add_remote_candidate()
.
- remote_password: Optional[str]¶
Remote password, which you need to set.
- remote_username: Optional[str]¶
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')
- to_sdp()¶
Return a string representation suitable for SDP.
- Return type
str