fixed speedtest action

This commit is contained in:
2025-12-09 08:21:12 +01:00
parent ceda4feab1
commit 40c986534b
2 changed files with 94 additions and 112 deletions
+25 -106
View File
@@ -288,19 +288,6 @@ const RadiusRouterManager = {
}
this.routerActionLoading = false;
},
async setParameterValues(parameters) {
if (!this.routerDevice || !this.routerDevice.deviceId || !parameters) return false;
try {
const { data } = await axios.post(`${window.TT_CONFIG.BASE_PATH}/Radius/genieacsSetParameters`, {
deviceId: this.routerDevice.deviceId,
parameters: parameters
});
return data.success;
} catch (error) {
console.error('Error setting parameters:', error);
return false;
}
},
async runSpeedtest() {
if (!this.routerDevice || !this.routerDevice.deviceId) return;
this.showSpeedtestModal = true;
@@ -310,32 +297,23 @@ const RadiusRouterManager = {
this.speedtestHasStarted = false;
try {
const params = {
'InternetGatewayDevice.X_AVM-DE_SpeedtestServer.UDP.Start': 1,
'InternetGatewayDevice.X_AVM-DE_SpeedtestServer.UDP.StartBidirect': 1,
'InternetGatewayDevice.X_AVM-DE_SpeedtestServer.UDP.WANAccess': true
};
const { data } = await axios.post(`${window.TT_CONFIG.BASE_PATH}/Radius/genieacsRunSpeedtest`, {
deviceId: this.routerDevice.deviceId
});
if (!await this.setParameterValues(params)) {
throw new Error("Konnte Speedtest-Parameter nicht setzen");
if (data.success) {
this.pollSpeedtestResult();
} else {
throw new Error(data.message || "Speedtest konnte nicht gestartet werden");
}
const ip = this.routerDevice.ip;
if (!ip) throw new Error("Keine IP-Adresse gefunden");
await axios.post(`${window.TT_CONFIG.BASE_PATH}/Radius/genieacsRunSpeedtest`, { ip });
this.pollSpeedtestResult();
} catch (e) {
window.notify('error', e.message);
window.notify('error', e.response?.data?.message || e.message || 'Fehler beim Starten des Speedtests');
this.speedtestLoading = false;
}
},
async pollSpeedtestResult() {
let attempts = 0;
const maxAttempts = 240;
const resultParam = 'InternetGatewayDevice.X_AVM-DE_SpeedtestServer.UDP.Result';
const poll = async () => {
if (!this.showSpeedtestModal) return;
@@ -347,93 +325,34 @@ const RadiusRouterManager = {
attempts++;
try {
await axios.post(`${window.TT_CONFIG.BASE_PATH}/Radius/genieacsGetParameters`, {
deviceId: this.routerDevice.deviceId,
parameters: [resultParam]
const { data } = await axios.post(`${window.TT_CONFIG.BASE_PATH}/Radius/genieacsGetSpeedtestResult`, {
deviceId: this.routerDevice.deviceId
});
setTimeout(async () => {
try {
const val = await this.fetchDeviceParameterValue(resultParam);
if (val && typeof val === 'string' && val.includes("BPS")) {
const parsed = this.parseSpeedtestResult(val);
if (parsed) {
this.speedtestHistory.push(parsed);
this.$nextTick(() => {
if (this.$refs.speedtestBottom) {
this.$refs.speedtestBottom.scrollIntoView({ behavior: 'smooth' });
}
});
if (parsed.bps > 0) this.speedtestHasStarted = true;
if (this.speedtestHasStarted && parsed.bps === 0) {
this.speedtestLoading = false;
window.notify('success', 'Speedtest abgeschlossen');
return;
}
}
if (data.success && data.result) {
this.speedtestHistory.push(data.result);
this.$nextTick(() => {
if (this.$refs.speedtestBottom) {
this.$refs.speedtestBottom.scrollIntoView({ behavior: 'smooth' });
}
} catch(e) { console.error(e); }
});
if (this.speedtestLoading) setTimeout(poll, 500);
}, 500);
if (data.result.bps > 0) this.speedtestHasStarted = true;
if (this.speedtestHasStarted && data.result.bps === 0) {
this.speedtestLoading = false;
window.notify('success', 'Speedtest abgeschlossen');
return;
}
}
} catch (e) {
console.error(e);
if (this.speedtestLoading) setTimeout(poll, 500);
}
if (this.speedtestLoading) setTimeout(poll, 1000);
};
poll();
},
async fetchDeviceParameterValue(paramName) {
if (!this.routerDevice || !this.routerDevice.deviceId) return null;
try {
const { data: deviceInfo } = await axios.get(`${window.TT_CONFIG.BASE_PATH}/Radius/genieacsGetDeviceInfo`, {
params: { deviceId: this.routerDevice.deviceId }
});
if (deviceInfo?.success && deviceInfo?.fullData) {
const paramData = deviceInfo.fullData[paramName];
if (paramData?.value?.[0]) {
return paramData.value[0];
}
}
} catch (error) {
console.error('Error fetching parameter value:', error);
}
return null;
},
formatBits(bps) {
if (!bps) return '0 Mbit/s';
const mbits = bps / 1000000;
return mbits.toFixed(2) + ' Mbit/s';
},
parseSpeedtestResult(raw) {
try {
const bpsMatch = raw.match(/BPS\s+(\d+)/);
const bytesMatch = raw.match(/Bytes\s+(\d+)/);
const packetsMatch = raw.match(/Packets\s+(\d+)/);
if (bpsMatch) {
const bps = parseInt(bpsMatch[1]);
const bytes = bytesMatch ? parseInt(bytesMatch[1]) : 0;
const packets = packetsMatch ? parseInt(packetsMatch[1]) : 0;
return {
raw: raw,
bps: bps,
bpsFormatted: this.formatBits(bps),
bytes: bytes,
bytesFormatted: window.TT_CORE.formatBytes(bytes),
packets: packets
};
}
} catch (e) {
console.error("Error parsing speedtest result", e);
}
return null;
},
async runRemoteAccess() {
if (!this.routerDevice || !this.routerDevice.deviceId) return;
this.showRemoteAccessModal = true;