add button to dropdown menu to ping destination

This commit is contained in:
liamcottle 2024-12-23 22:18:48 +13:00
commit 647ee32c87
2 changed files with 33 additions and 4 deletions

View file

@ -1163,8 +1163,9 @@ class ReticulumMeshChat:
"message": f"Ping failed. Timed out after {timeout_seconds} seconds.",
}, status=503)
# get number of hops to destination
hops = RNS.Transport.hops_to(destination_hash)
# get number of hops to destination and back from destination
hops_there = RNS.Transport.hops_to(destination_hash)
hops_back = receipt.proof_packet.hops
# get rssi
rssi = receipt.proof_packet.rssi
@ -1187,10 +1188,11 @@ class ReticulumMeshChat:
rtt_duration_string = f"{rtt_milliseconds} ms"
return web.json_response({
"message": f"Valid reply from {receipt.destination.hash.hex()}: hops={hops} time={rtt_duration_string}",
"message": f"Valid reply from {receipt.destination.hash.hex()}\nDuration: {rtt_duration_string}\nHops There: {hops_there}\nHops Back: {hops_back}",
"ping_result": {
"rtt": rtt,
"hops": hops,
"hops_there": hops_there,
"hops_back": hops_back,
"rssi": rssi,
"snr": snr,
"quality": quality,

View file

@ -19,6 +19,14 @@
</DropDownMenuItem>
</a>
<!-- ping button -->
<DropDownMenuItem @click="onPingDestination">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-5">
<path fill-rule="evenodd" d="M14.615 1.595a.75.75 0 0 1 .359.852L12.982 9.75h7.268a.75.75 0 0 1 .548 1.262l-10.5 11.25a.75.75 0 0 1-1.272-.71l1.992-7.302H3.75a.75.75 0 0 1-.548-1.262l10.5-11.25a.75.75 0 0 1 .913-.143Z" clip-rule="evenodd" />
</svg>
<span>Ping Destination</span>
</DropDownMenuItem>
<!-- set custom display name button -->
<DropDownMenuItem @click="onSetCustomDisplayName">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-5">
@ -84,6 +92,25 @@ export default {
async onSetCustomDisplayName() {
this.$emit("set-custom-display-name");
},
async onPingDestination() {
try {
// ping destination
const response = await window.axios.get(`/api/v1/ping/${this.peer.destination_hash}/lxmf.delivery`, {
params: {
timeout: 30,
},
});
// show result
DialogUtils.alert(response.data.message);
} catch(e) {
console.log(e);
const message = e.response?.data?.message ?? "Ping failed. Try again later";
DialogUtils.alert(message);
}
},
},
}
</script>