# RTCIceTransport

The ICE transport of a connection, which can also be used on its own.

### *class* webrtc.interfaces.rtc_ice_transport.RTCIceTransport

The ICE transport a [`webrtc.RTCDtlsTransport`](rtc_dtls_transport.md#webrtc.interfaces.rtc_dtls_transport.RTCDtlsTransport) of a connection runs over, or a standalone one.

A standalone transport (`RTCIceTransport()`, from WebRTC Extensions) is driven by hand. Call [`gather()`](#webrtc.interfaces.rtc_ice_transport.RTCIceTransport.gather),
[`start()`](#webrtc.interfaces.rtc_ice_transport.RTCIceTransport.start) and [`add_remote_candidate()`](#webrtc.interfaces.rtc_ice_transport.RTCIceTransport.add_remote_candidate), then [`stop()`](#webrtc.interfaces.rtc_ice_transport.RTCIceTransport.stop) when done. Those methods raise for a
transport of a connection.

See [MDN: RTCIceTransport](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceTransport).

* **Events:**
  * **statechange** ([`webrtc.Event`](../models/events.md#webrtc.models.events.Event)) – [`state`](#webrtc.interfaces.rtc_ice_transport.RTCIceTransport.state) changed.
  * **gatheringstatechange** ([`webrtc.Event`](../models/events.md#webrtc.models.events.Event)) – [`gathering_state`](#webrtc.interfaces.rtc_ice_transport.RTCIceTransport.gathering_state) changed.
  * **selectedcandidatepairchange** ([`webrtc.Event`](../models/events.md#webrtc.models.events.Event)) – [`get_selected_candidate_pair()`](#webrtc.interfaces.rtc_ice_transport.RTCIceTransport.get_selected_candidate_pair) changed.
  * **icecandidate** ([`webrtc.RTCPeerConnectionIceEvent`](../models/events.md#webrtc.models.events.RTCPeerConnectionIceEvent)) – A standalone transport gathered a candidate,
    or [`None`](https://docs.python.org/3/builtins/constants.html#None) once it gathered them all.
  * **error** ([`webrtc.Event`](../models/events.md#webrtc.models.events.Event)) – A standalone transport failed. It never fires, because the native ICE
    agent doesn’t report it.

### Events

- `statechange`: [`Event`](../models/events.md#webrtc.models.events.Event)
- `gatheringstatechange`: [`Event`](../models/events.md#webrtc.models.events.Event)
- `selectedcandidatepairchange`: [`Event`](../models/events.md#webrtc.models.events.Event)
- `error`: [`Event`](../models/events.md#webrtc.models.events.Event)
- `icecandidate`: [`RTCPeerConnectionIceEvent`](../models/events.md#webrtc.models.events.RTCPeerConnectionIceEvent)

Handlers are registered with [`on()`](../events.md#webrtc.utils.events.UniformEventTarget.on).

#### gather(options=None)

Starts gathering the local candidates of a standalone transport, each sent in an `icecandidate` event.

* **Parameters:**
  **options** ([`webrtc.RTCIceGatherOptions`](../models/rtc_configuration.md#webrtc.models.rtc_configuration.RTCIceGatherOptions), optional) – The policy and the ICE servers to gather with.
* **Raises:**
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If it’s stopped, gathering already, or belongs to a connection.
  * [**webrtc.InvalidSyntaxError**](../exceptions.md#webrtc.exceptions.InvalidSyntaxError) – If an ICE server URL is invalid.
  * [**webrtc.InvalidAccessError**](../exceptions.md#webrtc.exceptions.InvalidAccessError) – If a TURN server has no credentials.
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If the policy isn’t a value of [`webrtc.RTCIceTransportPolicy`](../enums.md#webrtc.enums.RTCIceTransportPolicy).

#### start(remote_parameters=None, role='controlled')

Starts connectivity checks of a standalone transport with the remote agent.

Checks use the remote candidates added so far and any added later. Calling it again with other remote
parameters (an ICE restart of the remote agent) drops the remote candidates added before.

* **Parameters:**
  * **remote_parameters** ([`webrtc.RTCIceParameters`](../models/rtc_ice_candidate.md#webrtc.models.rtc_ice_candidate.RTCIceParameters), optional) – The username fragment and the password of
    the remote agent. Both are required, even though the argument has a default.
  * **role** ([`webrtc.RTCIceRole`](../enums.md#webrtc.enums.RTCIceRole), optional) – Controlling or controlled (the default). If both agents pick
    the same role, the conflict is resolved and one of them switches.
* **Raises:**
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If it’s stopped, started with another role, or belongs to a connection.
  * [**webrtc.InvalidSyntaxError**](../exceptions.md#webrtc.exceptions.InvalidSyntaxError) – If the username fragment or the password is invalid.
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If the role is neither controlling nor controlled.

#### add_remote_candidate(remote_candidate=None)

Adds a candidate of the remote agent to a standalone transport.

The object passed is the one [`get_remote_candidates()`](#webrtc.interfaces.rtc_ice_transport.RTCIceTransport.get_remote_candidates) returns for it.

* **Parameters:**
  **remote_candidate** ([`webrtc.RTCIceCandidate`](../models/rtc_ice_candidate.md#webrtc.models.rtc_ice_candidate.RTCIceCandidate) or [`webrtc.RTCIceCandidateInit`](../models/rtc_ice_candidate.md#webrtc.models.rtc_ice_candidate.RTCIceCandidateInit), optional) – The
  candidate, which needs `sdp_mid` or `sdp_m_line_index` to be set.
* **Raises:**
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If the candidate has neither `sdp_mid` nor `sdp_m_line_index`.
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If it’s stopped, or belongs to a connection.
  * [**webrtc.OperationError**](../exceptions.md#webrtc.exceptions.OperationError) – If the candidate can’t be parsed.

#### stop()

Stops a standalone transport for good.

Its [`state`](#webrtc.interfaces.rtc_ice_transport.RTCIceTransport.state) becomes `closed` without a `statechange` event.

* **Raises:**
  [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If it belongs to a connection.

#### get_selected_candidate_pair()

Returns the local and the remote candidate the transport sends and receives with.

A remote peer-reflexive candidate comes from connectivity checks. It has an empty `candidate` and no
address.

See [MDN: RTCIceTransport/getSelectedCandidatePair](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceTransport/getSelectedCandidatePair).

* **Returns:**
  [`webrtc.RTCIceCandidatePair`](../models/rtc_ice_candidate.md#webrtc.models.rtc_ice_candidate.RTCIceCandidatePair), optional – The pair, or [`None`](https://docs.python.org/3/builtins/constants.html#None) until one is selected.
* **Return type:**
  [*RTCIceCandidatePair*](../models/rtc_ice_candidate.md#webrtc.models.rtc_ice_candidate.RTCIceCandidatePair) | None

#### get_local_candidates()

Returns the local candidates gathered for the transport so far.

Each call returns the same objects. For a standalone transport, they’re the ones of its `icecandidate`
events.

See [MDN: RTCIceTransport/getLocalCandidates](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceTransport/getLocalCandidates).

* **Returns:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list) of [`webrtc.RTCIceCandidate`](../models/rtc_ice_candidate.md#webrtc.models.rtc_ice_candidate.RTCIceCandidate) – The candidates.
* **Return type:**
  [list](https://docs.python.org/3/builtins/stdtypes.html#list)[[*RTCIceCandidate*](../models/rtc_ice_candidate.md#webrtc.models.rtc_ice_candidate.RTCIceCandidate)]

#### get_remote_candidates()

Returns the candidates the remote peer signaled for the transport, without peer-reflexive ones.

They come from its description, [`webrtc.RTCPeerConnection.add_ice_candidate()`](rtc_peer_connection.md#webrtc.interfaces.rtc_peer_connection.RTCPeerConnection.add_ice_candidate) or
[`add_remote_candidate()`](#webrtc.interfaces.rtc_ice_transport.RTCIceTransport.add_remote_candidate).

See [MDN: RTCIceTransport/getRemoteCandidates](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceTransport/getRemoteCandidates).

* **Returns:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list) of [`webrtc.RTCIceCandidate`](../models/rtc_ice_candidate.md#webrtc.models.rtc_ice_candidate.RTCIceCandidate) – The candidates.
* **Return type:**
  [list](https://docs.python.org/3/builtins/stdtypes.html#list)[[*RTCIceCandidate*](../models/rtc_ice_candidate.md#webrtc.models.rtc_ice_candidate.RTCIceCandidate)]

#### get_local_parameters()

Returns the local username fragment and password of the transport, with `ice_lite` [`False`](https://docs.python.org/3/builtins/constants.html#False).

See [MDN: RTCIceTransport/getLocalParameters](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceTransport/getLocalParameters).

* **Returns:**
  [`webrtc.RTCIceParameters`](../models/rtc_ice_candidate.md#webrtc.models.rtc_ice_candidate.RTCIceParameters), optional – The parameters, or [`None`](https://docs.python.org/3/builtins/constants.html#None) without a local description.
* **Return type:**
  [*RTCIceParameters*](../models/rtc_ice_candidate.md#webrtc.models.rtc_ice_candidate.RTCIceParameters) | None

#### get_remote_parameters()

Returns the remote username fragment and password of the transport, with `ice_lite` unknown.

See [MDN: RTCIceTransport/getRemoteParameters](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceTransport/getRemoteParameters).

* **Returns:**
  [`webrtc.RTCIceParameters`](../models/rtc_ice_candidate.md#webrtc.models.rtc_ice_candidate.RTCIceParameters), optional – The parameters, or [`None`](https://docs.python.org/3/builtins/constants.html#None) without a remote description.
* **Return type:**
  [*RTCIceParameters*](../models/rtc_ice_candidate.md#webrtc.models.rtc_ice_candidate.RTCIceParameters) | None

#### *property* component *: [RTCIceComponent](../enums.md#webrtc.enums.RTCIceComponent)*

Whether the transport carries RTP or RTCP. It’s `rtp` when they’re muxed.

See [MDN: RTCIceTransport/component](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceTransport/component).

* **Type:**
  [`webrtc.RTCIceComponent`](../enums.md#webrtc.enums.RTCIceComponent)

#### *property* gathering_state *: [RTCIceGathererState](../enums.md#webrtc.enums.RTCIceGathererState)*

Whether local candidates are being gathered, or all were.

See [MDN: RTCIceTransport/gatheringState](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceTransport/gatheringState).

* **Type:**
  [`webrtc.RTCIceGathererState`](../enums.md#webrtc.enums.RTCIceGathererState)

#### *property* role *: [RTCIceRole](../enums.md#webrtc.enums.RTCIceRole) | [None](https://docs.python.org/3/builtins/constants.html#None)*

Whether this agent is the controlling one, which picks the pair.

[`None`](https://docs.python.org/3/builtins/constants.html#None) for a standalone transport not started yet.

See [MDN: RTCIceTransport/role](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceTransport/role).

* **Type:**
  [`webrtc.RTCIceRole`](../enums.md#webrtc.enums.RTCIceRole), optional

#### *property* state *: [RTCIceTransportState](../enums.md#webrtc.enums.RTCIceTransportState)*

Whether the transport is checking, connected, failed or closed.

See [MDN: RTCIceTransport/state](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceTransport/state).

* **Type:**
  [`webrtc.RTCIceTransportState`](../enums.md#webrtc.enums.RTCIceTransportState)
