Files
go2rtc/www/network.html
T

92 lines
2.9 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>go2rtc - Network</title>
<script src="https://unpkg.com/vis-network@9.1.9/standalone/umd/vis-network.min.js"></script>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background-color: white;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
}
html, body, #network {
height: 100%;
width: 100%;
}
#network {
flex-grow: 1;
}
</style>
</head>
<body>
<div id="network"></div>
<script src="main.js"></script>
<script>
let network;
let nodes = new vis.DataSet();
let edges = new vis.DataSet();
/* global vis */
window.addEventListener('load', () => {
const url = new URL('api/streams.dot' + location.search, location.href);
const options = {
layout: {
randomSeed: "0.4597730541017021:1718519934576"
},
edges: {
font: { align: 'middle' },
smooth: false,
},
nodes: { shape: 'box' },
physics: {
enabled: false,
stabilization: {
enabled: false,
}
},
autoResize: false,
locale: navigator.language.toLowerCase().split('-').slice(0, 2).join('-'),
};
const container = document.getElementById('network');
async function fetchDataAndUpdateNetwork() {
try {
const response = await fetch(url, { cache: 'no-cache' });
const dotData = await response.text();
const data = vis.parseDOTNetwork(dotData);
if (!network) {
nodes = new vis.DataSet(data.nodes);
edges = new vis.DataSet(data.edges);
network = new vis.Network(container, { nodes, edges }, options);
network.storePositions();
} else {
const positions = network.getPositions();
network.setData(data);
for (const nodeId in positions) {
if (positions.hasOwnProperty(nodeId)) {
network.moveNode(nodeId, positions[nodeId].x, positions[nodeId].y);
}
}
}
} catch (error) {
console.error('Error fetching or updating network data:', error);
}
}
fetchDataAndUpdateNetwork();
setInterval(fetchDataAndUpdateNetwork, 5000);
});
</script>
</body>
</html>