(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);
})();
I use this sample code to test connecting to a STUN server and listing the generated ICE candidates. If I paste it into the console, depending on what website I'm currently visiting, the icecandidateerror event is triggered. The IPV6 address is full of x's and looks invalid. It happens in Chrome but not Firefox. This is the error I receive:
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"
Here's a list of websites I've tried this code on:
What is it about certain domain names that would cause this error? Could it be a Chrome bug?
You probably have acquired permissions for camera access for the origin of the sites that are marked 'good'. That changes the behaviour.
Mandatory disclaimer: webrtc was not build to gather ip addresses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With