Новые возможности client.html: - 🔊 Управление громкостью (слайдер 0-100%) - 🔇/🔊 Кнопки Mute/Unmute - 🔔 Тест звука (play_sound команда) - 💡 LED управление (цвет, яркость) - 📊 RMS Audio Level визуализация (реальное время) - 🎨 Современный UI (карточки, градиенты, анимации) - 📱 Адаптивный дизайн start_web_server.py: - Простой HTTP сервер для тестирования - Авто-определение WebSocket URL - Красивый вывод в консоль Запуск: cd examples/websocket-service ./start_web_server.py --port 8080 Открыть: http://localhost:8080/client.html
64 lines
2.2 KiB
Python
Executable File
64 lines
2.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Simple HTTP server for WebSocket client testing.
|
|
|
|
Usage:
|
|
python3 start_web_server.py [--port PORT]
|
|
|
|
Open in browser:
|
|
http://localhost:PORT/client.html
|
|
"""
|
|
|
|
import argparse
|
|
import http.server
|
|
import socketserver
|
|
import os
|
|
from pathlib import Path
|
|
|
|
PORT = 8080
|
|
SCRIPT_DIR = Path(__file__).parent.resolve()
|
|
|
|
|
|
class CustomHandler(http.server.SimpleHTTPRequestHandler):
|
|
"""Custom handler with better logging."""
|
|
|
|
def do_GET(self):
|
|
super().do_GET()
|
|
self.log_message(f"✅ Served: {self.path}")
|
|
|
|
def log_message(self, format, *args):
|
|
print(f"[WebServer] {args[0]}")
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description='WebSocket Client Web Server')
|
|
parser.add_argument('--port', type=int, default=PORT, help=f'Port (default: {PORT})')
|
|
parser.add_argument('--host', default='0.0.0.0', help='Host (default: 0.0.0.0)')
|
|
args = parser.parse_args()
|
|
|
|
# Change to websocket-service directory
|
|
os.chdir(SCRIPT_DIR)
|
|
|
|
print(f"""
|
|
╔══════════════════════════════════════════════════════════╗
|
|
║ 🛰️ Wyoming Satellite WebSocket Client Server ║
|
|
╠══════════════════════════════════════════════════════════╣
|
|
║ Serving: {str(SCRIPT_DIR):<45} ║
|
|
║ URL: http://localhost:{args.port:<36} ║
|
|
║ ║
|
|
║ Press Ctrl+C to stop ║
|
|
╚══════════════════════════════════════════════════════════╝
|
|
""")
|
|
|
|
with socketserver.TCPServer((args.host, args.port), CustomHandler) as httpd:
|
|
try:
|
|
print(f"🚀 Server started on http://{args.host}:{args.port}")
|
|
httpd.serve_forever()
|
|
except KeyboardInterrupt:
|
|
print("\n👋 Shutting down...")
|
|
httpd.shutdown()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|