Swap games
POST /api/session/swap-out and /api/session/swap-in: change the game inside a running room without anyone leaving.
A game swap changes the game inside a running session. The room stays up the whole time: the invite links, the seats, the gamepad slots, chat and the stream itself are kept, so nobody in the room has to rejoin. Only the emulator is replaced.
It's two calls, both from RomM's backend with the shared secret. RomM decides who may swap (the host only) and which games are allowed; the broker only checks that the room is in a state to take each step.
swap-outsaves the running game and stops it, exactly like an exit, but leaves the room open.- RomM pulls the saved state (and the memory card, on card-sync containers) the way it does after an exit.
swap-inlaunches the next game into the same room.
Swap out
curl -X POST "http://localhost:3000/streaming/api/session/swap-out?slot=0" \
-H 'X-Broker-Secret: <shared secret>'The broker saves a state first, with the game still running. If that state
doesn't save, nothing else happens: the answer is 502, the game keeps
running and the room is unchanged. Only once the state is confirmed does the
broker stop the emulator, dump the save files and upload the archive, the
same way exit does. The upload is filed under the outgoing
game (see Game ids).
The answer is the exit report with "status": "swapped_out" and
"phase": "swapping". The session is now between two games: status
reports "phase": "swapping" and no game. The swapped-out game's state stays
readable on GET /api/session/state-file until the next game launches, so
RomM can file it in the library.
| Answer | Meaning |
|---|---|
200 | Saved, stopped, archived. The room is waiting for swap-in. |
400 | The running emulator can't take part in a game swap (supports_game_swap is off). |
409 | No session, a swap already in progress, the emulator isn't running, or another session operation is running. |
502 | The state didn't save. The current game keeps running. |
Swap in
curl -X POST http://localhost:3000/streaming/api/session/swap-in \
-H 'X-Broker-Secret: <shared secret>' \
-H 'Content-Type: application/json' \
-d '{ "emulator": "retroarch", "rom": { "id": 9, "name": "Game B", "platform": "snes", "path": "/romm/snes/Game B.sfc" }, "save": { "resume_slot": 0 } }'The body is the activate body without the room fields
(session_id, user, multiplayer): emulator, rom, gui_language,
save, callback and firmware. The game launches exactly as activate
launches one, save restore and resume included, so the resume rule is the
same as pressing Play on that game. The answer is the activate report with
"phase": "playing"; selkies_tokens_pushed is null, since the seats'
stream tokens never changed.
The next game may use a different emulator, as long as this container serves it. A room lives in one container, so a game from another container can't be swapped in.
| Answer | Meaning |
|---|---|
200 | Launching in the same room. |
409 | No session, the room isn't between two games (swap out first), the last game's emulator is still running, or another session operation is running. |
| other | Anything activate refuses with, including its launch error codes (409 emulator_import_pending among them). The room stays waiting, so RomM can try another game or exit. |
While a swap is in progress
Between swap-out and swap-in:
activate,save-state,load-state,swap-disc,menu, aPUT state-fileand a secondswap-outanswer409.- The memory-card routes are open, since nothing is running: RomM evacuates
the old game's card and lays down the next one's here, the same as around
an exit and an activate. If the old game's emulator outlived its stop, they
answer
409instead, and so doesswap-in. exitends the room. There's no game to save, so it saves nothing.- If no game is swapped in within
BROKER_GAME_SWAP_TIMEOUTseconds (default600), the broker ends the room by itself.
What the room sees
Each step is broadcast to everyone in the room on the room websocket:
{ "type": "game_swap", "phase": "saving", "rom_name": "Game A", "game_running": false }phase | rom_name | game_running | When |
|---|---|---|---|
saving | the outgoing game | false | swap-out started |
failed | the outgoing game | true | swap-out aborted; the old game is still playing |
launching | the incoming game | false | swap-in started |
failed | the incoming game | false | swap-in failed; the room is still waiting |
ready | the incoming game | true | the new game is launching in the room |
rom_name is the rom's name from RomM, or the emulator's display name, or
null when neither is known. game_running says whether a game is playing
once that step is done, so a room page can tell the two failed cases apart
and know whether to show a game or a "switching game" state. The message
carries no paths, ids or error text, since anonymous invite guests receive
it too.
The room's GET /api/session/context also carries phase, so a page
loaded mid-swap can tell that no game is running yet.
Game ids
session_id is the room's id and never changes. Each game in it gets a
game_id: the room id itself for the first game, then <room id>-g1,
<room id>-g2 and so on for each game swapped in. A session that never
swaps therefore names its archive after the room id.
The game_id names the save archive (<game_id>-<time>.zip) and is sent as
session_id in the upload, alongside the outgoing game's rom_id; a game
after the first also sends room_id. Exit and swap-out reports and
last_exit carry both.
Which emulators can swap
supports_game_swap on the status route says whether the
running game can be swapped out. It's on for RetroArch (on every core that
saves states) and PCSX2, with their live save-integrity check still pending,
and off for every other emulator. See the support matrix.
RomM shows its picker disabled, with a reason, when it's off.