gpt4 book ai didi

javascript - 为什么从某些网站发送 STUN 请求会失败?

转载 作者:行者123 更新时间:2023-12-03 07:09:55 26 4
gpt4 key购买 nike

(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://stackoverflow.com/ - 错误

  • 某些会导致此错误的域名是什么?会不会是 Chrome 的错误?

    最佳答案

    您可能已获得对标记为“良好”的网站来源的摄像头访问权限。这会改变行为。
    强制性免责声明:webrtc 不是为了收集 IP 地址而构建的。

    关于javascript - 为什么从某些网站发送 STUN 请求会失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64792854/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com