Update README.md to provide detailed project description, features, installation instructions, usage guidelines, and technical details for WebCounter - a Flask WebSocket server.

This commit is contained in:
2025-07-07 09:01:37 +03:00
parent 12466170c3
commit 09d8871ac3
18 changed files with 3492 additions and 1 deletions

155
templates/client.html Normal file
View File

@@ -0,0 +1,155 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebCounter - Client</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.7.2/socket.io.js"></script>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
text-align: center;
margin-bottom: 30px;
}
.status {
padding: 10px;
border-radius: 5px;
margin-bottom: 20px;
text-align: center;
font-weight: bold;
}
.status.connected {
background-color: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.status.disconnected {
background-color: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.events-container {
border: 1px solid #ddd;
border-radius: 5px;
padding: 20px;
max-height: 400px;
overflow-y: auto;
background-color: #f9f9f9;
}
.event {
background: white;
padding: 10px;
margin-bottom: 10px;
border-radius: 5px;
border-left: 4px solid #4CAF50;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.event-time {
color: #666;
font-size: 12px;
margin-bottom: 5px;
}
.event-data {
font-family: monospace;
background-color: #f8f9fa;
padding: 5px;
border-radius: 3px;
word-break: break-all;
}
.nav-link {
display: inline-block;
margin-top: 20px;
padding: 10px 20px;
background-color: #6c757d;
color: white;
text-decoration: none;
border-radius: 5px;
}
.nav-link:hover {
background-color: #5a6268;
}
</style>
</head>
<body>
<div class="container">
<h1>WebCounter - Client</h1>
<div id="status" class="status disconnected">Disconnected</div>
<div class="events-container">
<h3>Received Events:</h3>
<div id="events"></div>
</div>
<a href="/" class="nav-link">← Back to Home</a>
</div>
<script>
// Connect to WebSocket server
const socket = io();
const statusDiv = document.getElementById('status');
const eventsDiv = document.getElementById('events');
// Connection status
socket.on('connect', function() {
statusDiv.textContent = 'Connected to server';
statusDiv.className = 'status connected';
console.log('Connected to server');
});
socket.on('disconnect', function() {
statusDiv.textContent = 'Disconnected from server';
statusDiv.className = 'status disconnected';
console.log('Disconnected from server');
});
// Handle status messages
socket.on('status', function(data) {
addEvent('Status', data);
});
// Handle received events
socket.on('receive_event', function(data) {
addEvent('Event', data);
});
function addEvent(type, data) {
const eventDiv = document.createElement('div');
eventDiv.className = 'event';
const timeDiv = document.createElement('div');
timeDiv.className = 'event-time';
timeDiv.textContent = new Date().toLocaleTimeString();
const dataDiv = document.createElement('div');
dataDiv.className = 'event-data';
dataDiv.textContent = JSON.stringify(data, null, 2);
eventDiv.appendChild(timeDiv);
eventDiv.appendChild(dataDiv);
eventsDiv.appendChild(eventDiv);
// Auto-scroll to bottom
eventsDiv.scrollTop = eventsDiv.scrollHeight;
}
// Add initial connection event
window.addEventListener('load', function() {
addEvent('Info', { message: 'Client page loaded' });
});
</script>
</body>
</html>