Add console debug output to pingServer: OK/ERR/TIMEOUT with elapsed ms

This commit is contained in:
2026-08-24 21:33:31 +00:00
parent 1642497c10
commit d26a3ee725
+5 -2
View File
@@ -374,13 +374,16 @@ var si = 0,
var timedOut = false; var timedOut = false;
var timer = setTimeout(function() { var timer = setTimeout(function() {
timedOut = true; img.src = ''; timedOut = true; img.src = '';
console.log('[ping] ' + host + ' TIMEOUT (2s)');
resolve({ host: host, time: -1 }); resolve({ host: host, time: -1 });
}, 2000); }, 2000);
img.onload = function() { img.onload = function() {
if (!timedOut) { clearTimeout(timer); resolve({ host: host, time: performance.now() - start }); } var elapsed = performance.now() - start;
if (!timedOut) { clearTimeout(timer); console.log('[ping] ' + host + ' OK ' + elapsed.toFixed(0) + 'ms'); resolve({ host: host, time: elapsed }); }
}; };
img.onerror = function() { img.onerror = function() {
if (!timedOut) { clearTimeout(timer); resolve({ host: host, time: performance.now() - start }); } var elapsed = performance.now() - start;
if (!timedOut) { clearTimeout(timer); console.log('[ping] ' + host + ' ERR ' + elapsed.toFixed(0) + 'ms'); resolve({ host: host, time: elapsed }); }
}; };
img.src = 'https://' + host + '/favicon.ico?_=' + Date.now() + '_' + Math.random().toString(36).slice(2,6); img.src = 'https://' + host + '/favicon.ico?_=' + Date.now() + '_' + Math.random().toString(36).slice(2,6);
}); });