// I wanted a bookmarklet to take me to the local instance of Plex running on my desktop, so Chromecast would function correctly // (if I used localhost it wouldn't send the correct uri) // For this I had to get the local ethernet interface IP // I initiate a connection to 0.0.0.0, then use the data on the connection object to get the interface IP used for that connection // May not work on the most popular web browser var path = prompt("Enter uri (e.g http://{}:32400/web)"); // var path = "http://{}:32400/web"; var RTCPeerConnection = window.webkitRTCPeerConnection || window.mozRTCPeerConnection; RTCPeerConnection && function() { function c(ip) { ip in b || (window.location.href = path.replace(/{}/g, ip)) } function d(a) { a.split("\r\n").forEach(function(a) { ~a.indexOf("a=candidate") ? "host" === a.split(" ")[7] && c(a.split(" ")[4]) : ~a.indexOf("c=") && c(a.split(" ")[2]) }) } var a = new RTCPeerConnection({ iceServers: [] }); a.createDataChannel("", { reliable: !1 }), a.onicecandidate = function(a) { a.candidate && d("a=" + a.candidate.candidate) }, a.createOffer(function(b) { d(b.sdp), a.setLocalDescription(b) }, function(a) { console.warn("offer failed", a) }); var b = Object.create(null); b["0.0.0.0"] = !1 }();