5.6 RTCIceTransport接口

RTCIceTransport接口允许应用程序获取有关用来发送接收数据包的ICE传输的信息。特别的,ICE管理对等连接,它牵涉到应用程序可能获取的状态。由于需要调用setLocalDescription()setRemoteDescription(),RTCIceTransport对象被创建。底层ICE状态由ICE代理管理,所以当ICE代理向用户代理提供指示时,RTCIceTransport的状态就会改变。每个RTCIceTransport对象代表一个特定RTCRtpTransceiver的RTP或RTCP组件的ICE传输层,或者是一组已经通过[BUNDLE]协商的RTCRtpTransceiver

NOTE:现存RTCRtpTranceiver的ICE重启将会由现存RTCIceTransport对象表示,它的状态将会被对应更新,而不是由新对象表示。

当ICE代理表示它将为一个RTCIceTransport收集一系列的候选者时,用户代理必须对运行以下步骤的任务进行排序:

  1. 让connection成为与这个ICE代理关联的RTCPeerConnection对象。
  2. 如果connection的[[IsClosed]]插槽为true,中断这些步骤。
  3. 让transport成为RTCIceTransport。
  4. 设置transport的[[IceGathererState]]插槽为gathering
  5. 在transport发起一个名为gatheringstatechange的事件。
  6. 更新connection的ICE收集状态。

当ICE代理表示它已经成功收集了一个RTCIceTransport的一系列候选者时,用户代理必须对运行以下步骤的任务进行排序:

  1. 让connection成为与ICE代理关联的RTCPeerConnection对象。

  2. 如果connection的[[IsClosed]]插槽为true,中断这些步骤。

  3. 让transport成为RTCIceTransport

  4. newCandidate成为创建一个RTCIceCandidate的结果,伴随一个新字典,它的sdpMidsdpMLineIndex都被设置为与此RTCIceTransport相关联的值,usernameFrangment被设置为收集完成的candidates的用户名片段,candidate被设置为空字符串。

  5. 使用RTCPeerConnectionIceEvent接口发起一个名为icecandidate的事件,并且candidate属性在connection被设置为newCandidate

  6. 如果另一代candidates还在被收集,中断这些步骤。

    NOTE:这可能会出现,如果在ICE代理还在收集上一代的candidates时,开始ICE重启,可能会发生这种情况。

  7. 设置transport的[[IceGathererState]]插槽为complete。

  8. 在transport发起一个名为gatheringstatechange的事件。

  9. 更新connection的ICE收集状态。

当用户代理表示新的ICE candidate可用于RTCIceTransport,或者从ICE候选者池中选择一个,或者从头开始收集它,用户代理必须对运行以下步骤的任务进行排序:

  1. candidate成为可用的ICE候选者。
  2. 让connection成为与这个ICE代理相关联的RTCPeerConnection对象。
  3. 如果connection的[[IsClosed]]插槽为true,中断这些步骤。
  4. 让transport成为可供候选者使用的RTCIceTransport
  5. 如果connection.[[PendingLocalDescription]]不是null,并且表示收集候选者的ICE generation,向connection.[[PendingLocalDesciption]].sdp中添加候选者。
  6. 如果connection.[[CurrentLocalDescription]]不是null,并且表示收集候选者的ICE generation,向connection.[[CurrentLocalDescription]].sdp中添加候选者。
  7. newCandidate成为创建一个RTCIceCandidate的结果,伴随一个新字典,它的sdpMidsdpMLineIndex都被设置为与此RTCIceTransport相关联的值,usernameFrangment被设置为候选者的用户名片段,并且candidate被设置为使用candidate-attribute语法编码的字符串来代表candidate
  8. newCandidate添加到transport的本地候选者集合中。
  9. 使用RTCPeerConnectionIceEvent接口发起一个名为icecandidate的事件,并且候选者属性在connection被设置为newCandidate

当ICE代理表示RTCIceTransportRTCIceTransportState已经改变时,用户代理必须对运行以下步骤的任务进行排序:

  1. connection成为与这个ICE代理相关联的RTCPeerConnection对象。
  2. 如果connection的[[IsClosed]]插槽为true,中断这些步骤。
  3. transport成为状态正在改变的RTCIceTransport
  4. newState成为新的被指示的RTCIceTransportState
  5. 设置transport的[[IceTransportState]]插槽为newState
  6. transport发起一个名为statechange的事件。
  7. 更新connection的ICE连接状态。
  8. 更新connection的连接状态。

当ICE代理表示选定的一对RTCIceTransport候选者已经改变时,用户代理必须对运行以下步骤的任务进行排序:

  1. connection成为与这个ICE代理相关联的RTCPeerConnection对象。
  2. 如果connection的[[IsClosed]]插槽为true,中断这些步骤。
  3. transport成为选定候选者对正在改变的RTCIceTransport
  4. newCandidatePair成为新常见的RTCIceCandidatePair,如果选定了一个,表示选择正确,否则为null。
  5. 设置transport的[[SelectedCandidatePair]]插槽为newCandidatePair
  6. transport发起一个名为selectedcandidatepairchange的事件。

一个RTCIceTransport对象具有下列内部插槽:

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

属性

RTCIceRole类型的role,只读:role属性必须返回transport的ICE role。

RTCIceComponent类型的component,只读:component属性必须返回transport的ICE组件。当RTCP mux被使用时,单一的RTCIceTransport同时传输RTP和RTCP,并且component被设置为RTP

RTCIceTransportState类型的state,只读:当需要获得state属性时,它必须返回[[IceTransportState]]插槽的值。

RTCIceGathererState类型的gatheringState,只读:当获取gathering state属性时,它必须返回[[IceGathererState]]插槽的值。

EventHandler类型的onstatechange:此event handler,当RTCIceTransportstate类型改变时,必须启动。

EventHandler类型的ongatheringstatechange:此event handler,当RTCIceTransportgatheringstate改变时,必须启动。

EventHandler类型的onselectedcandidatepairchange:此event handler,当RTCIceTransport选定的候选者对改变时,必须启动。

方法

getLocalCandidates:返回一个序列,描述为RTCIceTransport收集并在onicecandidate中发送的本地候选者。

getRemoteCandidates:返回一个序列,描述通过addIceCandidate(),由RTCIceTransport接收的ICE候选者。

NOTE:getRemoteCandidates不会暴露peer reflexive candidates,因为它们不是通过addIceCandidate()接收的。

getSelectedCandidatePair:返回用来发送数据包的选定候选者对。此方法必须返回[[SelectedCandidatePair]]插槽的值。

getLocalParameters:返回通过setLocalDescriptionRTCIceTransport接收的本地ICE参数,如果参数未被接收,则为null

getRemoteParameters:返回通过setRemoteDescription,由RTCIceTransport接收的ICE远程参数,如果参数未被接收,则为null