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

Function sendTelemetry

speedtest_worker.js:682–724  ·  view source on GitHub ↗
(done)

Source from the content-addressed store, hash-verified

680}
681// telemetry
682function sendTelemetry(done) {
683 if (settings.telemetry_level < 1) return;
684 xhr = new XMLHttpRequest();
685 xhr.onload = function() {
686 try {
687 const parts = xhr.responseText.split(" ");
688 if (parts[0] == "id") {
689 try {
690 let id = parts[1];
691 done(id);
692 } catch (e) {
693 done(null);
694 }
695 } else done(null);
696 } catch (e) {
697 done(null);
698 }
699 };
700 xhr.onerror = function() {
701 console.log("TELEMETRY ERROR " + xhr.status);
702 done(null);
703 };
704 xhr.open("POST", settings.url_telemetry + url_sep(settings.url_telemetry) + (settings.mpot ? "cors=true&" : "") + "r=" + Math.random(), true);
705 const telemetryIspInfo = {
706 processedString: clientIp,
707 rawIspInfo: typeof ispInfo === "object" ? ispInfo : ""
708 };
709 try {
710 const fd = new FormData();
711 fd.append("ispinfo", JSON.stringify(telemetryIspInfo));
712 fd.append("dl", dlStatus);
713 fd.append("ul", ulStatus);
714 fd.append("ping", pingStatus);
715 fd.append("jitter", jitterStatus);
716 fd.append("log", settings.telemetry_level > 1 ? log : "");
717 fd.append("extra", settings.telemetry_extra);
718 xhr.send(fd);
719 } catch (ex) {
720 const postData = "extra=" + encodeURIComponent(settings.telemetry_extra) + "&ispinfo=" + encodeURIComponent(JSON.stringify(telemetryIspInfo)) + "&dl=" + encodeURIComponent(dlStatus) + "&ul=" + encodeURIComponent(ulStatus) + "&ping=" + encodeURIComponent(pingStatus) + "&jitter=" + encodeURIComponent(jitterStatus) + "&log=" + encodeURIComponent(settings.telemetry_level > 1 ? log : "");
721 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
722 xhr.send(postData);
723 }
724}

Callers 2

runNextTestFunction · 0.85

Calls 1

url_sepFunction · 0.85

Tested by

no test coverage detected