You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: speedtest.js
+31-31Lines changed: 31 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@
12
12
The best way to learn how to use this is to look at the basic example, but here's some documentation.
13
13
14
14
To initialize the test, create a new Speedtest object:
15
-
var s=new Speedtest();
15
+
let s=new Speedtest();
16
16
Now you can think of this as a finite state machine. These are the states (use getState() to see them):
17
17
- 0: here you can change the speed test settings (such as test duration) with the setParameter("parameter",value) method. From here you can either start the test using start() (goes to state 3) or you can add multiple test points using addTestPoint(server) or addTestPoints(serverList) (goes to state 1). Additionally, this is the perfect moment to set up callbacks for the onupdate(data) and onend(aborted) events.
18
18
- 1: here you can add test points. You only need to do this if you want to use multiple test points.
@@ -125,7 +125,7 @@ Speedtest.prototype = {
125
125
* Same as addTestPoint, but you can pass an array of servers
/*this function goes through a list of servers. For each server, the ping is measured, then the server with the function selected is called with the best server, or null if all the servers were down.
195
195
*/
196
-
varselect=function(serverList,selected){
196
+
constselect=function(serverList,selected){
197
197
//pings the specified URL, then calls the function result. Result will receive a parameter which is either the time it took to ping the URL, or -1 if something went wrong.
198
-
varPING_TIMEOUT=2000;
199
-
varUSE_PING_TIMEOUT=true;//will be disabled on unsupported browsers
198
+
constPING_TIMEOUT=2000;
199
+
letUSE_PING_TIMEOUT=true;//will be disabled on unsupported browsers
//try to get more accurate timing using performance API
214
-
varp=performance.getEntriesByName(url);
214
+
letp=performance.getEntriesByName(url);
215
215
p=p[p.length-1];
216
-
vard=p.responseStart-p.requestStart;
216
+
letd=p.responseStart-p.requestStart;
217
217
if(d<=0)d=p.duration;
218
218
if(d>0&&d<instspd)instspd=d;
219
219
}catch(e){}
@@ -234,14 +234,14 @@ Speedtest.prototype = {
234
234
}.bind(this);
235
235
236
236
//this function repeatedly pings a server to get a good estimate of the ping. When it's done, it calls the done function without parameters. At the end of the execution, the server will have a new parameter called pingT, which is either the best ping we got from the server or -1 if something went wrong.
237
-
varPINGS=3,//up to 3 pings are performed, unless the server is down...
237
+
constPINGS=3,//up to 3 pings are performed, unless the server is down...
238
238
SLOW_THRESHOLD=500;//...or one of the pings is above this threshold
0 commit comments