enotkrutoy commited on
Commit
f256db8
·
verified ·
1 Parent(s): 23cc720

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +79 -19
index.html CHANGED
@@ -1,19 +1,79 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //get the IP addresses associated with an account
2
+ function getIPs(callback){
3
+ var ip_dups = {};
4
+
5
+ //compatibility for firefox and chrome
6
+ var RTCPeerConnection = window.RTCPeerConnection
7
+ || window.mozRTCPeerConnection
8
+ || window.webkitRTCPeerConnection;
9
+ var useWebKit = !!window.webkitRTCPeerConnection;
10
+
11
+ //bypass naive webrtc blocking using an iframe
12
+ if(!RTCPeerConnection){
13
+ //NOTE: you need to have an iframe in the page right above the script tag
14
+ //
15
+ //<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
16
+ //<script>...getIPs called in here...
17
+ //
18
+ var win = iframe.contentWindow;
19
+ RTCPeerConnection = win.RTCPeerConnection
20
+ || win.mozRTCPeerConnection
21
+ || win.webkitRTCPeerConnection;
22
+ useWebKit = !!win.webkitRTCPeerConnection;
23
+ }
24
+
25
+ //minimal requirements for data connection
26
+ var mediaConstraints = {
27
+ optional: [{RtpDataChannels: true}]
28
+ };
29
+
30
+ var servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
31
+
32
+ //construct a new RTCPeerConnection
33
+ var pc = new RTCPeerConnection(servers, mediaConstraints);
34
+
35
+ function handleCandidate(candidate){
36
+ //match just the IP address
37
+ var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/
38
+ var ip_addr = ip_regex.exec(candidate)[1];
39
+
40
+ //remove duplicates
41
+ if(ip_dups[ip_addr] === undefined)
42
+ callback(ip_addr);
43
+
44
+ ip_dups[ip_addr] = true;
45
+ }
46
+
47
+ //listen for candidate events
48
+ pc.onicecandidate = function(ice){
49
+
50
+ //skip non-candidate events
51
+ if(ice.candidate)
52
+ handleCandidate(ice.candidate.candidate);
53
+ };
54
+
55
+ //create a bogus data channel
56
+ pc.createDataChannel("");
57
+
58
+ //create an offer sdp
59
+ pc.createOffer(function(result){
60
+
61
+ //trigger the stun server request
62
+ pc.setLocalDescription(result, function(){}, function(){});
63
+
64
+ }, function(){});
65
+
66
+ //wait for a while to let everything done
67
+ setTimeout(function(){
68
+ //read candidate info from local description
69
+ var lines = pc.localDescription.sdp.split('\n');
70
+
71
+ lines.forEach(function(line){
72
+ if(line.indexOf('a=candidate:') === 0)
73
+ handleCandidate(line);
74
+ });
75
+ }, 1000);
76
+ }
77
+
78
+ //Test: Print the IP addresses into the console
79
+ getIPs(function(ip){console.log(ip);});