【发布时间】:2020-05-30 06:27:53
【问题描述】:
我正在尝试使用 WebRTC 查找客户端 IP 地址,但在 Firefox 中我收到此错误:
ICE 失败,您的 TURN 服务器似乎已损坏,有关详细信息,请参阅 about:webrtc
var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
var pc = new myPeerConnection({ iceServers: [
{ url: "turn:numb.viagenie.ca:3478", username: "my@gmail.com", "credential": "xxxxxx" },
{ urls: "stun:stun.l.google.com:19302" }
] }),
noop = function () { },
localIPs = {},
ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g,
key;
function ipIterate(ip) {
if (!localIPs[ip]) onNewIP(ip);
localIPs[ip] = true;
}
pc.createDataChannel("");
pc.createOffer(function (sdp) {
sdp.sdp.split('\n').forEach(function (line) {
if (line.indexOf('candidate') < 0) return;
line.match(ipRegex).forEach(ipIterate);
});
pc.setLocalDescription(sdp, noop, noop);
}, noop);
pc.onicecandidate = function (ice) {
if (!ice || !ice.candidate || !ice.candidate.candidate || !ice.candidate.candidate.match(ipRegex)) return;
ice.candidate.candidate.match(ipRegex).forEach(ipIterate);
};
登录about:webrtc:
ICE 中继日志
0.009 rtp 主机 3350409123 udp e6e7f092-e632-4986-97b2-90b20c3b15cd.local 59923 126 | 30 | 255 0.062 rtp srflx 842163049 udp IP 59923 100 | 30 | 255 0.313 rtp 中继 453802058 udp IP 57652 2 | 30 | 255 0.313 完成 0.315
【问题讨论】:
-
有人吗?似乎转弯服务器不是免费的.. 并且 Firefox 出于某种原因需要转弯服务器?
-
您可以尝试使用this website 检索您的 ICE 接力候选人吗?
-
是的,我将日志添加到主要问题中
-
奇怪的是..当我打开页面时我得到这个错误..但是当我从上一页点击返回到这个..所以回发工作正常
-
好的,你的 TURN 似乎工作了,因为浏览器检索了它的中继候选。请注意,您的公共 IP 存在,您可能希望将其从帖子中删除。只是一个细节,您应该在
url属性(第一个iceServers值)处添加一个“s”
标签: javascript html http firefox webrtc