Skip to content

Commit

Permalink
add button to dropdown menu to ping destination
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcottle committed Dec 23, 2024
1 parent b0abe21 commit 647ee32
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
10 changes: 6 additions & 4 deletions meshchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,8 +1163,9 @@ async def index(request):
"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
Expand All @@ -1187,10 +1188,11 @@ async def index(request):
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,
Expand Down
27 changes: 27 additions & 0 deletions src/frontend/components/messages/ConversationDropDownMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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>

0 comments on commit 647ee32

Please sign in to comment.