mirror of
https://github.com/liamcottle/reticulum-meshchat.git
synced 2026-11-30 20:06:32 -05:00
implement new network visualiser
This commit is contained in:
parent
8fa6298bf7
commit
520b6e6c2a
12 changed files with 338 additions and 18 deletions
|
|
@ -78,18 +78,16 @@
|
|||
</SidebarLink>
|
||||
</li>
|
||||
|
||||
<!-- network -->
|
||||
<!-- network visualiser -->
|
||||
<li>
|
||||
<a target="_blank" href="/network.html" class="w-full text-gray-800 group flex gap-x-3 rounded-r-full p-2 mr-2 text-sm leading-6 font-semibold focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600 hover:bg-gray-100">
|
||||
<span class="my-auto">
|
||||
<SidebarLink :to="{ name: 'network-visualiser' }">
|
||||
<template v-slot:icon>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 256 256" class="w-6 h-6">
|
||||
<path d="M200,152a31.84,31.84,0,0,0-19.53,6.68l-23.11-18A31.65,31.65,0,0,0,160,128c0-.74,0-1.48-.08-2.21l13.23-4.41A32,32,0,1,0,168,104c0,.74,0,1.48.08,2.21l-13.23,4.41A32,32,0,0,0,128,96a32.59,32.59,0,0,0-5.27.44L115.89,81A32,32,0,1,0,96,88a32.59,32.59,0,0,0,5.27-.44l6.84,15.4a31.92,31.92,0,0,0-8.57,39.64L73.83,165.44a32.06,32.06,0,1,0,10.63,12l25.71-22.84a31.91,31.91,0,0,0,37.36-1.24l23.11,18A31.65,31.65,0,0,0,168,184a32,32,0,1,0,32-32Zm0-64a16,16,0,1,1-16,16A16,16,0,0,1,200,88ZM80,56A16,16,0,1,1,96,72,16,16,0,0,1,80,56ZM56,208a16,16,0,1,1,16-16A16,16,0,0,1,56,208Zm56-80a16,16,0,1,1,16,16A16,16,0,0,1,112,128Zm88,72a16,16,0,1,1,16-16A16,16,0,0,1,200,200Z"></path>
|
||||
</svg>
|
||||
</span>
|
||||
<span class="my-auto flex w-full">
|
||||
Network Visualiser
|
||||
</span>
|
||||
</a>
|
||||
</template>
|
||||
<template v-slot:text>Network Visualiser</template>
|
||||
</SidebarLink>
|
||||
</li>
|
||||
|
||||
<!-- settings -->
|
||||
|
|
|
|||
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>
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
<template>
|
||||
<iframe class="w-full h-full" src="/network.html"/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'NetworkVisualiserPage',
|
||||
}
|
||||
</script>
|
||||
|
|
@ -5,7 +5,7 @@ import vClickOutside from "click-outside-vue3";
|
|||
import App from './components/App.vue';
|
||||
import AboutPage from "./components/about/AboutPage.vue";
|
||||
import SettingsPage from "./components/settings/SettingsPage.vue";
|
||||
import NetworkVisualiserPage from "./components/network/NetworkVisualiserPage.vue";
|
||||
import NetworkVisualiserPage from "./components/network-visualiser/NetworkVisualiserPage.vue";
|
||||
import InterfacesPage from "./components/interfaces/InterfacesPage.vue";
|
||||
import NomadNetworkPage from "./components/nomadnetwork/NomadNetworkPage.vue";
|
||||
import MessagesPage from "./components/messages/MessagesPage.vue";
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 4.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
BIN
src/frontend/public/assets/images/network-visualiser/server.png
Normal file
BIN
src/frontend/public/assets/images/network-visualiser/server.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.2 KiB |
BIN
src/frontend/public/assets/images/network-visualiser/user.png
Normal file
BIN
src/frontend/public/assets/images/network-visualiser/user.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8 KiB |
BIN
src/frontend/public/assets/images/reticulum_logo_512.png
Normal file
BIN
src/frontend/public/assets/images/reticulum_logo_512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 85 KiB |
Loading…
Add table
Add a link
Reference in a new issue