feat: add /ws/companion_frame WebSocket proxy

Dumb byte pipe between browser WebSocket and companion TCP frame server.
Allows browser clients to speak the MeshCore companion frame protocol
directly — all parsing lives client-side.

New file: repeater/web/companion_ws_proxy.py
- ws4py handler with JWT auth (same pattern as PacketWebSocket)
- Resolves companion_name → TCP port from config
- Bidirectional byte forwarding: WS ↔ TCP

http_server.py: mount at /ws/companion_frame alongside /ws/packets

Co-Authored-By: Oz <oz-agent@warp.dev>
This commit is contained in:
dmduran12
2026-03-12 17:50:20 -07:00
parent bc19c0fd9b
commit 2b4012eeb6
2 changed files with 192 additions and 1 deletions
+15 -1
View File
@@ -28,6 +28,7 @@ try:
broadcast_packet,
init_websocket,
)
from .companion_ws_proxy import CompanionFrameWebSocket, set_daemon as _set_companion_daemon
WEBSOCKET_AVAILABLE = True
except ImportError:
@@ -163,7 +164,7 @@ class StatsApp:
raise cherrypy.NotFound()
# Handle WebSocket routes
if args and len(args) >= 2 and args[0] == "ws" and args[1] == "packets":
if args and len(args) >= 2 and args[0] == "ws" and args[1] in ("packets", "companion_frame"):
# WebSocket tool will intercept this
return ""
@@ -191,6 +192,7 @@ class HTTPStatsServer:
self.port = port
self.config = config or {}
self.config_path = config_path
self.daemon_instance = daemon_instance
# Initialize authentication handlers
self._init_auth_handlers()
@@ -359,6 +361,18 @@ class HTTPStatsServer:
"tools.gzip.on": False,
}
logger.info("WebSocket endpoint configured at /ws/packets")
# Companion frame proxy (binary WS ↔ TCP byte pipe)
if self.daemon_instance:
_set_companion_daemon(self.daemon_instance)
config["/ws/companion_frame"] = {
"tools.websocket.on": True,
"tools.websocket.handler_cls": CompanionFrameWebSocket,
"tools.trailing_slash.on": False,
"tools.require_auth.on": False,
"tools.gzip.on": False,
}
logger.info("WebSocket endpoint configured at /ws/companion_frame")
except Exception as e:
logger.error(f"Failed to initialize WebSocket: {e}")
import traceback