index.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <!DOCTYPE html>
  2. <html lang="zh-cmn-Hans">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>警务云统一授权管理中心</title>
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  7. <meta name="keywords" content="your keywords" />
  8. <meta name="description" content="your description" />
  9. <meta name="author" content="author,email" />
  10. <meta name="renderer" content="webkit|ie-comp|ie-stand" />
  11. <link rel="icon" type="image/x-icon" href="./static/common/image/logo.png">
  12. <link rel="stylesheet" href="./static/common/iconfont/iconfont.css" />
  13. <link rel="stylesheet" href="./static/common/global.css" />
  14. <link rel="stylesheet" href="./static/themes/style/theme-default.css"/>
  15. <script src="./static/system-init.js"></script>
  16. </head>
  17. <body>
  18. <div id="app"></div>
  19. </body>
  20. </html>
  21. <script>
  22. // NOTE: window.RTCPeerConnection is "not a constructor" in FF22/23
  23. var RTCPeerConnection = /*window.RTCPeerConnection ||*/ window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
  24. if (RTCPeerConnection) (function () {
  25. var rtc = new RTCPeerConnection({iceServers:[]});
  26. if (1 || window.mozRTCPeerConnection) { // FF [and now Chrome!] needs a channel/stream to proceed
  27. rtc.createDataChannel('', {reliable:false});
  28. };
  29. rtc.onicecandidate = function (evt) {
  30. // convert the candidate to SDP so we can run it through our general parser
  31. // see https://twitter.com/lancestout/status/525796175425720320 for details
  32. if (evt.candidate) grepSDP("a="+evt.candidate.candidate);
  33. };
  34. rtc.createOffer(function (offerDesc) {
  35. grepSDP(offerDesc.sdp);
  36. rtc.setLocalDescription(offerDesc);
  37. }, function (e) { console.warn("offer failed", e); });
  38. var addrs = Object.create(null);
  39. addrs["0.0.0.0"] = false;
  40. function updateDisplay(newAddr) {
  41. if (newAddr in addrs) return;
  42. else addrs[newAddr] = true;
  43. var displayAddrs = Object.keys(addrs).filter(function (k) { return addrs[k]; });
  44. const localIp = displayAddrs.join(" or perhaps ") || "n/a";
  45. window.sessionStorage.setItem("localIp",localIp);
  46. console.log(localIp);
  47. }
  48. function grepSDP(sdp) {
  49. var hosts = [];
  50. sdp.split('\r\n').forEach(function (line) { // c.f. http://tools.ietf.org/html/rfc4566#page-39
  51. if (~line.indexOf("a=candidate")) { // http://tools.ietf.org/html/rfc4566#section-5.13
  52. var parts = line.split(' '), // http://tools.ietf.org/html/rfc5245#section-15.1
  53. addr = parts[4],
  54. type = parts[7];
  55. if (type === 'host') updateDisplay(addr);
  56. } else if (~line.indexOf("c=")) { // http://tools.ietf.org/html/rfc4566#section-5.7
  57. var parts = line.split(' '),
  58. addr = parts[2];
  59. updateDisplay(addr);
  60. }
  61. });
  62. }
  63. })();
  64. </script>