Commit Graph

8 Commits

Author SHA1 Message Date
Zach Clendenen
9e2dbc207d feat(streaming): hydrate and resume only states the booted core can load
A RetroArch container's core filter comes from the core activate reports
booting, or before launch from the configured core and the broker's
default (asked over its cores route and cached for a minute). Hydration,
an explicit resume and the config payload all apply it, so a state
written by one core never lands where another core's quick-load reads it.
A resume the booted core cannot load launches fresh, and the resume
endpoint refuses such a state up front with a 400.
2026-09-27 16:42:02 -05:00
Zach Clendenen
f58a7ad7e0 polish(pr-ready step 4): trim the comments and name the resolve helper for its answer
Cut the docstrings and comments this branch added down to the one non-obvious
fact each, in the resolver and in the tests alike, and rename the new helper to
_claimable_broker_host so it says what it returns next to _derive_broker_host.
2026-09-15 17:09:59 -05:00
Zach Clendenen
1b3caebabf simplify(pr-ready step 3): flatten the container resolve and compare protocols by name
Move the three ways a raw entry fails to resolve into one helper with a guard
clause each, so none of them has to unset a broker host a sibling branch set.

The subfolder match moves onto WebstationProtocol, next to the normalization it
has to agree with, and interchangeable_with compares protocol names, the
discriminator the record already uses elsewhere.
2026-09-15 17:05:08 -05:00
Zach Clendenen
9a4b644c01 review(pr-ready step 2): let a player reclaim their own stale container
The holder gate added with the pool ran before the stale-takeover walk, so a
player whose tab crashed was refused their own container until its TTL lapsed.
Block only on a live holder, and when the holder's own session is stale narrow
the candidates to that container so the existing takeover path reclaims it.

Also widen the proxy path check to compare the host's URL path, so a container
on another origin mounted at a path that disagrees with its subfolder is
refused the same way a bare path already was.
2026-09-15 16:57:37 -05:00
Georges-Antoine Assi
7546ebafda docs(streaming): move the migration guide to the docs site
The webstation migration guide belongs in rommapp/docs, where users reading
about emulator streaming will find it (rommapp/docs#128). The deprecation
warning and the protocol module now link to the published page.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 19:10:28 -04:00
Georges-Antoine Assi
7443b690be fix(streaming): keep the container's answers inside its own origin
A broker's launch, join and desktop replies name the URL the browser loads
in an iframe, and urljoin keeps an absolute (or `javascript:`) URL verbatim,
so a container that answered with one could run script in RomM's origin
instead of its own. The three sites now share one resolver that drops a room
URL leaving the configured host, the stage refuses a source that is not
http(s), and the frame is sandboxed without allow-top-navigation so a
container page cannot steer the tab it sits in.

Also drop the shared secret from the config entry a resolution warning
prints, which named the misconfigured container by dumping it whole.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 14:53:43 -04:00
Georges-Antoine Assi
eccafd13d1 refactor(streaming): polish pass over the new modules
- The five new modules each defined `log = logging.getLogger("romm")`, which is
  what `logger.logger` already exports; they import it now.
- `ACK_TIMEOUT` had two homes. It is a protocol fact, so `protocol.py` owns it
  and the endpoint imports it from there; the unused
  `BROKER_LOAD_STATE_TIMEOUT` copy goes.
- Module and function docstrings trimmed to what the code cannot say: the
  change history and the justifications belong in the commit messages they came
  from.
- `asset_store` takes the union `write_file` accepts rather than `Any`.
- Four hand-rolled `setInterval` pairs (presence beat, session poll, exit
  chord, live sessions, activity tick) become `useIntervalFn`, which also
  cleared a real gap: the presence composable's timer had no scope teardown.
- The launch pushes are matched on the container the claim's 202 named, not on
  the platform: a pool serves one platform from more than one container, so a
  second tab could otherwise act on the first's launch.
- Test helpers typed: the push capture and the resume-claim tuple carry real
  types, and an unused `_claim_ready` helper goes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 13:13:02 -04:00
Georges-Antoine Assi
1246d18fe3 refactor(streaming): resolve containers once, behind a broker protocol
Two shapes of streaming broker were branched on at 19 call sites, and every
consumer re-derived a container's host, key, emulator, capabilities and card
sync from the raw YAML on each call. `_containers_for_platform` re-ran host
parsing and the operator's misconfiguration warnings on every request, and
`_container_label` re-read config.yml once per listed row.

`handler/streaming/`:
- `protocol.py` gives each broker shape a class owning its route prefixes,
  timeouts, response dialect, stream-URL assembly and capability flags. A call
  site now asks `protocol.supports_disc_swap` or `protocol.save_state_accepted`
  instead of re-testing `protocol: webstation`. Instances are interned per
  subfolder so identical configs share one object.
- `capabilities.py` holds the per-platform and per-emulator slot tables and the
  state transfer limits, keyed purely by platform and emulator.
- `config.py` turns the raw list into frozen `ResolvedContainer` records with
  every question already answered, memoized until the config changes, so the
  warnings fire once per config rather than once per lookup. A container RomM
  cannot dial still resolves, with an empty key: unclaimable, but visible in
  the admin fleet view where the operator can see why.

`endpoints/streaming.py` drops ~700 lines and takes records rather than dicts
throughout; `container.emulator` and `container.protocol.session_route(...)`
replace the derivations that used to run per call.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 10:13:46 -04:00