indi_nexus.web¶
The FastAPI web bridge: one shared upstream IndiClient relayed to browsers
as typed JSON over a WebSocket, plus a REST snapshot and the bundled panel.
App¶
indi_nexus.web.app ¶
FastAPI application factory for the INDINexus web bridge.
:func:create_app builds a FastAPI app that serves, on top of one shared
:class:~indi_nexus.client.IndiClient:
GET /- the built reference panel if present, else the debug inspector page;GET /debug- the self-contained debug inspector page;GET /health- liveness and upstream connection state;GET /api/devicesand/api/devices/{device}[/{name}]- a read-only JSON snapshot of the property cache;WS /ws- the live bridge: a snapshot on connect, then streamed updates, with browser-sent frames forwarded upstream.
The client is injectable so tests drive the app over an in-memory transport; by
default a real TCP client to indiserver is created.
create_app ¶
create_app(*, client: IndiClient | None = None, indi_host: str = 'localhost', indi_port: int = 7624) -> FastAPI
Build the web-bridge FastAPI application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
IndiClient
|
An existing client to relay (used by tests); if omitted, a real
:class: |
None
|
indi_host
|
str
|
Upstream |
'localhost'
|
indi_port
|
int
|
Upstream |
7624
|
Returns:
| Name | Type | Description |
|---|---|---|
app |
FastAPI
|
The configured application; its lifespan starts and stops the bridge. |
Source code in src/indi_nexus/web/app.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
Bridge¶
indi_nexus.web.bridge ¶
Bridge: fan one shared IndiClient out to many browser WebSockets.
The bridge owns a single upstream connection to indiserver (via the M3
:class:~indi_nexus.client.IndiClient) and relays its activity to every connected
browser as JSON. Property changes, log messages, and connection-state transitions
are broadcast to all registered sinks; a browser's inbound frames are parsed back
into typed models and forwarded upstream. A newly-connected browser first receives
a snapshot of the current cache so it starts with full state.
Server -> browser frames are either an INDI message ({"tag": ...}, mirroring
the protocol models) or a small bridge control frame ({"event": ...}) for
UI affordances the INDI protocol has no message for, e.g. upstream connection
state. Browser -> server frames are always INDI messages.
Bridge ¶
Bridge(client: IndiClient)
Relay between one IndiClient and many browser WebSocket sinks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
IndiClient
|
The shared upstream client the bridge relays. |
required |
Source code in src/indi_nexus/web/bridge.py
44 45 46 47 48 49 | |
start
async
¶
start() -> None
Subscribe to the client and open its upstream connection.
Source code in src/indi_nexus/web/bridge.py
56 57 58 59 60 61 | |
aclose
async
¶
aclose() -> None
Close the upstream connection.
Source code in src/indi_nexus/web/bridge.py
63 64 65 | |
add_sink ¶
add_sink(sink: Sink) -> None
Register a browser sink to receive broadcasts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sink
|
Sink
|
An awaitable that sends one text frame to the browser. |
required |
Source code in src/indi_nexus/web/bridge.py
68 69 70 71 72 73 74 75 76 | |
remove_sink ¶
remove_sink(sink: Sink) -> None
Remove a previously registered sink.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sink
|
Sink
|
The sink to remove. |
required |
Source code in src/indi_nexus/web/bridge.py
78 79 80 81 82 83 84 85 86 | |
snapshot ¶
snapshot() -> list[str]
Return the current cache and recent messages as JSON frames.
Returns:
| Name | Type | Description |
|---|---|---|
frames |
list of str
|
One |
Source code in src/indi_nexus/web/bridge.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
connection_frame
staticmethod
¶
connection_frame(connected: bool) -> str
Build the control frame announcing upstream connection state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connected
|
bool
|
Whether the bridge is connected to |
required |
Returns:
| Name | Type | Description |
|---|---|---|
frame |
str
|
A JSON control frame ( |
Source code in src/indi_nexus/web/bridge.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
handle_incoming
async
¶
handle_incoming(text: str) -> None
Parse a browser frame and forward it upstream.
Malformed frames are logged and dropped rather than closing the socket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
A JSON INDI message from the browser. |
required |
Source code in src/indi_nexus/web/bridge.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |