Skip to content

Commit 2bf166b

Browse files
keesverruijtclaude
andauthored
docs(radar): subscribe to spokes only while displaying the radar (#3019)
* docs(radar): subscribe to spokes only while displaying the radar A provider treats spoke subscribers as the measure of whether anyone is watching a radar and may let an unwatched one stand down. Spell out that clients open the stream only while showing the radar, and that a relaying provider holds its upstream subscription only while it has subscribers of its own, using binaryStreamManager.getClientCount. Co-Authored-By: Claude Code <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015VvpP3eXB2WhgD8bwyDWoU * docs(radar): show the spoke socket being closed, name the stream id * docs(radar): fix the connection example introduction --------- Co-authored-by: Claude Code <noreply@anthropic.com>
1 parent 0bfc4b1 commit 2bf166b

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@ nul
5959

6060
# debug artefacts
6161
*.sln
62-
test/server-test-config/debug
62+
test/server-test-config/debug
63+
# Per-developer local Makefile (deploy shortcuts, scratch targets)
64+
Makefile.local

docs/develop/rest-api/radar_api.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ Different manufacturers have vastly different hardware capabilities, control set
8383
1. **Capabilities** — hardware capabilities (Doppler, dual-range, no-transmit zones, supported ranges)
8484
2. **Controls** — schema for each control (type, valid values, modes, read-only status)
8585

86+
A provider also treats the spoke stream's subscribers as the measure of whether anyone is
87+
watching a radar, and may let an unwatched radar stand down. A plugin that relays spokes from
88+
another provider — a proxy in front of mayara-server, say — must therefore hold its own
89+
upstream subscription only while it has subscribers of its own; see
90+
[Subscribe only while displaying](#subscribe-only-while-displaying).
91+
8692
## Control Categories
8793

8894
| Category | Description | Examples |
@@ -994,7 +1000,9 @@ The URL is constructed by convention from the host serving the radar list:
9941000

9951001
### Connection Logic
9961002

997-
This a Javascript example how to set up the connection to receive spokes:
1003+
This is a JavaScript example of how to set up the connection to receive spokes. It returns the
1004+
socket so the caller can close it when the radar is no longer displayed (see
1005+
[Subscribe only while displaying](#subscribe-only-while-displaying)):
9981006

9991007
```javascript
10001008
async function connectToSpokes() {
@@ -1019,9 +1027,35 @@ async function connectToSpokes() {
10191027
const spokeData = new Uint8Array(event.data)
10201028
// Process binary spoke data...
10211029
}
1030+
return socket
10221031
}
1032+
1033+
// When the radar view is hidden or unmounted:
1034+
// socket.close()
10231035
```
10241036

1037+
### Subscribe only while displaying
1038+
1039+
An open spoke stream tells the provider that someone is watching the radar. A provider may
1040+
use that to stop holding an unwatched radar up: mayara-server, for instance, lets a radar
1041+
stand down once nobody has subscribed to its spokes for the period set by its `autoStandby`
1042+
control (a minute by default), so that a headless installation does not keep the magnetron
1043+
transmitting for nobody. Control PUTs and REST reads do not count as watching — only the
1044+
spoke stream does.
1045+
1046+
So a client must open the spoke stream only while it is actually displaying the radar, and
1047+
close it as soon as it stops — when the radar view is hidden, not merely when the page is
1048+
closed. A subscription held open "just in case" keeps the radar transmitting.
1049+
1050+
The same rule applies one level up. A provider plugin that relays spokes from another
1051+
source (the mayara-server plugin, or an app-specific bridge such as an ORCA emulator)
1052+
must hold its upstream subscription only while it has subscribers itself, and close it
1053+
when the last one leaves. On the server side `app.binaryStreamManager.getClientCount(streamId)`,
1054+
with `streamId` being `` `radars/${radarId}` ``, gives the number of clients currently
1055+
subscribed to that radar's spoke stream, so a relay can connect on the first subscriber and
1056+
disconnect after the last. A relay that stays subscribed around the clock hides every
1057+
downstream client from the provider, and the radar never stands down.
1058+
10251059
### Spoke content and the legend
10261060

10271061
Every spoke contains `spoke_len` bytes. The radar API always uses one byte per pixel, with every byte representing a value explained by the `legend` contained in the capabilities.

0 commit comments

Comments
 (0)