mirror of
https://github.com/liamcottle/reticulum-meshchat.git
synced 2026-11-29 03:16:37 -05:00
implement new network visualiser
This commit is contained in:
parent
8fa6298bf7
commit
520b6e6c2a
12 changed files with 338 additions and 18 deletions
221
src/frontend/components/network-visualiser/NetworkVisualiser.vue
Normal file
221
src/frontend/components/network-visualiser/NetworkVisualiser.vue
Normal file
|
|
@ -0,0 +1,221 @@
|
|||
<template>
|
||||
<div id="network"></div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { Network } from "vis-network";
|
||||
import Utils from "../../js/Utils";
|
||||
export default {
|
||||
name: 'NetworkVisualiser',
|
||||
data() {
|
||||
return {
|
||||
config: null,
|
||||
interfaces: [],
|
||||
pathTable: [],
|
||||
announces: {},
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.update();
|
||||
},
|
||||
methods: {
|
||||
async getInterfaceStats() {
|
||||
try {
|
||||
const response = await axios.get(`/api/v1/interface-stats`);
|
||||
this.interfaces = response.data.interface_stats?.interfaces ?? [];
|
||||
} catch(e) {
|
||||
alert("failed to load interface stats");
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
async getPathTable() {
|
||||
try {
|
||||
const response = await axios.get(`/api/v1/path-table`);
|
||||
this.pathTable = response.data.path_table;
|
||||
} catch(e) {
|
||||
alert("failed to load path table");
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
async getConfig() {
|
||||
try {
|
||||
const response = await axios.get("/api/v1/config");
|
||||
this.config = response.data.config;
|
||||
} catch(e) {
|
||||
alert("failed to load config");
|
||||
console.error(e);
|
||||
}
|
||||
},
|
||||
async getAnnounces() {
|
||||
try {
|
||||
|
||||
// fetch announces
|
||||
const response = await window.axios.get(`/api/v1/announces`);
|
||||
|
||||
// cache announces
|
||||
this.announces = {};
|
||||
for(const announce of response.data.announces){
|
||||
this.announces[announce.destination_hash] = announce;
|
||||
}
|
||||
|
||||
} catch(e) {
|
||||
// do nothing if failed to load announces
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
async update() {
|
||||
|
||||
await this.getConfig();
|
||||
await this.getInterfaceStats();
|
||||
await this.getPathTable();
|
||||
await this.getAnnounces();
|
||||
|
||||
const nodes = [];
|
||||
const edges = [];
|
||||
|
||||
// add me
|
||||
nodes.push({
|
||||
id: "me",
|
||||
group: "me",
|
||||
label: this.config?.display_name ?? "This Device",
|
||||
size: 50,
|
||||
font: {
|
||||
color: "#000000",
|
||||
background: "#ffffff",
|
||||
},
|
||||
});
|
||||
|
||||
// add interfaces
|
||||
for(const entry of this.interfaces){
|
||||
|
||||
const node = {
|
||||
id: entry.name,
|
||||
group: "interface",
|
||||
label: entry.name,
|
||||
size: 30,
|
||||
font: {
|
||||
color: "#000000",
|
||||
background: '#ffffff',
|
||||
},
|
||||
shape: "circularImage",
|
||||
image: entry.status ? "/assets/images/network-visualiser/interface_connected.png" : "/assets/images/network-visualiser/interface_disconnected.png",
|
||||
};
|
||||
|
||||
// add interface node
|
||||
nodes.push(node);
|
||||
|
||||
// add edge from me to interface
|
||||
edges.push({
|
||||
from: "me",
|
||||
to: entry.name,
|
||||
color: "transparent",
|
||||
background: {
|
||||
enabled: true,
|
||||
color: entry.status ? "#22c55e" : "#ef4444",
|
||||
},
|
||||
label: [
|
||||
`Bitrate: ${this.formatBitsPerSecond(entry.bitrate)}`,
|
||||
`TX: ${this.formatBytes(entry.txb)}`,
|
||||
`RX: ${this.formatBytes(entry.rxb)}`,
|
||||
].join("\n"),
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// add paths for announces
|
||||
for(const entry of this.pathTable){
|
||||
|
||||
// skip this path if hops are unknown
|
||||
if(entry.hops == null){
|
||||
continue;
|
||||
}
|
||||
|
||||
// find what announced this path, or skip showing it for now
|
||||
const announce = this.announces[entry.hash];
|
||||
if(!announce){
|
||||
continue;
|
||||
}
|
||||
|
||||
const node = {
|
||||
id: entry.hash,
|
||||
group: "announce",
|
||||
size: 15,
|
||||
};
|
||||
|
||||
if(announce.aspect === "lxmf.delivery"){
|
||||
node.shape = "circularImage";
|
||||
node.image = "/assets/images/network-visualiser/user.png";
|
||||
node.label = [
|
||||
announce.app_data ? atob(announce.app_data) : "Anonymous Peer",
|
||||
`${entry.hops} ${entry.hops === 1 ? 'Hop' : 'Hops'}`,
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
if(announce.aspect === "nomadnetwork.node"){
|
||||
node.shape = "circularImage";
|
||||
node.image = "/assets/images/network-visualiser/server.png";
|
||||
node.label = [
|
||||
announce.app_data ? atob(announce.app_data) : "Anonymous Node",
|
||||
`${entry.hops} ${entry.hops === 1 ? 'Hop' : 'Hops'}`,
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
// add node
|
||||
nodes.push(node);
|
||||
|
||||
// add edge from interface to announced aspect
|
||||
edges.push({
|
||||
from: entry.interface,
|
||||
to: entry.hash,
|
||||
color: "gray",
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// create network ui
|
||||
const container = document.getElementById("network");
|
||||
new Network(container, {
|
||||
nodes: nodes,
|
||||
edges: edges,
|
||||
}, {
|
||||
layout: {
|
||||
// always layout nodes the same way across reloads if nothing changed
|
||||
randomSeed: 1,
|
||||
},
|
||||
nodes: {
|
||||
color: {
|
||||
border: "#000000",
|
||||
highlight: {
|
||||
border: "#000000",
|
||||
},
|
||||
},
|
||||
},
|
||||
physics: {
|
||||
barnesHut: {
|
||||
gravitationalConstant: -5000,
|
||||
},
|
||||
},
|
||||
groups: {
|
||||
"me": {
|
||||
shape: "image",
|
||||
image: "/assets/images/reticulum_logo_512.png",
|
||||
},
|
||||
"interface": {
|
||||
|
||||
},
|
||||
"announce": {
|
||||
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
},
|
||||
formatBytes: function(bytes) {
|
||||
return Utils.formatBytes(bytes);
|
||||
},
|
||||
formatBitsPerSecond: function(bits) {
|
||||
return Utils.formatBitsPerSecond(bits);
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<template>
|
||||
<NetworkVisualiser class="w-full h-full"/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import NetworkVisualiser from "./NetworkVisualiser.vue";
|
||||
|
||||
export default {
|
||||
name: 'NetworkVisualiserPage',
|
||||
components: {
|
||||
NetworkVisualiser,
|
||||
},
|
||||
}
|
||||
</script>
|
||||
Loading…
Add table
Add a link
Reference in a new issue