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

esbemjvw  于 2023-05-11  发布在  Go
关注(0)|答案(1)|浏览(169)

为了支持任意客户端的ICE涓流,建议信令机制也支持涓流支持的信令。我的就是这样对等体可以在初始信令握手中包括其是否支持涓流的标志,因此远程对等体可以决定涓流。
我遇到的问题是,我不知道如何检测 * 当前浏览器 * 是否支持ICE滴注,因此它可以正确设置该标志。我试着用这个作为一种检测机制:

typeof RTCPeerConnection.prototype.addIceCandidate == 'function'

这是可靠的,最好的,或者有一个更好的API或方法来查询 * 本地 * 支持ICE滴?

hjqgdpho

hjqgdpho1#

所有现代WebRTC端点 * 必须 * 支持Trickle ICE。
JSEP第5.2.1节说:
必须添加带有“trickle”选项的“a=ice-options”行,如第4节[I-D.ietf-ice-trickle]中所述。
此外,从我对WebRTC规范的阅读来看,浏览器要符合规范,它必须实现addIceCandidate等。
目前所有支持WebRTC的浏览器都支持trickling。下面的代码在Firefox中返回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 peer是否支持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");

相关问题