-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
312 lines (289 loc) · 9.18 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta content="Vardhan Varma <vardhanvarma@gmail.com>" name="author">
<meta content="Web browsing speed measurement using HTML5 technolgies" name="description">
<meta content="broadband,internet,browsing,speed,test,check,cloud,server,bandwidth" name="keywords">
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<title>True Bandwidth Speed Tester</title>
<style type="text/css">
h1 {
color: darkgreen ;
background-color : lightyellow;
text-align: center;
}
#map {
text-align: center;
border: 5px solid red;
height:300px;
width:400px ;
};
</style>
<!--
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script src="https://raw.github.com/mapstraction/mxn/master/source/mxn.js?(openlayers)" type="text/javascript"></script>
-->
<script src="http://js.local/OpenLayers/OpenLayers.js"></script>
<script src="http://js.local/mxn/mxn.js?(openlayers)" type="text/javascript"></script>
<script type="text/javascript" >
/* all the data about all the servers.
* TODO: make it possible to get this from server at run time
*
*/
var server_list = {};
// For now ... keep index as integers and 0..n .. will be fixed later
server_list[0] = { id : "d0.net"
, type : "server"
, name : "d0.net : original trueSpeed server"
, ip_addr : "d0.net"
, url_dl : "http://d0.net/test_data/5MB.zip"
, url_ul : "http://d0.net/test_data/dev_null"
, latitude : 123.03
, longitude : -12.35
, sponsor : "D0.net Testing"
, sponsor_link : "http://www.gnu.org"
, sponsor_icon : "http://foo.bar/favicon.png"
, max_dl : "100 Mbps"
, max_ul : "16 Kbps"
};
server_list[1] = { id : "d1.net"
, type : "server"
, name : "d1.net : D1 "
, ip_addr : "s1.d1.net"
, url_dl : "http://s1.d1.net/5MB.zip"
, url_ul : "http://s1.d2.net/test_data/dev_null"
, latitude : 23.03
, longitude : 47.35
, sponsor : "D1.net "
, sponsor_link : "http://www.fsf.org"
, sponsor_icon : "http://foo.bar/favicon.png"
, max_dl : "100 Mbps"
, max_ul : "16 Kbps"
};
server_list[2] = { id : "d2.net"
, type : "server"
, name : "d2.net : D2 "
, ip_addr : "s1.d2.net"
, url_dl : "http://s1.d2.net/5MB.zip"
, url_ul : "http://s1.d2.net/test_data/dev_null"
, latitude : -23.03
, longitude : 56.35
, sponsor : "D2.net "
, sponsor_link : "http://www.fsf.org"
, sponsor_icon : "http://foo.bar/favicon.png"
, max_dl : "100 Mbps"
, max_ul : "16 Kbps"
};
var
// The mapstraction map
map
// The marker ofclient on the map
, client_marker
// the latlong poing of cliet
, client_point
// the div for selected server information
, info
// the div for result
, result
// Captures the result for all the servers
// The bandwidth used by each server every granularity..
, ResultCapture = function ( ) {
var
// me is this
me = {}
// granularity in ms
, granularity = 1
// A hack here .. Assuming index are integers .. see server_list creation
, lists = []
, start = null
, last = null
;
// arr[from] to arr[to] are set t o val,
// grown as needed, filled with zero as needed
me.fill = function ( arr, from, to, val) {
me.upd( arr, from, 0);
me.upd( arr, to,val);
}
me.upd = function( arr, to, val) {
while ( arr.length < to )
arr.push(val);
}
me.begin = function( id, tnow) {
lists[id] = [];
if ( start == null ) { start = tnow; }
last = tnow;
}
me.update = function( id, tnow, snow, tprev, sprev ) {
var idx1 = ( tprev - start ) / granularity;
var idx2 = ( tnow - start ) / granularity;
var val = ( snow - sprev ) / ( tnow - tprev );
me.fill( lists[id], idx1, idx2, val);
//console.log(" For: %s : %s -- %s -- %s:%s : %s\n",
//id, lists[id].length, idx1, idx2, snow, sprev);
last = tnow;
}
me.finish = function( id) {
}
me.update_result = function () {
if ( start ) {
var str = "";
var count = lists.length;
var idx1 = ( last - start ) / granularity;
var total = [];
for( var i = 0 ; i < idx1 ; ++i ) {
var total = 0;
for ( var j = 0 ; j < count ; j ++ )
if ( lists[j].length > i )
total += lists[j][i];
if ( total < 1000 ) {
total = total.toFixed(0) + " Bps";
} else if ( total < 1000000 ) {
total = total / 1000;
total = total.toFixed(0) + " KBps";
} else {
total = total / 1000000;
total = total.toFixed(0) + " MBps";
}
//str += " , " + total;
str = total;
}
result.innerHTML = str;
}
}
window.setInterval( me.update_result, 100);
return me;
}
// And the Object ...
, result_capture = new ResultCapture()
//the state machine object, created by iterating over server_list
, StateMachine = function ( server_id ) {
var
// me is this of this (-:
me = {},
// key of server_list hash
id = server_id,
// value of server_list hash for id
server = server_list[server_id],
// state .. created/ready/downloading/uploading/done
state = "created",
// XHR object .. freed when done.
xhr = null,
// latlong point of server
server_point = null,
// marker for this server on the map
server_marker = null
// to update results ...
, tprev, sprev
;
// Async send
me.send = function ( ev, data ) {
var fn = "got_" + ev + "_at_" + state;
if ( me.hasOwnProperty(fn) ) {
setTimeout( function () { me[fn](data); },0);
}
}
// Sync send
me.have = function ( ev, data ) {
var fn = "got_" + ev + "_at_" + state;
if ( me.hasOwnProperty(fn) ) {
me[fn](data);
}
}
me.xhr_changed = function () {
var tnow = new Date();
tnow = tnow.getTime();
var snow = 0;
switch ( xhr.readyState ) {
case 0 :
break;
case 1:
result_capture.begin(id,tnow);
break;
case 2:
result_capture.begin(id,tnow);
break;
case 3:
snow = xhr.responseText? xhr.responseText.length : 0;
result_capture.update(id, tnow, snow,tprev, sprev);
break;
case 4:
snow = xhr.responseText? xhr.responseText.length : 0;
result_capture.update(id, tnow, snow, tprev, sprev);
result_capture.finish(id);
break;
}
tprev = tnow;
sprev = snow;
}
me.got_start_at_created = function ( data ) {
server_point = new mxn.LatLonPoint(server.longitude,server.latitude);
server_marker = new mxn.Marker( server_point);
map.addMarker(server_marker);
//var pts = [ client_point, server.point];
//server.line = new mxn.Polyline( pts);
//map.addPolyline(server.line);
xhr = new XMLHttpRequest();
xhr.open('GET',server.url_dl + "?randomize="+ new Date(), true);
// Adding this causes pre-flight .. hence delayed..
//xhr.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2005 00:00:00 GMT");
xhr.overrideMimeType('text/plain; charset=x-user-defined');
//xhr.responseType = 'arraybuffer';
xhr.onreadystatechange = me.xhr_changed;
xhr.send();
}
return me;
}
, mark_client_location = function (pos) {
client_point = new mxn.LatLonPoint(pos.coords.latitude, pos.coords.longitude);
client_marker = new mxn.Marker( client_point);
map.addMarker(client_marker);
//map.setCenter(latlon);
//map.autoCenterAndZoom();
}
, initiate_client_check = function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(mark_client_location);
}
}
, create_map = function () {
map = new mxn.Mapstraction('map', 'openlayers');
// Get the full world in view
map.centerAndZoomOnPoints( [ new mxn.LatLonPoint(70,-170),
new mxn.LatLonPoint(-45,170) ] );
}
// update the info
, update_info = function () {
info.innerHTML = "Loading ...";
}
// update the result .. this needs improvement
, update_result = function() {
result.innerHTML = "Loading ...";
}
// create statemachines and rev them up
, initiate_server_check = function () {
for ( var server in server_list ) {
var s = new StateMachine(server);
//server_list[server]["fsm"] = s;
s.send("start",0);
}
}
// starting place ...
, onload = function() {
info = document.getElementById("info");
result = document.getElementById("result");
create_map();
update_info();
update_result();
initiate_server_check();
initiate_client_check();
}
;
</script>
</head>
<body onload="onload();">
<h1> trueSpeed : Measure true browsing speed </h1>
<div id="info"></div>
<div id="result"></div>
<div id="map"></div>
</body>
</html>