Created
August 2, 2024 18:54
-
-
Save arafathusayn/884f6f23689400852ad3a111b672d104 to your computer and use it in GitHub Desktop.
Revisions
-
arafathusayn created this gist
Aug 2, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,87 @@ <!DOCTYPE html> <html> <head> <title>Test Stun/Turn Servers</title> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> </head> <body> <h1>Test Ice Servers</h1> <hr /> <pre id="ice" style="overflow: auto"></pre> <hr /> <p id="ip"></p> <p id="stun">π΄ The STUN server is NOT reachable!</p> <p id="turn">π΄ The TURN server is NOT reachable!</p> <p id="err"></p> <hr /> <script> const Ice = document.getElementById("ice"); const IP = document.getElementById("ip"); const Stun = document.getElementById("stun"); const Turn = document.getElementById("turn"); const Err = document.getElementById("err"); const iceServers = [ // { // urls: "turn:0.0.0.0:3478", // username: "", // credential: "", // }, ]; // Print iceServers config Ice.innerHTML = JSON.stringify(iceServers, null, 4); // Test the connections const pc = new RTCPeerConnection({ iceServers, }); pc.onicecandidate = (e) => { if (!e.candidate) return; console.log(e.candidate.candidate); // If a srflx candidate was found, notify that the STUN server works! if ( e.candidate.type == "srflx" || e.candidate.candidate.includes("srflx") ) { let ip = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/; let address = e.candidate.address ? e.candidate.address : e.candidate.candidate.match(ip); IP.innerHTML = "π’ Your Public IP Address is " + address; Stun.innerHTML = "π’ The STUN server is reachable!"; } // If a relay candidate was found, notify that the TURN server works! if ( e.candidate.type == "relay" || e.candidate.candidate.includes("relay") ) { Turn.innerHTML = "π’ The TURN server is reachable!"; } }; // handle error pc.onicecandidateerror = (e) => { console.error(e); Err.innerHTML = "π΄ Error: " + e.errorText; }; pc.createDataChannel("test"); pc.createOffer().then((offer) => pc.setLocalDescription(offer)); </script> </body> </html>