import json from nats.aio.client import Client from src.backend.config import settings from src.backend.nats_client.subjects import Subjects CAPABILITIES = { "service": settings.service_name, "domain": settings.service_domain, "version": "1.0.0", "description": "Intel RealSense D4xx stereo depth camera server", "endpoints": { "rest": { "health": {"method": "GET", "path": "/api/health"}, "discover": {"method": "GET", "path": "/api/discover"}, "open": {"method": "POST", "path": "/api/open"}, "close": {"method": "POST", "path": "/api/close"}, "capture": {"method": "GET", "path": "/api/capture"}, "rgb": {"method": "GET", "path": "/api/rgb"}, "depth": {"method": "GET", "path": "/api/depth"}, }, }, "nats": { "actions": [ { "subject": Subjects.action("snapshot"), "pattern": "request/reply", "description": "Capture RGB+depth frame", "request_schema": {"include_depth": "boolean"}, "response_schema": {"rgb_jpeg_b64": "string", "depth_png_b64": "string", "timestamp": "number"}, }, { "subject": Subjects.action("status"), "pattern": "request/reply", "description": "Get camera status", "response_schema": {"camera_open": "boolean", "sdk_initialized": "boolean"}, }, ], }, } async def publish_discovery(nc: Client): await nc.publish( Subjects.DISCOVERY_ANNOUNCE, json.dumps(CAPABILITIES).encode(), ) async def handle_discovery_request(msg): await msg.respond(json.dumps(CAPABILITIES).encode()) await nc.subscribe(Subjects.DISCOVERY_REQUEST, cb=handle_discovery_request) await nc.subscribe(Subjects.SERVICE_DISCOVERY, cb=handle_discovery_request)