feat: web-client — синхронизация команд с satellite
Изменения: - Перенесён start_server.py в web-client/ - Обновлены команды в client.html для соответствия satellite - handle_websocket_command поддерживает: - set_volume (level/volume) - mute/unmute - play_sound - set_led_brightness - trigger_event - Обновлён обработчик входящих событий: - voice-started/voice-stopped - transcript - synthesize - audio-start/audio-stop/played - timer-started/timer-finished - streaming-started/streaming-stopped - satellite-connected/satellite-disconnected - error - audio-level (RMS) Теперь client.html полностью соответствует API satellite
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
#!/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
|
||||
import signal
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
PORT = 8080
|
||||
SCRIPT_DIR = Path(__file__).parent.resolve()
|
||||
|
||||
# Global server reference for cleanup
|
||||
httpd = None
|
||||
|
||||
|
||||
class CustomHandler(http.server.SimpleHTTPRequestHandler):
|
||||
"""Custom handler with better logging."""
|
||||
|
||||
def do_GET(self):
|
||||
super().do_GET()
|
||||
print(f"[WebServer] ✅ {self.requestline} → {self.command} {self.path}")
|
||||
|
||||
def log_message(self, format, *args):
|
||||
# Suppress default logging
|
||||
pass
|
||||
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
"""Handle Ctrl+C gracefully."""
|
||||
print("\n👋 Shutting down...")
|
||||
if httpd:
|
||||
# Use shutdown() to stop serve_forever()
|
||||
httpd.shutdown()
|
||||
|
||||
|
||||
def main():
|
||||
global httpd
|
||||
|
||||
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)
|
||||
|
||||
# Register signal handlers
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
|
||||
# Allow socket reuse
|
||||
socketserver.TCPServer.allow_reuse_address = True
|
||||
|
||||
print(f"""
|
||||
╔══════════════════════════════════════════════════════════╗
|
||||
║ 🛰️ Wyoming Satellite WebSocket Client Server ║
|
||||
╠══════════════════════════════════════════════════════════╣
|
||||
║ Serving: {str(SCRIPT_DIR):<45} ║
|
||||
║ URL: http://localhost:{args.port:<36} ║
|
||||
║ Remote: http://<your-ip>:{args.port:<32} ║
|
||||
║ ║
|
||||
║ Press Ctrl+C to stop ║
|
||||
╚══════════════════════════════════════════════════════════╝
|
||||
""")
|
||||
|
||||
httpd = socketserver.TCPServer((args.host, args.port), CustomHandler)
|
||||
print(f"🚀 Server started on http://{args.host}:{args.port}")
|
||||
|
||||
try:
|
||||
httpd.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
print("\n👋 Server stopped")
|
||||
httpd.server_close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user