为什么从某些网站发送 STUN 请求会失败?
Why do STUN requests fail when sent from certain websites?
(async function()
{
var iceServers = [{ urls: ["stun:stun.l.google.com:19302"] }];
var peer = new RTCPeerConnection({ iceServers });
peer.channel = peer.createDataChannel("channel");
peer.onicecandidate = function(e)
{
if(e.candidate)
console.log(JSON.stringify(e.candidate, null, '\t'));
else
console.log("DONE");
};
peer.onicecandidateerror = (e) => console.error(e);
var offer = await peer.createOffer();
await peer.setLocalDescription(offer);
})();
我使用此示例代码来测试连接到 STUN 服务器并列出生成的 ICE 候选者。如果我将它粘贴到控制台中,根据我当前访问的网站,将触发 icecandidateerror
事件。 IPV6 地址全是 x,看起来无效。它发生在 Chrome 但不是 Firefox。这是我收到的错误:
RTCPeerConnectionIceErrorEvent
address: "[0:0:0:x:x:x:x:x]"
bubbles: false
cancelBubble: false
cancelable: false
composed: false
currentTarget: RTCPeerConnection {…}
defaultPrevented: false
errorCode: 701
errorText: "STUN host lookup received error."
eventPhase: 0
hostCandidate: "[0:0:0:x:x:x:x:x]:33860"
isTrusted: true
path: []
port: 33860
returnValue: true
srcElement: RTCPeerConnection {…}
target: RTCPeerConnection {…}
timeStamp: 2621.4149999996152
type: "icecandidateerror"
url: "stun:stun.l.google.com:19302"
以下是我试过此代码的网站列表:
- https://webrtc.github.io/samples/ - 好
- https://webrtc.github.io/definitelya404page/ - 好
- https://luisfonsivevo.github.io/samples/ - 错误(这是上述 repo 的一个分支,使用相同的 GitHub 页面 HTTP 服务器)
- https://google.com/ - 错误
- https://codepen.io/ - 好
- https://whosebug.com/ - 错误
某些域名会导致此错误的原因是什么?会不会是 Chrome 错误?
您可能已经获得了对标记为 'good' 的网站来源的摄像头访问权限。这改变了行为。
强制免责声明:webrtc 不是为了收集 ip 地址而构建的。
(async function()
{
var iceServers = [{ urls: ["stun:stun.l.google.com:19302"] }];
var peer = new RTCPeerConnection({ iceServers });
peer.channel = peer.createDataChannel("channel");
peer.onicecandidate = function(e)
{
if(e.candidate)
console.log(JSON.stringify(e.candidate, null, '\t'));
else
console.log("DONE");
};
peer.onicecandidateerror = (e) => console.error(e);
var offer = await peer.createOffer();
await peer.setLocalDescription(offer);
})();
我使用此示例代码来测试连接到 STUN 服务器并列出生成的 ICE 候选者。如果我将它粘贴到控制台中,根据我当前访问的网站,将触发 icecandidateerror
事件。 IPV6 地址全是 x,看起来无效。它发生在 Chrome 但不是 Firefox。这是我收到的错误:
RTCPeerConnectionIceErrorEvent
address: "[0:0:0:x:x:x:x:x]"
bubbles: false
cancelBubble: false
cancelable: false
composed: false
currentTarget: RTCPeerConnection {…}
defaultPrevented: false
errorCode: 701
errorText: "STUN host lookup received error."
eventPhase: 0
hostCandidate: "[0:0:0:x:x:x:x:x]:33860"
isTrusted: true
path: []
port: 33860
returnValue: true
srcElement: RTCPeerConnection {…}
target: RTCPeerConnection {…}
timeStamp: 2621.4149999996152
type: "icecandidateerror"
url: "stun:stun.l.google.com:19302"
以下是我试过此代码的网站列表:
- https://webrtc.github.io/samples/ - 好
- https://webrtc.github.io/definitelya404page/ - 好
- https://luisfonsivevo.github.io/samples/ - 错误(这是上述 repo 的一个分支,使用相同的 GitHub 页面 HTTP 服务器)
- https://google.com/ - 错误
- https://codepen.io/ - 好
- https://whosebug.com/ - 错误
某些域名会导致此错误的原因是什么?会不会是 Chrome 错误?
您可能已经获得了对标记为 'good' 的网站来源的摄像头访问权限。这改变了行为。
强制免责声明:webrtc 不是为了收集 ip 地址而构建的。