Repository navigation
feat: meet riders from other apps on the shared Herne Hill track - #89
RalfLeonFasler wants to merge 4 commits into
Conversation
Share the built-in Herne Hill velodrome through OpenBikeNet (protocol v0.2): one backend WebSocket per ride, off by default, with the rider's name, position, lap and speed. Power and cadence go only when the rider allows it, and heart rate is never sent. Riders from other apps appear on the track with their app next to their name, and remote riders move on smoothly between one-second updates. On the track, a group-ride room is off while OpenBikeNet is on. The wire messages, name rules, route mapping and smoothing are unit-tested; the link is tested against a local WebSocket server. See pepperstm#69.
eb119ca to
8f52466
Compare
pepperstm
left a comment
There was a problem hiding this comment.
Hi Ralf, thanks for picking this up, and for starting on Herne Hill. I like the shape of it: off by default, power/cadence opt-in, and written from the spec rather than ported. I've had a read through and most of what I spotted is around what happens when the connection drops.
The ones I'd want sorted before it goes in:
- If the link drops and someone leaves while we're offline, they never get removed (obn.rs:161). The known-riders set starts fresh on reconnect, so anyone missing from the new snapshot just stays in the engine, frozen, and still counts as a rival. Could you diff the snapshot against what's already in the engine?
- While we're backing off, the session keeps queueing an update every second, and on reconnect they all go out in one go (obn.rs:169). After a long outage that's a lot of stale positions well over 4 Hz, and other apps would see the rider rewind. Probably easiest to only ever send the latest position, e.g. a
watchchannel instead of the mpsc. - If the server sends
welcomeand then a fatal error (room full, bad name, unknown route), we end up withRetry { connected: true }and the backoff resets, so it hammers the server about once a second forever (obn.rs:130). I'd stop retrying on fatal errors, and pass the server's message through to the UI rather than "the server refused the connection". - In session.rs:383,
GroupLink::joingets called before we decide to drop the group room because OpenBikeNet is on. Its task is already running by then, and nothing callsleave(), so the relay connection sits in the room until the app quits. Checking OpenBikeNet first should do it. - When the ride is paused or finished, we keep sending the last speed (session.rs:749), because
tickreturns early without zeroing it. So other people see you roll on and snap back every second.
And some smaller things, none of them blockers:
- The remote
appfield doesn't go throughclean_namebefore it ends up in the label (session.rs:754). - Nothing stops our own rider coming back to us if the server echoes it, and since
set_remotematches on id only, a remote rider calledghostorbot0could overwrite one of our rivals. Maybe prefix remote ids with something likeobn:? - The smoothing only runs while the local rider is moving, and it uses moving time rather than wall-clock time (ride.rs:399). On a "Once round" ride remote riders also stick at 450 m and then jump back to the start.
forbidden()misses the private-use planes (U+F0000 and up), and the name is cut to 32 before it's trimmed, so leading spaces eat into it (core obn.rs:240).Message::Closealready matches thelet Some(Ok(message))above it, so those else arms never run. The snapshot andjoinedbranches could also share a helper.
I haven't built it or tried it against the public server yet. I'll give it a proper go once these are in. Thanks again!
Updates the docs to where the project is today. - HANDOFF: the test count (154, not 114), the CI check names, #70 confirmed by the reporter, Windows as the remaining untried platform, and a new *Work in progress* table: PR #89 (OpenBikeNet, changes requested), the `next` branch (world update, #39) and `feature/visual-style` (#50), plus what's on `main` since 0.3.10. - README: 130 core tests, the Linux Bluetooth row, and OpenBikeNet and the world update on the roadmap. - Wiki: the XOSS speed sensor in the tested-hardware table. - Some sentences across the README, HANDOFF, CONTRIBUTING, release notes and wiki reworded for readability. Every file, function and `VP_` switch the docs mention was checked against the code and still exists. Docs only.
They were only moved on while this rider was moving, by moving time, so they froze whenever this rider stopped pedalling or paused. On a "once round" ride they also stuck at the line and jumped back to the start. Now they move on every tick by the engine's wall clock and wrap on any closed route. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Known riders are kept across reconnects; anyone missing from the new snapshot is taken away instead of staying frozen on the track. - Only the latest position is sent (a watch channel), so after an outage one update goes out instead of a backlog. - A fatal error, or an error about subscribe/join (tagged with a ref), stops the link for the ride and shows a plain reason with the server's message. A connection that drops within 30 s of welcome no longer resets the backoff. - The remote app name is cleaned like a display name; our own rider id is never shown back to us. - Names are trimmed before they are cut to 32 characters, and the private-use planes are filtered out. - Tidier socket loop: Close handled explicitly, snapshot and joined share a helper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… stopped - Decide on OpenBikeNet before joining a group room, so the room is never joined (and never left open) when OpenBikeNet replaces it. - Paused, finished or standing, share speed 0 with group rides and OpenBikeNet; the engine keeps its last speed when it stops ticking. - Prefix OpenBikeNet rider ids with obn: so they can't overwrite the engine's own rivals (ghost, bot0, ...). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the careful read! All of it is in, in three commits: Blockers
Smaller ones
New tests cover the reconnect diff, the refusal (we send The rebase onto |
What and why
Meet riders from other indoor cycling apps on the Herne Hill velodrome through OpenBikeNet, the open protocol for shared presence. Refs #69.
Since #75 the track is built in and its measuring line is exactly 450 m, so this starts with Herne Hill instead of adding
velodrome-250:herne-hillisherne-hill-450, andherne-hill-clockwiseisherne-hill-450-clockwise.velodrome-250can follow later if wanted.How it works
crates/core/src/obn.rs: the pure protocol v0.2 messages, display-name cleaning (Cc/Cf/Co/Zl/Zp except U+200D), lap and position mapping, and the track → route table. Written from the spec, not ported: OpenRadlr is AGPL-3.0 and this repo is GPL-3.0.src-tauri/src/obn.rs: one backend WebSocket per ride. It says hello asvelopopuli, subscribes to the route in thepublicroom, joins, sends one update a second, reconnects with backoff, and pings after 20 s of silence. Other apps' riders come back as remote rivals.crates/core/src/ride.rs: remote riders move on at their last speed for at most 2 s between updates, so 1 Hz doesn't look jerky. This also smooths group-ride friends.What is sent
Display name, position, lap and speed. Power and cadence only when the rider turns them on. Never heart rate. Names are cleaned before they are sent and before other apps' names are shown. The server keeps only per-app counts (spec 10).
Checked
cargo fmt --all --check,cargo clippy --workspace -- -D clippy::correctness,cargo test --workspace(including 8 new protocol tests and a smoothing test),npx tsc --noEmit, Prettier andnpm run build:web.left, and leaving closes the connection.Not sure about
wss://openbikenet.cloud/v0) as the preset, or leave it empty and make people paste one? The issue proposed the public server.