RTCPeerConnection.canTrickleIceCandidates

只读的 RTCPeerConnection 属性 canTrickleIceCandidates 返回一个Boolean,它指示远程对等端是否可以接受 trickled ICE candidates

ICE trickling是在初始发送或回应已经发送给其他设备之后继续发送候选的过程。

仅在调用RTCPeerConnection.setRemoteDescription()之后才设置此属性。 理想情况下,您的信令协议提供了一种检测滴流支持的方法,因此您无需依赖此属性。 WebRTC浏览器将始终支持
trickle ICE 如果不支持滴流,或者您无法辨别,则可以检查此属性的伪值,然后等待iceGatheringState的值更改在创建和发送之前“完成”。
这样,发送信息包含所有候选。

语法

 var canTrickle = RTCPeerConnection.canTrickleIceCandidates;

Boolean 如果远程对等体可以接受滴入的ICE candidate,则为true;如果不能,则为false。 如果尚未建立远程对等方,则此值为null。

Note: 一旦本地对等方调用RTCPeerConnection.setRemoteDescription(),就确定该属性的值; ICE代理使用所提供的描述来确定远程对等体是否支持滴入的ICE candidates

用例

var pc = new RTCPeerConnection();
// The following code might be used to handle an offer from a peer when
// it isn't known whether it supports trickle ICE.
pc.setRemoteDescription(remoteOffer)
  .then(_ => pc.createAnswer())
  .then(answer => pc.setLocalDescription(answer))
  .then(_ =>     
    if (pc.canTrickleIceCandidates) {
      return pc.localDescription;
    }
    return new Promise(r => {
      pc.addEventListener('icegatheringstatechange', e => {
        if (e.target.iceGatheringState === 'complete') {
          r(pc.localDescription);
        }
      });
    });
  })
  .then(answer => sendAnswerToPeer(answer)) // signaling message
  .catch(e => handleError(e));

pc.addEventListener('icecandidate', e => {
  if (pc.canTrickleIceCandidates) {
    sendCandidateToPeer(e.candidate); // signaling message
  }
});

规范

Specification Status Comment
WebRTC 1.0: Real-time Communication Between Browsers
RTCPeerConnection.canTrickleIceCandidates
Candidate Recommendation Initial specification.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
canTrickleIceCandidatesChrome No support NoEdge Full support 15Firefox Full support 47IE No support NoOpera No support NoSafari ? WebView Android No support NoChrome Android No support NoFirefox Android Full support 44Opera Android No support NoSafari iOS ? Samsung Internet Android Full support 6.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

相关阅读