mirror of
https://github.com/dpup/meshstream.git
synced 2026-03-28 17:42:37 +01:00
210 lines
6.1 KiB
HTML
210 lines
6.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="description" content="Meshstream - A web interface for viewing Meshtastic network traffic">
|
|
<title>Meshstream</title>
|
|
<style>
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 40px 20px;
|
|
line-height: 1.6;
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
text-align: center;
|
|
background-color: #f9fafb;
|
|
color: #1f2937;
|
|
display: flex;
|
|
flex-direction: column;
|
|
min-height: 90vh;
|
|
justify-content: center;
|
|
}
|
|
|
|
h1 {
|
|
color: #2563eb;
|
|
font-size: 2.5rem;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
p {
|
|
margin-bottom: 1.5rem;
|
|
font-size: 1.1rem;
|
|
}
|
|
|
|
.container {
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.tabs {
|
|
display: flex;
|
|
justify-content: center;
|
|
margin-bottom: 2rem;
|
|
border-bottom: 1px solid #e5e7eb;
|
|
padding-bottom: 1rem;
|
|
}
|
|
|
|
.tab {
|
|
margin: 0 1rem;
|
|
padding: 0.5rem 1rem;
|
|
border-radius: 0.375rem;
|
|
cursor: pointer;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.tab.active {
|
|
background-color: #2563eb;
|
|
color: white;
|
|
}
|
|
|
|
.view {
|
|
display: none;
|
|
}
|
|
|
|
.view.active {
|
|
display: block;
|
|
}
|
|
|
|
#messages {
|
|
margin-top: 20px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 8px;
|
|
padding: 15px;
|
|
height: 400px;
|
|
overflow-y: auto;
|
|
background-color: #ffffff;
|
|
font-family: 'Monaco', 'Consolas', monospace;
|
|
font-size: 14px;
|
|
text-align: left;
|
|
}
|
|
|
|
.message {
|
|
padding: 8px 0;
|
|
border-bottom: 1px solid #eee;
|
|
}
|
|
|
|
.message:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.cta {
|
|
display: inline-block;
|
|
padding: 0.75rem 1.5rem;
|
|
background-color: #2563eb;
|
|
color: white;
|
|
font-size: 1.1rem;
|
|
font-weight: 500;
|
|
text-decoration: none;
|
|
border-radius: 0.375rem;
|
|
transition: background-color 0.2s;
|
|
}
|
|
|
|
.cta:hover {
|
|
background-color: #1d4ed8;
|
|
}
|
|
|
|
.note {
|
|
margin-top: 2rem;
|
|
font-size: 0.9rem;
|
|
color: #4b5563;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>Meshstream</h1>
|
|
|
|
<p>This page displays real-time messages from Meshtastic nodes via MQTT.</p>
|
|
<div id="messages">
|
|
<p>Waiting for messages...</p>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
function showView(viewName) {
|
|
// Hide all views
|
|
document.querySelectorAll('.view').forEach(view => {
|
|
view.classList.remove('active');
|
|
});
|
|
|
|
// Show selected view
|
|
document.getElementById(viewName + '-view').classList.add('active');
|
|
|
|
// Update tab styling
|
|
document.querySelectorAll('.tab').forEach(tab => {
|
|
tab.classList.remove('active');
|
|
});
|
|
|
|
// Find and activate the clicked tab
|
|
document.querySelectorAll('.tab').forEach(tab => {
|
|
if (tab.textContent.toLowerCase().includes(viewName)) {
|
|
tab.classList.add('active');
|
|
}
|
|
});
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const messagesDiv = document.getElementById('messages');
|
|
|
|
// Function to add a message to the UI
|
|
function addMessage(text) {
|
|
const msgElement = document.createElement('pre');
|
|
msgElement.className = 'message';
|
|
msgElement.textContent = text;
|
|
messagesDiv.appendChild(msgElement);
|
|
|
|
// Auto-scroll to the bottom
|
|
messagesDiv.scrollTop = messagesDiv.scrollHeight;
|
|
}
|
|
|
|
// Clear initial waiting message
|
|
messagesDiv.innerHTML = '';
|
|
|
|
// Connect to SSE endpoint
|
|
console.log('Connecting to SSE stream...');
|
|
const eventSource = new EventSource('/api/stream');
|
|
|
|
// Handle connection open
|
|
eventSource.onopen = () => {
|
|
console.log('SSE connection established');
|
|
addMessage('Connected to Meshtastic stream.');
|
|
};
|
|
|
|
// Handle connection error
|
|
eventSource.onerror = (error) => {
|
|
console.error('SSE connection error:', error);
|
|
addMessage('Error: Connection to server lost. Trying to reconnect...');
|
|
};
|
|
|
|
// Handle 'info' events
|
|
eventSource.addEventListener('info', (e) => {
|
|
console.log('Info event:', e.data);
|
|
addMessage(`Server info: ${e.data}`);
|
|
});
|
|
|
|
// Handle 'message' events
|
|
eventSource.addEventListener('message', (e) => {
|
|
console.log('Message event:', e.data);
|
|
try {
|
|
const packet = JSON.parse(e.data);
|
|
const timestamp = new Date(packet.received_at * 1000).toLocaleTimeString();
|
|
|
|
// Store the full packet data for later reference if needed
|
|
console.log('Full packet:', packet);
|
|
|
|
// Format the message with essential information
|
|
let msgText = `[${timestamp}] ${packet.port_string}\n\n`;
|
|
msgText += JSON.stringify(packet, null, 2);
|
|
|
|
addMessage(msgText);
|
|
} catch (err) {
|
|
console.error('Error parsing message:', err);
|
|
addMessage(`Raw message: ${e.data}`);
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |