RTCPeerConnection.canTrickleIceCandidates

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

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

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

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

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

示例

js
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
WebRTC: Real-Time Communication in Browsers
# dom-rtcpeerconnection-cantrickleicecandidates

浏览器兼容性

BCD tables only load in the browser

参见