MCPcopy
hub / github.com/librespeed/speedtest / getIp

Function getIp

speedtest_worker.js:294–318  ·  view source on GitHub ↗
(done)

Source from the content-addressed store, hash-verified

292let ipCalled = false; // used to prevent multiple accidental calls to getIp
293let ispInfo = ""; //used for telemetry
294function getIp(done) {
295 tverb("getIp");
296 if (ipCalled) return;
297 else ipCalled = true; // getIp already called?
298 let startT = new Date().getTime();
299 xhr = new XMLHttpRequest();
300 xhr.onload = function() {
301 tlog("IP: " + xhr.responseText + ", took " + (new Date().getTime() - startT) + "ms");
302 try {
303 const data = JSON.parse(xhr.responseText);
304 clientIp = data.processedString;
305 ispInfo = data.rawIspInfo;
306 } catch (e) {
307 clientIp = xhr.responseText;
308 ispInfo = "";
309 }
310 done();
311 };
312 xhr.onerror = function() {
313 tlog("getIp failed, took " + (new Date().getTime() - startT) + "ms");
314 done();
315 };
316 xhr.open("GET", settings.url_getIp + url_sep(settings.url_getIp) + (settings.mpot ? "cors=true&" : "") + (settings.getIp_ispInfo ? "isp=true" + (settings.getIp_ispInfo_distance ? "&distance=" + settings.getIp_ispInfo_distance + "&" : "&") : "&") + "r=" + Math.random(), true);
317 xhr.send();
318}
319// download test, calls done function when it's over
320let dlCalled = false; // used to prevent multiple accidental calls to dlTest
321function dlTest(done) {

Callers 1

runNextTestFunction · 0.85

Calls 3

tverbFunction · 0.85
tlogFunction · 0.85
url_sepFunction · 0.85

Tested by

no test coverage detected