5.6 RTCIceTransport Interface

The RTCIceTransport interface allows an application access to information about the ICE transport over which packets are sent and received. In particular, ICE manages peer-to-peer connections which involve state which the application may want to access. RTCIceTransport objects are constructed as a result of calls to setLocalDescription() and setRemoteDescription(). The underlying ICE state is managed by the ICE agent; as such, the state of an RTCIceTransport changes when the ICE Agent provides indications to the user agent as described below. Each RTCIceTransport object represents the ICE transport layer for the RTP or RTCP component of a specific RTCRtpTransceiver, or a group of RTCRtpTransceivers if such a group has been negotiated via [RFC8843].

Note

An ICE restart for an existing RTCRtpTransceiver will be represented by an existing RTCIceTransport object, whose state will be updated accordingly, as opposed to being represented by a new object.

When the ICE Agent indicates that it began gathering a generation of candidates for an RTCIceTransport, the user agent MUST queue a task that runs the following steps:

  1. Let connection be the RTCPeerConnection object associated with this ICE Agent.

  2. If connection.[[IsClosed]] is true, abort these steps.

  3. Let transport be the RTCIceTransport for which candidate gathering began.

  4. Set transport.[[IceGathererState]] to gathering.

  5. Fire an event named gatheringstatechange at transport.

  6. Update the ICE gathering state of connection.

When the ICE Agent is finished gathering a generation of candidates for an RTCIceTransport, and those candidates have been surfaced to the application, the user agent MUST queue a task that runs the following steps:

  1. Let connection be the RTCPeerConnection object associated with this ICE Agent.

  2. If connection.[[IsClosed]] is true, abort these steps.

  3. Let transport be the RTCIceTransport for which candidate gathering finished.

  4. Let newCandidate be the result of creating an RTCIceCandidate with a new dictionary whose sdpMid and sdpMLineIndex are set to the values associated with this RTCIceTransport, usernameFragment is set to the username fragment of the generation of candidates for which gathering finished, and candidate is set to an empty string.

  5. Fire an event named icecandidate using the RTCPeerConnectionIceEvent interface with the candidate attribute set to newCandidate at connection.

  6. If another generation of candidates is still being gathered, abort these steps.

    Note

    This may occur if an ICE restart is initiated while the ICE agent is still gathering the previous generation of candidates.

  7. Set transport.[[IceGathererState]] to complete.

  8. Fire an event named gatheringstatechange at transport.

  9. Update the ICE gathering state of connection.

When the ICE Agent indicates that a new ICE candidate is available for an RTCIceTransport, either by taking one from the ICE candidate pool or gathering it from scratch, the user agent MUST queue a task that runs the following steps:

  1. Let candidate be the available ICE candidate.

  2. Let connection be the RTCPeerConnection object associated with this ICE Agent.

  3. If connection.[[IsClosed]] is true, abort these steps.

  4. If either connection.[[PendingLocalDescription]] or connection.[[CurrentLocalDescription]] are not null, and represent the ICE generation for which candidate was gathered, surface the candidate with candidate and connection, and abort these steps.

  5. Otherwise, append candidate to connection.[[EarlyCandidates]].

When the ICE Agent signals that the ICE role has changed due to an ICE binding request with a role collision per [RFC8445] section 7.3.1.1, the UA will queue a task to set the value of [[IceRole]] to the new value.

To release early candidates of a connection, run the following steps:

  1. For each candidate, candidate, in connection.[[EarlyCandidates]], queue a task to surface the candidate with candidate and connection.

  2. Set connection.[[EarlyCandidates]] to an empty list.

To surface a candidate with candidate and connection, run the following steps:

  1. If connection.[[IsClosed]] is true, abort these steps.

  2. Let transport be the RTCIceTransport for which candidate is being made available.

  3. If connection.[[PendingLocalDescription]] is not null, and represents the ICE generation for which candidate was gathered, add candidate to connection.[[PendingLocalDescription]].sdp.

  4. If connection.[[CurrentLocalDescription]] is not null, and represents the ICE generation for which candidate was gathered, add candidate to connection.[[CurrentLocalDescription]].sdp.

  5. Let newCandidate be the result of creating an RTCIceCandidate with a new dictionary whose sdpMid and sdpMLineIndex are set to the values associated with this RTCIceTransport, usernameFragment is set to the username fragment of the candidate, and candidate is set to a string encoded using the candidate-attribute grammar to represent candidate.

  6. Add newCandidate to transport’s set of local candidates.

  7. Fire an event named icecandidate using the RTCPeerConnectionIceEvent interface with the candidate attribute set to newCandidate at connection.

The RTCIceTransportState of an RTCIceTransport may change because a candidate pair with a usable connection was found and selected or it may change without the selected candidate pair changing. The selected pair and RTCIceTransportState are related and are handled in the same task.

When the ICE Agent indicates that an RTCIceTransport has changed either the selected candidate pair, the RTCIceTransportState or both, the user agent MUST queue a task that runs the following steps:

  1. Let connection be the RTCPeerConnection object associated with this ICE Agent.

  2. If connection.[[IsClosed]] is true, abort these steps.

  3. Let transport be the RTCIceTransport whose state is changing.

  4. Let selectedCandidatePairChanged be false.

  5. Let transportIceConnectionStateChanged be false.

  6. Let connectionIceConnectionStateChanged be false.

  7. Let connectionStateChanged be false.

  8. If transport’s selected candidate pair was changed, run the following steps:

    1. Let newCandidatePair be a newly created RTCIceCandidatePair representing the indicated pair if one is selected, and null otherwise.

    2. Set transport.[[SelectedCandidatePair]] to newCandidatePair.

    3. Set selectedCandidatePairChanged to true.

  9. If transport’s RTCIceTransportState was changed, run the following steps:

    1. Set transport.[[IceTransportState]] to the new indicated RTCIceTransportState.

    2. Set transportIceConnectionStateChanged to true.

    3. Set connection’s ICE connection state to the value of deriving a new state value as described by the RTCIceConnectionState enum.

    4. If the ice connection state changed in the previous step, set connectionIceConnectionStateChanged to true.

    5. Set connection’s connection state to the value of deriving a new state value as described by the RTCPeerConnectionState enum.

    6. If the connection state changed in the previous step, set connectionStateChanged to true.

  10. If selectedCandidatePairChanged is true, fire an event named selectedcandidatepairchange at transport.

  11. If transportIceConnectionStateChanged is true, fire an event named statechange at transport.

  12. If connectionIceConnectionStateChanged is true, fire an event named iceconnectionstatechange at connection.

  13. If connectionStateChanged is true, fire an event named connectionstatechange at connection.

An RTCIceTransport object has the following internal slots:

  • [[IceTransportState]] initialized to “new
  • [[IceGathererState]] initialized to “new
  • [[SelectedCandidatePair]] initialized to null
  • [[IceRole]] initialized to “unknown
  1. WebIDL[Exposed=Window]
  2. interface RTCIceTransport : EventTarget {
  3. readonly attribute RTCIceRole role;
  4. readonly attribute RTCIceComponent component;
  5. readonly attribute RTCIceTransportState state;
  6. readonly attribute RTCIceGathererState gatheringState;
  7. sequence<RTCIceCandidate> getLocalCandidates();
  8. sequence<RTCIceCandidate> getRemoteCandidates();
  9. RTCIceCandidatePair? getSelectedCandidatePair();
  10. RTCIceParameters? getLocalParameters();
  11. RTCIceParameters? getRemoteParameters();
  12. attribute EventHandler onstatechange;
  13. attribute EventHandler ongatheringstatechange;
  14. attribute EventHandler onselectedcandidatepairchange;
  15. };

Attributes

role of type RTCIceRole, readonly

The role attribute MUST, on getting, return the value of the [[IceRole]] internal slot.

component of type RTCIceComponent, readonly

The component attribute MUST return the ICE component of the transport. When RTCP mux is used, a single RTCIceTransport transports both RTP and RTCP and component is set to “rtp“.

state of type RTCIceTransportState, readonly

The state attribute MUST, on getting, return the value of the [[IceTransportState]] slot.

gatheringState of type RTCIceGathererState, readonly

The gatheringState attribute MUST, on getting, return the value of the [[IceGathererState]] slot.

onstatechange of type EventHandler

This event handler, of event handler event type statechange, MUST be fired any time the RTCIceTransport state changes.

ongatheringstatechange of type EventHandler

This event handler, of event handler event type gatheringstatechange, MUST be fired any time the RTCIceTransport ICE gathering state changes.

onselectedcandidatepairchange of type EventHandler

This event handler, of event handler event type selectedcandidatepairchange, MUST be fired any time the RTCIceTransport‘s selected candidate pair changes.

Methods

getLocalCandidates

Returns a sequence describing the local ICE candidates gathered for this RTCIceTransport and sent in onicecandidate.

getRemoteCandidates

Returns a sequence describing the remote ICE candidates received by this RTCIceTransport via addIceCandidate().

Note

getRemoteCandidates will not expose peer reflexive candidates since they are not received via addIceCandidate().

getSelectedCandidatePair

Returns the selected candidate pair on which packets are sent. This method MUST return the value of the [[SelectedCandidatePair]] slot. When RTCIceTransport.state is “new“ or “closedgetSelectedCandidatePair returns null.

getLocalParameters

Returns the local ICE parameters received by this RTCIceTransport via setLocalDescription, or null if the parameters have not yet been received.

getRemoteParameters

Returns the remote ICE parameters received by this RTCIceTransport via setRemoteDescription or null if the parameters have not yet been received.

5.6.1 RTCIceParameters Dictionary

  1. WebIDLdictionary RTCIceParameters {
  2. DOMString usernameFragment;
  3. DOMString password;
  4. };
Dictionary RTCIceParameters Members

usernameFragment of type DOMString

The ICE username fragment as defined in [RFC5245], Section 7.1.2.3.

password of type DOMString

The ICE password as defined in [RFC5245], Section 7.1.2.3.

5.6.2 RTCIceCandidatePair Dictionary

  1. WebIDLdictionary RTCIceCandidatePair {
  2. RTCIceCandidate local;
  3. RTCIceCandidate remote;
  4. };
Dictionary RTCIceCandidatePair Members

local of type RTCIceCandidate

The local ICE candidate.

remote of type RTCIceCandidate

The remote ICE candidate.

5.6.3 RTCIceGathererState Enum

  1. WebIDLenum RTCIceGathererState {
  2. "new",
  3. "gathering",
  4. "complete"
  5. };
RTCIceGathererState Enumeration description
newThe RTCIceTransport was just created, and has not started gathering candidates yet.
gatheringThe RTCIceTransport is in the process of gathering candidates.
completeThe RTCIceTransport has completed gathering and the end-of-candidates indication for this transport has been sent. It will not gather candidates again until an ICE restart causes it to restart.

5.6.4 RTCIceTransportState Enum

  1. WebIDLenum RTCIceTransportState {
  2. "new",
  3. "checking",
  4. "connected",
  5. "completed",
  6. "disconnected",
  7. "failed",
  8. "closed"
  9. };
RTCIceTransportState Enumeration description
newThe RTCIceTransport is gathering candidates and/or waiting for remote candidates to be supplied, and has not yet started checking.
checkingThe RTCIceTransport has received at least one remote candidate and is checking candidate pairs and has either not yet found a connection or consent checks [RFC7675] have failed on all previously successful candidate pairs. In addition to checking, it may also still be gathering.
connectedThe RTCIceTransport has found a usable connection, but is still checking other candidate pairs to see if there is a better connection. It may also still be gathering and/or waiting for additional remote candidates. If consent checks [RFC7675] fail on the connection in use, and there are no other successful candidate pairs available, then the state transitions to “checking“ (if there are candidate pairs remaining to be checked) or “disconnected“ (if there are no candidate pairs to check, but the peer is still gathering and/or waiting for additional remote candidates).
completedThe RTCIceTransport has finished gathering, received an indication that there are no more remote candidates, finished checking all candidate pairs and found a connection. If consent checks [RFC7675] subsequently fail on all successful candidate pairs, the state transitions to “failed“.
disconnectedThe ICE Agent has determined that connectivity is currently lost for this RTCIceTransport. This is a transient state that may trigger intermittently (and resolve itself without action) on a flaky network. The way this state is determined is implementation dependent. Examples include:
  • Losing the network interface for the connection in use.
  • Repeatedly failing to receive a response to STUN requests.
Alternatively, the RTCIceTransport has finished checking all existing candidates pairs and not found a connection (or consent checks [RFC7675] once successful, have now failed), but it is still gathering and/or waiting for additional remote candidates.
failedThe RTCIceTransport has finished gathering, received an indication that there are no more remote candidates, finished checking all candidate pairs, and all pairs have either failed connectivity checks or have lost consent. This is a terminal state until ICE is restarted. Since an ICE restart may cause connectivity to resume, entering the “failed“ state does not cause DTLS transports, SCTP associations or the data channels that run over them to close, or tracks to mute.
closedThe RTCIceTransport has shut down and is no longer responding to STUN requests.

Note

The most common transitions for a successful call will be new -> checking -> connected -> completed, but under specific circumstances (only the last checked candidate succeeds, and gathering and the no-more candidates indication both occur prior to success), the state can transition directly from “checking“ to “completed“.

An ICE restart causes candidate gathering and connectivity checks to begin anew, causing a transition to “connected“ if begun in the “completed“ state. If begun in the transient “disconnected“ state, it causes a transition to “checking“, effectively forgetting that connectivity was previously lost.

The “failed“ and “completed“ states require an indication that there are no additional remote candidates. This can be indicated by calling addIceCandidate with a candidate value whose candidate property is set to an empty string or by canTrickleIceCandidates being set to false.

Some example state transitions are:

ICE transport state transition diagram

Figure 2 Non-normative ICE transport state transition diagram

5.6.5 RTCIceRole Enum

  1. WebIDLenum RTCIceRole {
  2. "unknown",
  3. "controlling",
  4. "controlled"
  5. };
RTCIceRole Enumeration description
unknownAn agent whose role as defined by [RFC5245], Section 3, has not yet been determined.
controllingA controlling agent as defined by [RFC5245], Section 3.
controlledA controlled agent as defined by [RFC5245], Section 3.

5.6.6 RTCIceComponent Enum

  1. WebIDLenum RTCIceComponent {
  2. "rtp",
  3. "rtcp"
  4. };
RTCIceComponent Enumeration description
rtpThe ICE Transport is used for RTP (or RTCP multiplexing), as defined in [RFC5245], Section 4.1.1.1. Protocols multiplexed with RTP (e.g. data channel) share its component ID. This represents the component-id value 1 when encoded in candidate-attribute.
rtcpThe ICE Transport is used for RTCP as defined by [RFC5245], Section 4.1.1.1. This represents the component-id value 2 when encoded in candidate-attribute.