forked from steveseguin/vdo.ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
icetest.html
59 lines (53 loc) · 1.49 KB
/
icetest.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<html>
<head>
<style>
* {font-size:6vw;}
</style>
</head>
<body>
<script>
const stunServers = [
'stun:stun.l.google.com:19302',
'stun:stun1.l.google.com:19302',
'stun:stun.cloudflare.com:3478',
];
async function checkConnectionModes() {
let hostMode = false;
let srflxMode = false;
for (const stunServer of stunServers) {
try {
const iceConfig = { iceServers: [{ urls: stunServer }] };
const rtcPeerConnection = new RTCPeerConnection(iceConfig);
rtcPeerConnection.createDataChannel(''); // Create a dummy data channel
const offer = await rtcPeerConnection.createOffer();
rtcPeerConnection.onicecandidate = (event) => {
if (event.candidate) {
// Check the ICE candidate type
if (event.candidate.candidate.includes('srflx')) {
if (!srflxMode){
srflxMode= true;
document.body.innerHTML += ('SRFLX');
document.body.innerHTML += ('<br />');
}
} else if (event.candidate.candidate.includes('host')) {
if (!hostMode){
hostMode = true;
document.body.innerHTML += ('Host');
document.body.innerHTML += ('<br />');
}
}
} else {
// All candidates have been gathered
rtcPeerConnection.onicecandidate = null; // Remove the event handler
}
};
rtcPeerConnection.setLocalDescription(offer);
} catch (error) {
srflxMode = true;
}
}
}
checkConnectionModes()
</script>
</body>
</html>