mirror of
https://github.com/SrIzan10/What-Is-My-IP-Address.git
synced 2026-05-01 11:06:57 +00:00
WebRTC Problem!
there was a small bug inside my code & thx a lot @RedSQL for helping me out :)
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
<body>
|
||||
<noscript>
|
||||
<h2>hmm, i guess you disabled JS so please enable it to see the magic! :)</h2>
|
||||
<p>ــــــــــــــــــــــ</p>
|
||||
<p>ــــــــــــــــــــــ</p>
|
||||
</noscript>
|
||||
<div id="IP">
|
||||
<h2>Your Public IP Is: </h2>
|
||||
@@ -55,7 +57,7 @@
|
||||
</div>
|
||||
<p>ــــــــــــــــــــــ</p>
|
||||
<div id="SPEEDTEST">
|
||||
<h2>Your Net's Speed Is: <br> <a id="speedtest"></a></h2>
|
||||
<h2>Your Net Speed Is: <br> <a id="speedtest"></a></h2>
|
||||
</div>
|
||||
<script src="main.js"></script>
|
||||
</body>
|
||||
|
||||
36
main.js
36
main.js
@@ -1,18 +1,28 @@
|
||||
// Find my ip code
|
||||
var RTCPeerConnection = window.RTCPeerConnection || webkitRTCPeerConnection || mozRTCPeerConnection;
|
||||
var peerConn = new RTCPeerConnection({
|
||||
'iceServers': [{
|
||||
'urls': ['stun:stun.l.google.com:19302']
|
||||
}]
|
||||
// Since when webrtc is disabled, webkitRTCPeerConnection is nonexistent, therefore we try and catch and define RTCPeerConnection with no value because webrtc is disabled.
|
||||
try {
|
||||
var RTCPeerConnection = window.RTCPeerConnection || webkitRTCPeerConnection || mozRTCPeerConnection;
|
||||
} catch {
|
||||
var RTCPeerConnection;
|
||||
}
|
||||
if (RTCPeerConnection) {
|
||||
var peerConn = new RTCPeerConnection({
|
||||
'iceServers': [{
|
||||
'urls': ['stun:stun.l.google.com:19302']
|
||||
}]
|
||||
|
||||
});
|
||||
var dataChannel = peerConn.createDataChannel('test'); // Needs something added for some reason
|
||||
peerConn.createOffer({}).then((desc) => peerConn.setLocalDescription(desc));
|
||||
peerConn.onicecandidate = (e) => {
|
||||
if (e.candidate == null) {
|
||||
document.getElementById("ip").innerText = /c=IN IP4 ([^\n]*)\n/.exec(peerConn.localDescription.sdp)[1];
|
||||
}
|
||||
};
|
||||
});
|
||||
var dataChannel = peerConn.createDataChannel('test'); // Needs something added for some reason
|
||||
peerConn.createOffer({}).then((desc) => peerConn.setLocalDescription(desc));
|
||||
peerConn.onicecandidate = (e) => {
|
||||
if (e.candidate == null) {
|
||||
document.getElementById("ip").innerText = /c=IN IP4 ([^\n]*)\n/.exec(peerConn.localDescription.sdp)[1];
|
||||
}
|
||||
};
|
||||
} else {
|
||||
// Inform user that webrtc fetch failed
|
||||
document.getElementById("ip").innerText = 'Failed to fetch IP via WebRTC, perhaps your WebRTC is disabled?';
|
||||
}
|
||||
// ـــــــــــــــــــــــــــــــــــ
|
||||
|
||||
// Location
|
||||
|
||||
Reference in New Issue
Block a user