Module ws

Module ws 

Source
Expand description

WebSocket routes for the Wactorz server.

Two routes are mounted under the same axum Router:

  • /ws — Python-compatible aggregated-state bridge. Compatible with monitor.html (and any client expecting full_snapshot / patch / delete_agent JSON messages).

  • /mqtt — Transparent WebSocket proxy to the Mosquitto broker’s WS listener (configurable host/port, default localhost:9001). Compatible with mqtt.js / frontend/dist/index.html.

Together these two routes ensure any combination of python|rust backend × monitor.html|frontend/dist/index.html frontend works without any client-side changes.

§/ws message protocol (mirrors monitor_server.py)

Server → browser on connect:

{ "type": "full_snapshot", "state": { "agents": [...], "nodes": [...], ... } }

Server → browser on MQTT event:

{ "type": "patch", "event": { ... }, "state": { ... } }

Server → browser after delete command:

{ "type": "delete_agent", "agent_id": "...", "state": { ... } }

Browser → server (commands):

{ "type": "command", "command": "pause|stop|resume|delete", "agent_id": "..." }

Structs§

BridgeState
MonitorState
Mirrors the in-memory state maintained by Python’s monitor_server.py.
WsBridge
WsEnvelope
Raw MQTT message forwarded from the broker event loop. Consumed by WsBridge::spawn_monitor_task; not sent to browser clients.