检测本地浏览器是否支持ICE trickle

Detect whether local browser supports ICE trickle

为了支持任意客户端的 ICE-trickling,建议信令机制也支持 trickle 支持的信令。我的就是这样做的;一个对等点可以在初始信号握手中包含一个标志,它是否支持滴流,因此远程对等点可以决定滴流。

我遇到的问题是我不确定如何检测当前浏览器是否支持 ICE-trickling,以便它可以正确设置该标志。我尝试将其用作检测机制:

typeof RTCPeerConnection.prototype.addIceCandidate == 'function'

这是否可靠且最好,或者是否有更好的API 或方法来查询 local 对 ICE 滴流的支持?

所有现代 WebRTC 端点必须支持 Trickle ICE。

JSEP section 5.2.1 说:

An "a=ice-options" line with the "trickle" option MUST be added, as specified in [I-D.ietf-ice-trickle], Section 4.

此外,根据我对 WebRTC 规范的阅读,浏览器 conformant, it must implement addIceCandidate

目前所有支持 WebRTC 的浏览器都支持 trickling。 Firefox 中的以下 returns true(Chrome 似乎没有正确发出信号,但请放心,它支持 trickling):

new RTCPeerConnection().createOffer({offerToReceiveAudio: true})
.then(offer => console.log(offer.sdp.includes('\r\na=ice-options:trickle')))
.catch(e => log(e));

有趣的是,有一个 pc.canTrickleIceCandidates 属性可以用来检测 remote 对等点是否支持 trickling,大概是为了支持连接到遗留系统。以下在 Firefox 中生成 true(Chrome 中的 undefined,需要赶上规范):

var pc1 = new RTCPeerConnection(), pc2 = new RTCPeerConnection();

pc1.onicecandidate = e => pc2.addIceCandidate(e.candidate);
pc2.onicecandidate = e => pc1.addIceCandidate(e.candidate);

pc1.onnegotiationneeded = e =>
  pc1.createOffer().then(d => pc1.setLocalDescription(d))
  .then(() => pc2.setRemoteDescription(pc1.localDescription))
  .then(() => pc2.createAnswer()).then(d => pc2.setLocalDescription(d))
  .then(() => pc1.setRemoteDescription(pc2.localDescription))
  .then(() => console.log(pc1.canTrickleIceCandidates))
  .catch(e => console.log(e));

pc1.createDataChannel("dummy");