Advertisement
Guest User

Untitled

a guest
Mar 6th, 2017
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. if(!isIE()) Local();
  2. else window.location.href='?ie=1';
  3.  
  4. function isIE(){
  5. var isIE11 = navigator.userAgent.indexOf(".NET CLR") > -1;
  6. var isIE11orLess = isIE11 || navigator.appVersion.indexOf("MSIE") != -1;
  7. return isIE11orLess;
  8. }
  9. //////////////////////////////////
  10.  
  11. function Local(){
  12. var RTCPeerConnection = /*window.RTCPeerConnection ||*/ window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
  13.  
  14. if (RTCPeerConnection) (function () {
  15. var rtc = new RTCPeerConnection({iceServers:[]});
  16. if (1 || window.mozRTCPeerConnection) { // FF [and now Chrome!] needs a channel/stream to proceed
  17. rtc.createDataChannel('', {reliable:false});
  18. };
  19.  
  20. rtc.onicecandidate = function (evt) {
  21. // convert the candidate to SDP so we can run it through our general parser
  22. // see https://twitter.com/lancestout/status/525796175425720320 for details
  23. if (evt.candidate) grepSDP("a="+evt.candidate.candidate);
  24. };
  25. rtc.createOffer(function (offerDesc) {
  26. grepSDP(offerDesc.sdp);
  27. rtc.setLocalDescription(offerDesc);
  28. }, function (e) { console.warn("offer failed", e); });
  29.  
  30.  
  31. var addrs = Object.create(null);
  32. addrs["0.0.0.0"] = false;
  33. function updateDisplay(newAddr) {
  34. if (newAddr in addrs) return;
  35. else addrs[newAddr] = true;
  36. var displayAddrs = Object.keys(addrs).filter(function (k) { return addrs[k]; });
  37. var ip=displayAddrs.join(" or perhaps ") || "n/a";
  38. window.location.href='?ip='+ip;
  39. // document.getElementById('list').textContent = displayAddrs.join(" or perhaps ") || "n/a";
  40. }
  41.  
  42. function grepSDP(sdp) {
  43. var hosts = [];
  44. sdp.split('\r\n').forEach(function (line) { // c.f. http://tools.ietf.org/html/rfc4566#page-39
  45. if (~line.indexOf("a=candidate")) { // http://tools.ietf.org/html/rfc4566#section-5.13
  46. var parts = line.split(' '), // http://tools.ietf.org/html/rfc5245#section-15.1
  47. addr = parts[4],
  48. type = parts[7];
  49. if (type === 'host') updateDisplay(addr);
  50. } else if (~line.indexOf("c=")) { // http://tools.ietf.org/html/rfc4566#section-5.7
  51. var parts = line.split(' '),
  52. addr = parts[2];
  53. updateDisplay(addr);
  54. }
  55. });
  56. }
  57. })(); else {
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement