getIp_ispInfo:true,//if set to true, the server will include ISP info with the IP address
getIp_ispInfo_distance:"km",//km or mi=estimate distance from server in km/mi; set to false to disable distance estimation. getIp_ispInfo must be enabled in order for this to work
xhr_dlMultistream:6,// number of download streams to use (can be different if enable_quirks is active)
xhr_ulMultistream:3,// number of upload streams to use (can be different if enable_quirks is active)
xhr_multistreamDelay:300,//how much concurrent requests should be delayed
xhr_ignoreErrors:1,// 0=fail on errors, 1=attempt to restart a stream if it fails, 2=ignore all errors
xhr_dlUseBlob:false,// if set to true, it reduces ram usage but uses the hard drive (useful with large garbagePhp_chunkSize and/or high xhr_dlMultistream)
xhr_ul_blob_megabytes:20,//size in megabytes of the upload blobs sent in the upload test (forced to 4 on chrome mobile)
garbagePhp_chunkSize:100,// size of chunks sent by garbage.php (can be different if enable_quirks is active)
enable_quirks:true,// enable quirks for specific browsers. currently it overrides settings to optimize for specific browsers, unless they are already being overridden with the start command
ping_allowPerformanceApi:true,// if enabled, the ping test will attempt to calculate the ping more precisely using the Performance API. Currently works perfectly in Chrome, badly in Edge, and not at all in Firefox. If Performance API is not supported or the result is obviously wrong, a fallback is provided.
overheadCompensationFactor:1.06,//can be changed to compensatie for transport overhead. (see doc.md for some other values)
xhr[i].open("GET",settings.url_dl+url_sep(settings.url_dl)+(settings.mpot?"cors=true&":"")+"r="+Math.random()+"&ckSize="+settings.garbagePhp_chunkSize,true);// random string to prevent caching
xhr[i].send();
}.bind(this),
1+delay
);
}.bind(this);
// open streams
for(vari=0;i<settings.xhr_dlMultistream;i++){
testStream(i,settings.xhr_multistreamDelay*i);
}
// every 200ms, update dlStatus
interval=setInterval(
function(){
tverb("DL: "+dlStatus+(graceTimeDone?"":" (in grace time)"));
dlStatus=((speed*8*settings.overheadCompensationFactor)/(settings.useMebibits?1048576:1000000)).toFixed(2);// speed is multiplied by 8 to go from bytes to bits, overhead compensation is applied, then everything is divided by 1048576 or 1000000 to go to megabits/mebibits
// IE11 workarond: xhr.upload does not work properly, therefore we send a bunch of small 256k requests and use the onload event as progress. This is not precise, especially on fast connections
xhr[i].onload=xhr[i].onerror=function(){
tverb("ul stream progress event (ie11wa)");
totLoaded+=reqsmall.size;
testStream(i,0);
};
xhr[i].open("POST",settings.url_ul+url_sep(settings.url_ul)+(settings.mpot?"cors=true&":"")+"r="+Math.random(),true);// random string to prevent caching
try{
xhr[i].setRequestHeader("Content-Encoding","identity");// disable compression (some browsers may refuse it, but data is incompressible anyway)
}catch(e){}
//No Content-Type header in MPOT branch because it triggers bugs in some browsers
xhr[i].open("POST",settings.url_ul+url_sep(settings.url_ul)+(settings.mpot?"cors=true&":"")+"r="+Math.random(),true);// random string to prevent caching
try{
xhr[i].setRequestHeader("Content-Encoding","identity");// disable compression (some browsers may refuse it, but data is incompressible anyway)
}catch(e){}
//No Content-Type header in MPOT branch because it triggers bugs in some browsers
xhr[i].send(req);
}
}.bind(this),
delay
);
}.bind(this);
// open streams
for(vari=0;i<settings.xhr_ulMultistream;i++){
testStream(i,settings.xhr_multistreamDelay*i);
}
// every 200ms, update ulStatus
interval=setInterval(
function(){
tverb("UL: "+ulStatus+(graceTimeDone?"":" (in grace time)"));
ulStatus=((speed*8*settings.overheadCompensationFactor)/(settings.useMebibits?1048576:1000000)).toFixed(2);// speed is multiplied by 8 to go from bytes to bits, overhead compensation is applied, then everything is divided by 1048576 or 1000000 to go to megabits/mebibits
tlog("ulTest: "+ulStatus+", took "+(newDate().getTime()-startT)+"ms");
done();
}
}
}.bind(this),
200
);
}.bind(this);
if(settings.mpot){
tverb("Sending POST request before performing upload test");
xhr=[];
xhr[0]=newXMLHttpRequest();
xhr[0].onload=xhr[0].onerror=function(){
tverb("POST request sent, starting upload test");
testFunction();
}.bind(this);
xhr[0].open("POST",settings.url_ul);
xhr[0].send();
}elsetestFunction();
}
// ping+jitter test, function done is called when it's over
varptCalled=false;// used to prevent multiple accidental calls to pingTest
functionpingTest(done){
tverb("pingTest");
if(ptCalled)return;
elseptCalled=true;// pingTest already called?
varstartT=newDate().getTime();//when the test was started
varprevT=null;// last time a pong was received
varping=0.0;// current ping value
varjitter=0.0;// current jitter value
vari=0;// counter of pongs received
varprevInstspd=0;// last ping time, used for jitter calculation
xhr=[];
// ping function
vardoPing=function(){
tverb("ping");
pingProgress=i/settings.count_ping;
prevT=newDate().getTime();
xhr[0]=newXMLHttpRequest();
xhr[0].onload=function(){
// pong
tverb("pong");
if(i===0){
prevT=newDate().getTime();// first pong
}else{
varinstspd=newDate().getTime()-prevT;
if(settings.ping_allowPerformanceApi){
try{
//try to get accurate performance timing using performance api
varp=performance.getEntries();
p=p[p.length-1];
vard=p.responseStart-p.requestStart;
if(d<=0)d=p.duration;
if(d>0&&d<instspd)instspd=d;
}catch(e){
//if not possible, keep the estimate
tverb("Performance API not supported, using estimate");
}
}
//noticed that some browsers randomly have 0ms ping
if(instspd<1)instspd=prevInstspd;
if(instspd<1)instspd=1;
varinstjitter=Math.abs(instspd-prevInstspd);
if(i===1)ping=instspd;
/* first ping, can't tell jitter yet*/else{
if(instspd<ping)ping=instspd;// update ping, if the instant ping is lower
if(i===2)jitter=instjitter;
//discard the first jitter measurement because it might be much higher than it should be
elsejitter=instjitter>jitter?jitter*0.3+instjitter*0.7:jitter*0.8+instjitter*0.2;// update jitter, weighted average. spikes in ping values are given more weight.
tlog("ping: "+pingStatus+" jitter: "+jitterStatus+", took "+(newDate().getTime()-startT)+"ms");
done();
}
}
}.bind(this);
// send xhr
xhr[0].open("GET",settings.url_ping+url_sep(settings.url_ping)+(settings.mpot?"cors=true&":"")+"r="+Math.random(),true);// random string to prevent caching