RTCIceTransport 方法 getSelectedCandidatePair() 返回 RTCIceCandidatePair object containing the current best-choice pair of ICE candidates describing the configuration of the endpoints of the transport.

句法

candidatePair = RTCIceTransport.getSelectedCandidatePair();
					

参数

None.

返回值

A RTCIceCandidatePair object describing the configurations of the currently-selected candidate pair's two endpoints. local describes the configuration of the local end of the connection, while remote describes the remote peer's configuration.

返回值为 null if no pair of candidates has been selected yet.

用法注意事项

As the ICE agent performs negotiation of a RTCPeerConnection , it gathers and analyzes candidate configurations from each the two peers. As soon as it finds an acceptable matching pair of candidates, meeting the requirements for the connection, a selectedcandidatepairchange event is fired at the RTCIceTransport . From that time forward, the best matching pair of candidates will always be available by calling getSelectedCandidatePair() .

As ICE negotiation continues, any time a pair of candidates is discovered that is better than the currently-selected pair, the new pair is selected, replacing the previous pairing, and the selectedcandidatepairchange event is fired again.

注意: It's possible for one of the configurations in the selected candidate pair to remain unchanged when a new pairing is chosen.

范例

In this example, an event handler for selectedcandidatepairchange is set up to update an on-screen display showing the protocol used by the currently selected candidate pair.

var iceTransport = pc.getSenders()[0].transport.iceTransport;
var localProto = document.getElementById("local-protocol");
var remoteProto = document.getElementById("remote-protocol");
iceTransport.onselectedcandidatepairchange = function(event) {
  var pair = iceTransport.getSelectedCandidatePair();
  localProtocol.innerText = pair.local.protocol.toUpperCase();
  remoteProtocol.innerText = pair.remote.protocol.toUpperCase();
}
					

规范

规范 状态 注释
WebRTC 1.0: Real-time Communication Between Browsers
The definition of 'RTCIceTransport.getSelectedCandidatePair()' in that specification.
候选推荐 最初的规范。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
getSelectedCandidatePair Chrome No Edge 15 — 79 Alternate Name
不支持 15 — 79 Alternate Name
Alternate Name Uses the non-standard name: getNominatedCandidatePair
Firefox No IE No Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No

图例

不支持

不支持

使用非标名称。

元数据

  • 最后修改: