Added minified JS; Updated examples
This commit is contained in:
parent
724c450821
commit
c5913d1a6c
|
@ -1,23 +1,39 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<script type="text/javascript" src="server_selector.js"></script>
|
<script type="text/javascript" src="server_selector.min.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function I(i){return document.getElementById(i);}
|
function I(i){return document.getElementById(i);}
|
||||||
|
|
||||||
//LIST OF TEST SERVERS. See documentation for details if needed
|
//LIST OF TEST SERVERS. See documentation for details if needed
|
||||||
var SPEEDTEST_SERVERS=[
|
var SPEEDTEST_SERVERS=[
|
||||||
{ //this is my demo server, remove it
|
{ //this is my demo server, remove it
|
||||||
name:"Speedtest Demo Server (fdossena.com)", //user friendly name for the server
|
name:"Speedtest Demo Server 1 (HTTP)", //user friendly name for the server
|
||||||
server:"https://speedtest.fdossena.com/testing/", //Full URL to the server, complete with / at the end
|
server:"http://mpotdemo.fdossena.com/", //Full URL to the server, complete with / at the end
|
||||||
dlURL:"garbage.php", //path to download test on this server (garbage.php or replacement)
|
dlURL:"garbage.php", //path to download test on this server (garbage.php or replacement)
|
||||||
ulURL:"empty.php", //path to upload test on this server (empty.php or replacement)
|
ulURL:"empty.php", //path to upload test on this server (empty.php or replacement)
|
||||||
pingURL:"empty.php", //path to ping/jitter test on this server (empty.php or replacement)
|
pingURL:"empty.php", //path to ping/jitter test on this server (empty.php or replacement)
|
||||||
getIpURL:"getIP.php" //path to getIP on this server (getIP.php or replacement)
|
getIpURL:"getIP.php" //path to getIP on this server (getIP.php or replacement)
|
||||||
},
|
},
|
||||||
{
|
{ //this is my demo server, remove it
|
||||||
name:"Localhost",
|
name:"Speedtest Demo Server 2 (HTTP)",
|
||||||
server:"http://127.0.0.1/",
|
server:"http://mpotdemo.adolfintel.com/",
|
||||||
|
dlURL:"garbage.php",
|
||||||
|
ulURL:"empty.php",
|
||||||
|
pingURL:"empty.php",
|
||||||
|
getIpURL:"getIP.php"
|
||||||
|
},
|
||||||
|
{ //this is my demo server, remove it
|
||||||
|
name:"Speedtest Demo Server 1 (HTTPS)",
|
||||||
|
server:"https://mpotdemo.fdossena.com/",
|
||||||
|
dlURL:"garbage.php",
|
||||||
|
ulURL:"empty.php",
|
||||||
|
pingURL:"empty.php",
|
||||||
|
getIpURL:"getIP.php"
|
||||||
|
},
|
||||||
|
{ //this is my demo server, remove it
|
||||||
|
name:"Speedtest Demo Server 2 (HTTPS)",
|
||||||
|
server:"https://mpotdemo.adolfintel.com/",
|
||||||
dlURL:"garbage.php",
|
dlURL:"garbage.php",
|
||||||
ulURL:"empty.php",
|
ulURL:"empty.php",
|
||||||
pingURL:"empty.php",
|
pingURL:"empty.php",
|
||||||
|
@ -104,7 +120,7 @@ function startStop(){
|
||||||
initUI();
|
initUI();
|
||||||
}else{
|
}else{
|
||||||
//test is not running, begin
|
//test is not running, begin
|
||||||
w=new Worker('speedtest_worker.js');
|
w=new Worker('speedtest_worker.min.js');
|
||||||
w.postMessage('start '+JSON.stringify(speedtestSettings)); //Add optional parameters as a JSON object to this command
|
w.postMessage('start '+JSON.stringify(speedtestSettings)); //Add optional parameters as a JSON object to this command
|
||||||
I("startStopBtn").className="running";
|
I("startStopBtn").className="running";
|
||||||
w.onmessage=function(e){
|
w.onmessage=function(e){
|
||||||
|
@ -178,7 +194,7 @@ function initUI(){
|
||||||
color:#404040;
|
color:#404040;
|
||||||
text-align:center;
|
text-align:center;
|
||||||
}
|
}
|
||||||
div.loadCircle{
|
span.loadCircle{
|
||||||
display:inline-block;
|
display:inline-block;
|
||||||
width:2em;
|
width:2em;
|
||||||
height:2em;
|
height:2em;
|
||||||
|
@ -311,7 +327,7 @@ function initUI(){
|
||||||
<body onload="initServers()">
|
<body onload="initServers()">
|
||||||
<h1>HTML5 Speedtest</h1>
|
<h1>HTML5 Speedtest</h1>
|
||||||
<div id="loading" class="visible">
|
<div id="loading" class="visible">
|
||||||
<p id="message"><div class="loadCircle"></div>Selecting a server...</p>
|
<p id="message"><span class="loadCircle"></span>Selecting a server...</p>
|
||||||
</div>
|
</div>
|
||||||
<div id="testWrapper" class="hidden">
|
<div id="testWrapper" class="hidden">
|
||||||
<div id="startStopBtn" onclick="startStop()"></div>
|
<div id="startStopBtn" onclick="startStop()"></div>
|
||||||
|
|
|
@ -1,23 +1,39 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<script type="text/javascript" src="server_selector.js"></script>
|
<script type="text/javascript" src="server_selector.min.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function I(i){return document.getElementById(i);}
|
function I(i){return document.getElementById(i);}
|
||||||
|
|
||||||
//LIST OF TEST SERVERS. See documentation for details if needed
|
//LIST OF TEST SERVERS. See documentation for details if needed
|
||||||
var SPEEDTEST_SERVERS=[
|
var SPEEDTEST_SERVERS=[
|
||||||
{ //this is my demo server, remove it
|
{ //this is my demo server, remove it
|
||||||
name:"Speedtest Demo Server (fdossena.com)", //user friendly name for the server
|
name:"Speedtest Demo Server 1 (HTTP)", //user friendly name for the server
|
||||||
server:"https://speedtest.fdossena.com/testing/", //Full URL to the server, complete with / at the end
|
server:"http://mpotdemo.fdossena.com/", //Full URL to the server, complete with / at the end
|
||||||
dlURL:"garbage.php", //path to download test on this server (garbage.php or replacement)
|
dlURL:"garbage.php", //path to download test on this server (garbage.php or replacement)
|
||||||
ulURL:"empty.php", //path to upload test on this server (empty.php or replacement)
|
ulURL:"empty.php", //path to upload test on this server (empty.php or replacement)
|
||||||
pingURL:"empty.php", //path to ping/jitter test on this server (empty.php or replacement)
|
pingURL:"empty.php", //path to ping/jitter test on this server (empty.php or replacement)
|
||||||
getIpURL:"getIP.php" //path to getIP on this server (getIP.php or replacement)
|
getIpURL:"getIP.php" //path to getIP on this server (getIP.php or replacement)
|
||||||
},
|
},
|
||||||
{
|
{ //this is my demo server, remove it
|
||||||
name:"Localhost",
|
name:"Speedtest Demo Server 2 (HTTP)",
|
||||||
server:"http://127.0.0.1/",
|
server:"http://mpotdemo.adolfintel.com/",
|
||||||
|
dlURL:"garbage.php",
|
||||||
|
ulURL:"empty.php",
|
||||||
|
pingURL:"empty.php",
|
||||||
|
getIpURL:"getIP.php"
|
||||||
|
},
|
||||||
|
{ //this is my demo server, remove it
|
||||||
|
name:"Speedtest Demo Server 1 (HTTPS)",
|
||||||
|
server:"https://mpotdemo.fdossena.com/",
|
||||||
|
dlURL:"garbage.php",
|
||||||
|
ulURL:"empty.php",
|
||||||
|
pingURL:"empty.php",
|
||||||
|
getIpURL:"getIP.php"
|
||||||
|
},
|
||||||
|
{ //this is my demo server, remove it
|
||||||
|
name:"Speedtest Demo Server 2 (HTTPS)",
|
||||||
|
server:"https://mpotdemo.adolfintel.com/",
|
||||||
dlURL:"garbage.php",
|
dlURL:"garbage.php",
|
||||||
ulURL:"empty.php",
|
ulURL:"empty.php",
|
||||||
pingURL:"empty.php",
|
pingURL:"empty.php",
|
||||||
|
@ -104,7 +120,7 @@ function startStop(){
|
||||||
initUI();
|
initUI();
|
||||||
}else{
|
}else{
|
||||||
//test is not running, begin
|
//test is not running, begin
|
||||||
w=new Worker('speedtest_worker.js');
|
w=new Worker('speedtest_worker.min.js');
|
||||||
w.postMessage('start '+JSON.stringify(speedtestSettings)); //Add optional parameters as a JSON object to this command
|
w.postMessage('start '+JSON.stringify(speedtestSettings)); //Add optional parameters as a JSON object to this command
|
||||||
I("startStopBtn").className="running";
|
I("startStopBtn").className="running";
|
||||||
I("shareArea").style.display="none";
|
I("shareArea").style.display="none";
|
||||||
|
@ -192,7 +208,7 @@ function initUI(){
|
||||||
color:#404040;
|
color:#404040;
|
||||||
text-align:center;
|
text-align:center;
|
||||||
}
|
}
|
||||||
div.loadCircle{
|
span.loadCircle{
|
||||||
display:inline-block;
|
display:inline-block;
|
||||||
width:2em;
|
width:2em;
|
||||||
height:2em;
|
height:2em;
|
||||||
|
@ -337,7 +353,7 @@ function initUI(){
|
||||||
<body onload="initServers()">
|
<body onload="initServers()">
|
||||||
<h1>HTML5 Speedtest</h1>
|
<h1>HTML5 Speedtest</h1>
|
||||||
<div id="loading" class="visible">
|
<div id="loading" class="visible">
|
||||||
<p id="message"><div class="loadCircle"></div>Selecting a server...</p>
|
<p id="message"><span class="loadCircle"></span>Selecting a server...</p>
|
||||||
</div>
|
</div>
|
||||||
<div id="testWrapper" class="hidden">
|
<div id="testWrapper" class="hidden">
|
||||||
<div id="startStopBtn" onclick="startStop()"></div>
|
<div id="startStopBtn" onclick="startStop()"></div>
|
||||||
|
|
1
Frontend/server_selector.min.js
vendored
Normal file
1
Frontend/server_selector.min.js
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
function ping(url,result){var xhr=new XMLHttpRequest,t=(new Date).getTime();xhr.onload=function(){if(0==xhr.responseText.length){var instspd=(new Date).getTime()-t;try{var p=performance.getEntries(),d=(p=p[p.length-1]).responseStart-p.requestStart;d<=0&&(d=p.duration),0<d&&d<instspd&&(instspd=d)}catch(e){}result(instspd)}else result(-1)}.bind(this),xhr.onerror=function(){result(-1)}.bind(this),xhr.open("GET",url),xhr.send()}var PINGS=3,SLOW_THRESHOLD=500;function checkServer(server,done){var i=0;server.pingT=-1;var nextPing=function(){i++!=PINGS?ping(server.server+server.pingURL,function(t){0<=t?((t<server.pingT||-1==server.pingT)&&(server.pingT=t),t<SLOW_THRESHOLD?nextPing():done()):done()}.bind(this)):done()}.bind(this);nextPing()}function selectServer(serverList,result){var i=0,done=function(){for(var bestServer=null,i=0;i<serverList.length;i++)-1!=serverList[i].pingT&&(null==bestServer||serverList[i].pingT<bestServer.pingT)&&(bestServer=serverList[i]);result(bestServer)}.bind(this),nextServer=function(){i!=serverList.length?checkServer(serverList[i++],nextServer):done()}.bind(this);nextServer()}var CONCURRENCY=4;function fastSelectServer(serverList,result){for(var serverLists=[],i=0;i<CONCURRENCY;i++)serverLists[i]=[];for(i=0;i<serverList.length;i++)serverLists[i%CONCURRENCY].push(serverList[i]);var completed=0,bestServer=null;for(i=0;i<CONCURRENCY;i++)selectServer(serverLists[i],function(server){null!=server&&(null==bestServer||server.pingT<bestServer.pingT)&&(bestServer=server),++completed==CONCURRENCY&&result(bestServer)}.bind(this))}
|
1
Frontend/speedtest_worker.min.js
vendored
Normal file
1
Frontend/speedtest_worker.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue