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 RTCRtpTransceiver
s 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:
Let connection be the
RTCPeerConnection
object associated with this ICE Agent.If connection.[[IsClosed]] is
true
, abort these steps.Let transport be the
RTCIceTransport
for which candidate gathering began.Set transport.[[IceGathererState]] to
gathering
.Fire an event named
gatheringstatechange
at transport.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:
Let connection be the
RTCPeerConnection
object associated with this ICE Agent.If connection.[[IsClosed]] is
true
, abort these steps.Let transport be the
RTCIceTransport
for which candidate gathering finished.Let newCandidate be the result of creating an RTCIceCandidate with a new dictionary whose
sdpMid
andsdpMLineIndex
are set to the values associated with thisRTCIceTransport
,usernameFragment
is set to the username fragment of the generation of candidates for which gathering finished, andcandidate
is set to an empty string.Fire an event named
icecandidate
using theRTCPeerConnectionIceEvent
interface with the candidate attribute set to newCandidate at connection.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.
Set transport.[[IceGathererState]] to
complete
.Fire an event named
gatheringstatechange
at transport.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:
Let candidate be the available ICE candidate.
Let connection be the
RTCPeerConnection
object associated with this ICE Agent.If connection.[[IsClosed]] is
true
, abort these steps.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.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:
For each candidate, candidate, in connection.[[EarlyCandidates]], queue a task to surface the candidate with candidate and connection.
Set connection.[[EarlyCandidates]] to an empty list.
To surface a candidate with candidate and connection, run the following steps:
If connection.[[IsClosed]] is
true
, abort these steps.Let transport be the
RTCIceTransport
for which candidate is being made available.If connection.[[PendingLocalDescription]] is not
null
, and represents the ICE generation for which candidate was gathered, add candidate to connection.[[PendingLocalDescription]].sdp.If connection.[[CurrentLocalDescription]] is not
null
, and represents the ICE generation for which candidate was gathered, add candidate to connection.[[CurrentLocalDescription]].sdp.Let newCandidate be the result of creating an RTCIceCandidate with a new dictionary whose
sdpMid
andsdpMLineIndex
are set to the values associated with thisRTCIceTransport
,usernameFragment
is set to the username fragment of the candidate, andcandidate
is set to a string encoded using thecandidate-attribute
grammar to represent candidate.Add newCandidate to transport’s set of local candidates.
Fire an event named
icecandidate
using theRTCPeerConnectionIceEvent
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:
Let connection be the
RTCPeerConnection
object associated with this ICE Agent.If connection.[[IsClosed]] is
true
, abort these steps.Let transport be the
RTCIceTransport
whose state is changing.Let selectedCandidatePairChanged be
false
.Let transportIceConnectionStateChanged be
false
.Let connectionIceConnectionStateChanged be
false
.Let connectionStateChanged be
false
.If transport’s selected candidate pair was changed, run the following steps:
Let newCandidatePair be a newly created
RTCIceCandidatePair
representing the indicated pair if one is selected, andnull
otherwise.Set transport.[[SelectedCandidatePair]] to newCandidatePair.
Set selectedCandidatePairChanged to
true
.
If transport’s
RTCIceTransportState
was changed, run the following steps:Set transport.[[IceTransportState]] to the new indicated
RTCIceTransportState
.Set transportIceConnectionStateChanged to
true
.Set connection’s ICE connection state to the value of deriving a new state value as described by the
RTCIceConnectionState
enum.If the ice connection state changed in the previous step, set connectionIceConnectionStateChanged to
true
.Set connection’s connection state to the value of deriving a new state value as described by the
RTCPeerConnectionState
enum.If the connection state changed in the previous step, set connectionStateChanged to
true
.
If selectedCandidatePairChanged is
true
, fire an event namedselectedcandidatepairchange
at transport.If transportIceConnectionStateChanged is
true
, fire an event namedstatechange
at transport.If connectionIceConnectionStateChanged is
true
, fire an event namediceconnectionstatechange
at connection.If connectionStateChanged is
true
, fire an event namedconnectionstatechange
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
“
- WebIDL[Exposed=Window]
- interface
RTCIceTransport
: EventTarget {- readonly attribute
RTCIceRole
role
;- readonly attribute
RTCIceComponent
component
;- readonly attribute
RTCIceTransportState
state
;- readonly attribute
RTCIceGathererState
gatheringState
;- sequence<
RTCIceCandidate
>getLocalCandidates
();- sequence<
RTCIceCandidate
>getRemoteCandidates
();RTCIceCandidatePair
?getSelectedCandidatePair
();RTCIceParameters
?getLocalParameters
();RTCIceParameters
?getRemoteParameters
();- attribute EventHandler
onstatechange
;- attribute EventHandler
ongatheringstatechange
;- attribute EventHandler
onselectedcandidatepairchange
;- };
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 “closed
“ getSelectedCandidatePair
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
- WebIDLdictionary
RTCIceParameters
{- DOMString
usernameFragment
;- DOMString
password
;- };
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
- WebIDLdictionary
RTCIceCandidatePair
{RTCIceCandidate
local
;RTCIceCandidate
remote
;- };
Dictionary RTCIceCandidatePair
Members
local
of type RTCIceCandidate
The local ICE candidate.
remote
of type RTCIceCandidate
The remote ICE candidate.
5.6.3 RTCIceGathererState
Enum
- WebIDLenum
RTCIceGathererState
{- "
new
",- "
gathering
",- "
complete
"- };
Enumeration description | |
---|---|
new | The was just created, and has not started gathering candidates yet. |
gathering | The is in the process of gathering candidates. |
complete | The 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
- WebIDLenum
RTCIceTransportState
{- "
new
",- "
checking
",- "
connected
",- "
completed
",- "
disconnected
",- "
failed
",- "
closed
"- };
Enumeration description | |
---|---|
new | The is gathering candidates and/or waiting for remote candidates to be supplied, and has not yet started checking. |
checking | The 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. |
connected | The 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 “ “ (if there are candidate pairs remaining to be checked) or “ “ (if there are no candidate pairs to check, but the peer is still gathering and/or waiting for additional remote candidates). |
completed | The 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 “ “. |
disconnected | The ICE Agent has determined that connectivity is currently lost for this . 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:
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. |
failed | The 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 “ “ state does not cause DTLS transports, SCTP associations or the data channels that run over them to close, or tracks to mute. |
closed | The 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:
- (
RTCIceTransport
first created, as a result ofsetLocalDescription
orsetRemoteDescription
): “new
“ - (“
new
“, remote candidates received): “checking
“ - (“
checking
“, found usable connection): “connected
“ - (“
checking
“, checks fail but gathering still in progress): “disconnected
“ - (“
checking
“, gave up): “failed
“ - (“
disconnected
“, new local candidates): “checking
“ - (“
connected
“, finished all checks): “completed
“ - (“
completed
“, lost connectivity): “disconnected
“ - (“
disconnected
“ or “failed
“, ICE restart occurs): “checking
“ - (“
completed
“, ICE restart occurs): “connected
“ RTCPeerConnection
.close
()
: “closed
“
Figure 2 Non-normative ICE transport state transition diagram
5.6.5 RTCIceRole
Enum
- WebIDLenum
RTCIceRole
{- "
unknown
",- "
controlling
",- "
controlled
"- };
Enumeration description | |
---|---|
unknown | An agent whose role as defined by [RFC5245], Section 3, has not yet been determined. |
controlling | A controlling agent as defined by [RFC5245], Section 3. |
controlled | A controlled agent as defined by [RFC5245], Section 3. |
5.6.6 RTCIceComponent
Enum
- WebIDLenum
RTCIceComponent
{- "
rtp
",- "
rtcp
"- };
Enumeration description | |
---|---|
rtp | The 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 . |
rtcp | The 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 . |