changed handling of settings
- changed worker: allowing direct message to set options, also timeouts and pingcounts - examples changed with new set message
This commit is contained in:
parent
d8b1f0d085
commit
2facf7f096
3 changed files with 269 additions and 254 deletions
|
@ -64,7 +64,10 @@ div.meter{
|
|||
ul.innerHTML=data[2];
|
||||
ping.innerHTML=data[3];
|
||||
}.bind(this);
|
||||
w.postMessage("start garbage.php empty.dat empty.dat");
|
||||
w.postMessage("set url_dl garbage.php");
|
||||
w.postMessage("set url_ul empty.dat");
|
||||
w.postMessage("set url_ping empty.dat");
|
||||
w.postMessage("start");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -50,7 +50,8 @@ function runTest(){
|
|||
var data=event.data.split(";");
|
||||
var status=Number(data[0]);
|
||||
var dl=document.getElementById("download"),ul=document.getElementById("upload"),ping=document.getElementById("ping");
|
||||
dl.className=status==1?"flash":"";ul.className=status==2?"flash":"";ping.className=status==3?"flash":"";
|
||||
// dl.className=status==1?"flash":"";ul.className=status==2?"flash":"";ping.className=status==3?"flash":"";
|
||||
|
||||
if(status>=4){
|
||||
clearInterval(interval);
|
||||
document.getElementById("abortBtn").style.display="none";
|
||||
|
@ -64,7 +65,10 @@ function runTest(){
|
|||
ul.innerHTML=data[2];
|
||||
ping.innerHTML=data[3];
|
||||
}.bind(this);
|
||||
w.postMessage("start garbage.php empty.dat empty.dat");
|
||||
w.postMessage("set time_dl 10"); // Timeout download
|
||||
w.postMessage("set time_ul 20"); // Timeout upload
|
||||
w.postMessage("set count_ping 30"); // Count of pings
|
||||
w.postMessage("start");
|
||||
}
|
||||
function abortTest(){
|
||||
if(w)w.postMessage("abort");
|
||||
|
|
|
@ -1,24 +1,32 @@
|
|||
var testStatus=0,dlStatus="",ulStatus="",pingStatus="";
|
||||
var settings={time_ul : 15, time_dl:15, count_ping: 15, url_dl:"garbage.php",url_ul:"empty.dat",url_ping:"empty.dat"};
|
||||
var xhr=null;
|
||||
this.addEventListener('message', function(e){
|
||||
var params=e.data.split(" ");
|
||||
if(params[0]=="set")
|
||||
{
|
||||
if(params[1] && settings.hasOwnProperty(params[1]) && params[2])
|
||||
{
|
||||
settings[params[1]]=params[2];
|
||||
}
|
||||
}
|
||||
if(params[0]=="status"){
|
||||
postMessage(testStatus+";"+dlStatus+";"+ulStatus+";"+pingStatus);
|
||||
}
|
||||
if(params[0]=="start"){
|
||||
if(testStatus==0){
|
||||
testStatus=1;
|
||||
var dlUrl=params[1]?params[1]:"garbage.php", ulUrl=params[2]?params[2]:"empty.dat", pingUrl=params[3]?params[3]:"empty.dat";
|
||||
dlTest(dlUrl,function(){testStatus=2;ulTest(ulUrl,function(){testStatus=3;pingTest(pingUrl,function(){testStatus=4;});});});
|
||||
dlTest(function(){testStatus=2;ulTest(function(){testStatus=3;pingTest(function(){testStatus=4;});});});
|
||||
}
|
||||
}
|
||||
if(params[0]=="abort"){
|
||||
console.warn("Aborting test...")
|
||||
try{if(xhr)xhr.abort();}catch(e){}
|
||||
testStatus=5;dlStatus="";ulStatus="";pingStatus="";
|
||||
}
|
||||
});
|
||||
|
||||
function dlTest(serverURL,done){
|
||||
function dlTest(done){
|
||||
var firstTick=true,startT=new Date().getTime(), prevT=new Date().getTime(),prevLoaded=0,speed=0.0;
|
||||
xhr=new XMLHttpRequest();
|
||||
xhr.onprogress=function(event){
|
||||
|
@ -33,7 +41,7 @@ function dlTest(serverURL,done){
|
|||
prevLoaded=event.loaded;
|
||||
prevT=new Date().getTime();
|
||||
dlStatus=((speed*8)/1048576.0).toFixed(2);
|
||||
if(((prevT-startT)/1000.0)>15){try{xhr.abort();}catch(e){} xhr=null; done();}
|
||||
if(((prevT-startT)/1000.0)>settings.time_dl){;try{xhr.abort();}catch(e){} xhr=null; done();}
|
||||
}.bind(this);
|
||||
xhr.onload=function(){
|
||||
dlStatus=((speed*8)/1048576.0).toFixed(2);
|
||||
|
@ -45,11 +53,11 @@ function dlTest(serverURL,done){
|
|||
xhr=null;
|
||||
done();
|
||||
}.bind(this);
|
||||
xhr.open("GET", serverURL+"?random="+Math.random(),true);
|
||||
xhr.open("GET", settings.url_dl+"?r="+Math.random(),true);
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function ulTest(serverURL,done){
|
||||
function ulTest(done){
|
||||
var firstTick=true,startT=new Date().getTime(), prevT=new Date().getTime(),prevLoaded=0,speed=0.0;
|
||||
xhr=new XMLHttpRequest();
|
||||
xhr.upload.onprogress=function(event){
|
||||
|
@ -63,7 +71,7 @@ function ulTest(serverURL,done){
|
|||
prevLoaded=event.loaded;
|
||||
prevT=new Date().getTime();
|
||||
ulStatus=((speed*8)/1048576.0).toFixed(2);
|
||||
if(((prevT-startT)/1000.0)>15){try{xhr.abort();}catch(e){} xhr=null; done();}
|
||||
if(((prevT-startT)/1000.0)>settings.time_ul){try{xhr.abort();}catch(e){} xhr=null; done();}
|
||||
}.bind(this);
|
||||
xhr.onload=function(){
|
||||
ulStatus=((speed*8)/1048576.0).toFixed(2);
|
||||
|
@ -73,11 +81,11 @@ function ulTest(serverURL,done){
|
|||
ulStatus="Fail";
|
||||
done();
|
||||
}.bind(this);
|
||||
xhr.open("POST", serverURL+"?random="+Math.random(),true);
|
||||
xhr.open("POST", settings.url_ul+"?r="+Math.random(),true);
|
||||
xhr.send(new ArrayBuffer(10485760));
|
||||
}
|
||||
|
||||
function pingTest(pingUrl,done){
|
||||
function pingTest(done){
|
||||
var prevT=null,ping=0.0,i=0;
|
||||
var doPing=function(){
|
||||
prevT=new Date().getTime();
|
||||
|
@ -91,13 +99,13 @@ function pingTest(pingUrl,done){
|
|||
}
|
||||
pingStatus=ping.toFixed(2);
|
||||
i++;
|
||||
if(i<50) doPing(); else done();
|
||||
if(i<settings.count_ping) doPing(); else done();
|
||||
}.bind(this);
|
||||
xhr.onerror=function(){
|
||||
pingStatus="Fail";
|
||||
done();
|
||||
}.bind(this);
|
||||
xhr.open("GET", pingUrl+"?random="+Math.random(),true);
|
||||
xhr.open("GET", settings.url_ping+"?r="+Math.random(),true);
|
||||
xhr.send();
|
||||
}.bind(this);
|
||||
doPing();
|
||||
|
|
Loading…
Reference in a new issue