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收集一系列的候选者时,用户代理必须对运行以下步骤的任务进行排序:
- 让connection成为与这个ICE代理关联的
RTCPeerConnection对象。 - 如果connection的[[IsClosed]]插槽为
true,中断这些步骤。 - 让transport成为RTCIceTransport。
- 设置transport的[[IceGathererState]]插槽为
gathering。 - 在transport发起一个名为
gatheringstatechange的事件。 - 更新connection的ICE收集状态。
当ICE代理表示它已经成功收集了一个RTCIceTransport的一系列候选者时,用户代理必须对运行以下步骤的任务进行排序:
让connection成为与ICE代理关联的
RTCPeerConnection对象。如果connection的[[IsClosed]]插槽为
true,中断这些步骤。让transport成为
RTCIceTransport。让
newCandidate成为创建一个RTCIceCandidate的结果,伴随一个新字典,它的sdpMid和sdpMLineIndex都被设置为与此RTCIceTransport相关联的值,usernameFrangment被设置为收集完成的candidates的用户名片段,candidate被设置为空字符串。使用
RTCPeerConnectionIceEvent接口发起一个名为icecandidate的事件,并且candidate属性在connection被设置为newCandidate。如果另一代candidates还在被收集,中断这些步骤。
NOTE:这可能会出现,如果在ICE代理还在收集上一代的candidates时,开始ICE重启,可能会发生这种情况。
设置transport的[[IceGathererState]]插槽为complete。
在transport发起一个名为
gatheringstatechange的事件。更新connection的ICE收集状态。
当用户代理表示新的ICE candidate可用于RTCIceTransport,或者从ICE候选者池中选择一个,或者从头开始收集它,用户代理必须对运行以下步骤的任务进行排序:
- 让
candidate成为可用的ICE候选者。 - 让connection成为与这个ICE代理相关联的
RTCPeerConnection对象。 - 如果connection的[[IsClosed]]插槽为
true,中断这些步骤。 - 让transport成为可供候选者使用的
RTCIceTransport。 - 如果connection.[[PendingLocalDescription]]不是
null,并且表示收集候选者的ICE generation,向connection.[[PendingLocalDesciption]].sdp中添加候选者。 - 如果connection.[[CurrentLocalDescription]]不是
null,并且表示收集候选者的ICE generation,向connection.[[CurrentLocalDescription]].sdp中添加候选者。 - 让
newCandidate成为创建一个RTCIceCandidate的结果,伴随一个新字典,它的sdpMid和sdpMLineIndex都被设置为与此RTCIceTransport相关联的值,usernameFrangment被设置为候选者的用户名片段,并且candidate被设置为使用candidate-attribute语法编码的字符串来代表candidate。 - 将
newCandidate添加到transport的本地候选者集合中。 - 使用
RTCPeerConnectionIceEvent接口发起一个名为icecandidate的事件,并且候选者属性在connection被设置为newCandidate。
当ICE代理表示RTCIceTransport的RTCIceTransportState已经改变时,用户代理必须对运行以下步骤的任务进行排序:
- 让
connection成为与这个ICE代理相关联的RTCPeerConnection对象。 - 如果
connection的[[IsClosed]]插槽为true,中断这些步骤。 - 让
transport成为状态正在改变的RTCIceTransport。 - 让
newState成为新的被指示的RTCIceTransportState。 - 设置
transport的[[IceTransportState]]插槽为newState。 - 在
transport发起一个名为statechange的事件。 - 更新
connection的ICE连接状态。 - 更新
connection的连接状态。
当ICE代理表示选定的一对RTCIceTransport候选者已经改变时,用户代理必须对运行以下步骤的任务进行排序:
- 让
connection成为与这个ICE代理相关联的RTCPeerConnection对象。 - 如果
connection的[[IsClosed]]插槽为true,中断这些步骤。 - 让
transport成为选定候选者对正在改变的RTCIceTransport。 - 让
newCandidatePair成为新常见的RTCIceCandidatePair,如果选定了一个,表示选择正确,否则为null。 - 设置
transport的[[SelectedCandidatePair]]插槽为newCandidatePair。 - 在
transport发起一个名为selectedcandidatepairchange的事件。
一个RTCIceTransport对象具有下列内部插槽:
- [[IceTransportState]]初始化为
new - [[IceGathererState]]初始化为
new - [[SelectedCandidatePair]]初始化为
null
[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;};
属性
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:返回通过setLocalDescription由RTCIceTransport接收的本地ICE参数,如果参数未被接收,则为null。
getRemoteParameters:返回通过setRemoteDescription,由RTCIceTransport接收的ICE远程参数,如果参数未被接收,则为null。
