-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.html
101 lines (96 loc) · 3.28 KB
/
index.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>Sample App</title>
</head>
<body>
<div id='root'>
<h1>RTT to server</h1>
<h3>
Dsiplay the Round Trip Time from your computer to the VoIP server.
</h3>
<p>
Console version : <a href="./console.html">console.html</a>
</p>
<p>
Knowing the 'distance' in milliseconds from your computer to the VoIP
server you're attached to is very useful, especially if you're running
some WebRTC application.
</p>
<div>
<span>API key : </span>
<input id="apikeyTextId" type="text" placeholder="e.g. : 23dh4r56">
<input id="apikeyButtonId" type="button" value="Connect">
</div>
<div id="serverInfoId" style="display:none">
<h4>
Server hostname : fs-us-ny-1.apidaze.io
</h4>
<h4>
RTT : <span id="rttId">N/A</span> msec <span id="rttAppreciationId"></span>
</h4>
</div>
</div>
<h3>Console output</h3>
<div id="output"></div>
<script type="text/javascript" src="/dist/APIdaze-latest-dev.js"></script></body>
<script type="text/javascript" src="../logger.js"></script>
<script>
const apikeyButtonObj = document.getElementById("apikeyButtonId");
const apikeyTextObj = document.getElementById("apikeyTextId");
const serverInfoObj = document.getElementById("serverInfoId");
const rttObj = document.getElementById("rttId");
const rttAppreciationObj = document.getElementById("rttAppreciationId");
var APIdazeClientObj = null;
apikeyButtonObj.onclick = function() {
if (/^[a-zA-Z0-9]{8}$/.test(apikeyTextObj.value)) {
toggleInputs();
console.log("Connecting...");
APIdazeClientObj = new APIdaze.CLIENT({
apiKey: apikeyTextObj.value,
debug: true,
onReady: function() {
alert("Success !");
toggleInputs();
displayServerInfo();
getRTT();
},
onError: function(errorMessage){
alert("Got error : " + errorMessage);
toggleInputs();
displayServerInfo();
}
});
} else {
alert("Wrong API key");
}
}
var toggleInputs = function(){
console.log("Toggling inputs");
apikeyTextObj.disabled === true ? apikeyTextObj.disabled = false : apikeyTextObj.disabled = true;;
apikeyButtonObj.disabled === true ? apikeyButtonObj.disabled = false : apikeyButtonObj.disabled = true;;
}
var displayServerInfo = function(){
serverInfoObj.style.display = 'block';
}
var getRTT = function() {
rttInterval = setInterval(function() {
APIdazeClientObj.ping(function(rtt){
rttObj.innerHTML = rtt;
if (rtt <= 50) {
rttAppreciationObj.innerHTML = "(good)";
} else if (rtt <= 100) {
rttAppreciationObj.innerHTML = "(that's ok)";
} else if (rtt <= 150) {
rttAppreciationObj.innerHTML = "(not bad)";
} else if (rtt <= 200) {
rttAppreciationObj.innerHTML = "(not good)";
} else {
rttAppreciationObj.innerHTML = "(too high)";
}
});
}, 2000);
}
</script>
</html>