How the /play 3-step wizard communicates with ros2 run unbeatabot web_bridge over HTTP/SSE, including calibration endpoints and Vercel HTTPS PNA.
The Next.js web app in web/ talks to ROS 2 through ros2_ws/src/unbeatabot/unbeatabot/web_bridge.py—a standard-library Python ThreadingHTTPServer listening on http://localhost:8780 (configurable via NEXT_PUBLIC_BRIDGE_URL and -p port:=8780).
The /play 3-Step Wizard
- Connect: Choose Demo (in-browser minimax) or Real robot (connects via EventSource to
/api/eventsand displays live game manager, arm, and camera status). - Calibration: Fetches
GET /api/calibration, previews the board footprint (corners 1, 3, 9, 7) from above, and lets you either accept the saved calibration or open the Recalibrate wizard. - Play: Displays the live 3x3 board, turn/help status banner, move sound effects, New game (
/api/new_game), and Resume (/api/resume) controls.
Bridge HTTP & SSE Endpoints
| Method & Path | Payload / Response | ROS 2 Action |
|---|---|---|
GET /api/events | SSE stream: state, status, calibration | Subscribes to /game_state, node heartbeats, and /board_state |
GET /api/calibration | { squareSize, tableZ, corners, tray, source } | Reads config/calibration.yaml |
POST /api/player_move | { "square": 1..9 } | Publishes move to /player_move |
POST /api/new_game | Empty body | Publishes empty trigger to /new_game |
POST /api/resume | Empty body | Publishes empty trigger to /resume |
Interactive Calibration Endpoints
The interactive browser calibration wizard uses four JSON routes backed by /get_tool and Calibration.fit_points:
| Endpoint | Request Body | Behavior |
|---|---|---|
POST /api/calibration/start | Optional { camera, view, markers } | Starts a calibration session and returns ordered board & piece steps |
POST /api/calibration/record | Optional { markerId, xyz } | Reads live arm tool position from /get_tool (if xyz omitted) and stores point |
POST /api/calibration/skip | Optional { markerId } | Marks the current marker skipped and advances to the next step |
POST /api/calibration/finish | Optional { cameraAt, updateTeach } | Runs Calibration.fit_points, saves YAMLs, and broadcasts updated calibration |
Vercel HTTPS & Private Network Access (PNA)
web_bridge.py restricts requests via an origin allowlist (DEFAULT_ORIGINS) so arbitrary tabs cannot command the robot arm. When the web app is deployed on Vercel over HTTPS and connects to http://localhost:8780, Chromium sends a Private Network Access preflight.
Access-Control-Allow-Origin: https://<your-app>.vercel.app
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Private-Network: trueCustom origins at launch
ros2 run unbeatabot web_bridge --ros-args -p origins:="['http://localhost:3000']".