Play and client services
Play and client services turn a library ROM into a usable play session. They connect browser and remote emulator clients to play history, save data, device sync, live streaming, and shared play while keeping game state tied to the right ROM, user, and device.
Player service model
The player service model starts a game through a suitable player and carries useful state back to the service. Browser players run in the web application. Remote players run in an emulator container. Both paths use the same library record for the game and its player data.
The main player paths connect through the following shared services:
flowchart LR
Library[ROM in library] --> Player{Player path}
Player --> Browser[Browser emulator]
Player --> Stream[Remote emulator stream]
Browser --> Activity[Play activity]
Stream --> Activity
Browser --> Saves[Save and state data]
Stream --> Saves
Saves --> Sync[Device and remote sync]
Player --> Netplay[Shared play]
Playback paths
The browser path offers a player only when the ROM has a file and a supported browser engine can run its platform. The shared play gate exposes the engine choices so the play action and the player view use the same decision. A DOS bundle also needs its expected bundle format. This prevents a play control from opening a player that cannot boot the file. frontend/…/index.ts.
The browser players cover general emulator content, DOS bundles, and Flash content. The common player shell separates the launch view from the running stage. Each player can then provide its own setup controls and its own exit rules. Browser runtimes use a local asset when it is available and a known remote asset as a fallback when it is not. frontend/…/PlayerShell.vue, frontend/…/EmulatorJS.vue, frontend/…/JsDos.vue, frontend/…/Ruffle.vue, and frontend/…/scriptLoader.ts.
The streaming path uses a native emulator outside the browser and places its remote view in the player page. It has its own launch and control surface because the server must own the remote session while the browser shows it.
References: frontend/…/index.ts• L24-55 frontend/…/PlayerShell.vue• L38-121 frontend/…/EmulatorJS.vue• L231-280 frontend/…/JsDos.vue• L45-101 frontend/…/Ruffle.vue• L51-88 frontend/…/scriptLoader.ts• L1-37
Library entry and readiness
The library entry point supplies the ROM records from which a player can start. It can narrow that set to playable games or to a HowLongToBeat main-story range, with the range sent in seconds and with each open end left out of the request. Setup services report whether the library is ready and which platforms are available before the user relies on those records.
These library checks shape the list of possible games. They do not replace the playback gate, which still confirms that the selected ROM has a usable file and a supported player path.
References: frontend/…/rom.ts• L158-220 frontend/…/rom.ts• L223-427 frontend/…/rom.test.ts• L133-162 frontend/…/setup.ts• L4-31
User identity and access
User identity ties play history, saves, states, memory cards, devices, and sessions to one account. Normal users receive access from a permission group and any user-specific overrides. Administrative streaming actions also require the matching scoped administrator permission: users.read for fleet and session views, and users.write for desktop setup, force release, and control of another user's session. backend/…/user.py, backend/…/access.py, and backend/…/streaming.py.
Streaming access has a separate streaming grant in addition to route scopes. The grant controls whether a caller can see streaming, start a session, or join one. This keeps a readable ROM list from granting access to a remote emulator by itself. backend/…/streaming.py.
Kiosk mode uses one synthetic visitor identity rather than a separate account for each visitor. Player-facing write routes therefore require the user-level write scope for actions such as claiming or controlling a remote session. This prevents anonymous visitors from sharing one ownership record and overwriting each other's state. A scoped administrator who controls another user's session does not become the owner of the session's saves, states, memory card, or play history. backend/…/access.py.
References: backend/…/user.py• L26-38 backend/…/user.py• L43-48 backend/…/user.py• L97-127 backend/…/access.py• L26-77 backend/…/streaming.py• L1-13 backend/…/streaming.py• L338-388 backend/…/streaming.py• L1635-1781
Play activity
Play activity is the record of what a user played and when. A player starts timing after gameplay begins and sends the completed interval when the player exits. The server stores valid intervals and uses them to update the user's last-played and active-play data. A short or failed launch does not create useful play history.
The player also emits live activity signals while an EmulatorJS game runs. Heartbeats keep the current game visible to other client surfaces. Exit signals clear that live presence. The saved play interval remains the durable history. Browser players also return controller and keyboard input to the application when they exit.
The play-session service accepts a bounded batch of completed intervals. It checks that each interval has a positive time span and a non-negative duration before it sends each entry through the shared ingest path. The database layer identifies repeated intervals by user, device, ROM, and start time. This lets browser play, remote play, and offline sync retry history without treating a repeated delivery as a new session.
Remote streaming sessions use the same play record as other clients. Their lifecycle records the session owner's time during teardown and keeps live activity separate from the durable interval. See Play sessions and saves for the session record and save relationship.
References: frontend/…/EmulatorJS.vue• L120-165 frontend/…/EmulatorJS.vue• L402-443 frontend/…/JsDos.vue• L100-179 frontend/…/Ruffle.vue• L80-131 backend/…/play_session_handler.py• L41-61 backend/…/play_sessions_handler.py• L13-110 backend/…/play_sessions.py• L25-139 backend/…/lifecycle.py• L246-369
Game state services
Game state services keep durable saves and emulator-specific states available to the player. A save is an archive of a game's own data, while a state is a player-specific resume point. Either asset can also carry emulator, slot, device, or screenshot context. Browser and streaming clients use the same library boundary for these assets.
Save and state access
The player can resume from a server save or a compatible emulator state. Save uploads and updates refresh the server record. They can also include a screenshot for the player view. Writing or updating a save marks the ROM as played, but a save is not proof of a complete play session.
Save uploads can create a new version in a named slot or update an existing record. The service rejects an ordinary device upload when the server has newer data, avoids storing a duplicate content version, and can prune old versions when the client requests retention. An explicit overwrite is the escape hatch for a deliberate replacement. A save held by a snapshot channel is treated as protected history rather than a file that an upload can silently replace. The client uses the reserved autosave slot for automatic progress, while a null slot remains an archival manual upload that is not paired with a device. backend/…/saves.py and frontend/…/save.ts.
Save responses can include sync status for every device that has seen the save when the request has device context. The caller's device is returned first, and a placeholder is returned when it has not seen the save yet. This lets clients compare their copy with the server and with other devices without treating a missing tracking row as a missing save. A download records the served server version as a provisional baseline. The caller can then confirm the bytes it received, while an ordinary upload still protects newer server data unless the caller asks to overwrite it. backend/…/saves.py.
ROM visibility is an access boundary for saves, not only a filter on the library list. Save lists, identifiers, summaries, per-save reads, downloads, confirmations, writes, deletion, and device tracking use the caller's visible ROM set. A shared save still cannot reveal or change a ROM that the caller cannot see. backend/…/saves.py.
State uploads and updates also mark the ROM as recently played. State lists can be limited to selected ROMs or platforms so a client can request only the part of its library that it knows about. A state download still checks the ROM's visibility, even when the state itself is public. This keeps shared state access inside the same library boundary as the game.
Streaming state history keeps each meaningful capture so a player can choose an earlier resume point. The newest compatible state is hydrated into a claimed container after launch, while an explicitly chosen state is loaded for that session. RetroArch states also follow the running core's shared folder identity, so equivalent core names do not create separate resume paths. In-game save archives remain separate from state history because they represent the emulator's own save files rather than a snapshot of emulator memory. backend/…/states.py and backend/…/saves.py.
When a launch selects data from another emulator, a supported streaming broker can accept a declared save or state import. The service builds one bounded archive with a manifest that records each imported member and its source. It combines the selected foreign data with a native save base when needed, while keeping foreign state data distinct from the save archive. This lets a compatible target emulator receive foreign data without treating it as a native save or state. A broker refusal is reported with its reason, so an unsupported import does not look like a successful resume.
Save and state visibility is user-controlled. Owners can keep assets private or share them. Sharing does not bypass ROM access rules. A shared asset remains within the same library access boundary as its game, and its preview follows the asset's visibility.
The player keeps save choice and state choice separate. This lets a user load a state without silently binding an unrelated save slot as the write-back target. DOS play also keeps browser-side file changes scoped to the RomM user and ROM, so browser profiles do not mix changes between accounts.
References: backend/…/saves.py• L52-169 backend/…/saves.py• L181-444 backend/…/saves.py• L447-615 backend/…/saves.py• L618-897 backend/…/archive.py• L7-44 backend/…/imports.py• L23-31 backend/…/imports.py• L73-203 backend/…/imports.py• L214-290 backend/…/saves.py• L147-235 backend/…/states.py• L351-520 frontend/…/save.ts• L13-118 frontend/…/save.ts• L121-175 frontend/…/EmulatorJS.vue• L176-181 frontend/…/EmulatorJS.vue• L352-391 frontend/…/JsDos.vue• L79-101
Device save tracking
Device save tracking records the last server version known by each device. It lets a client tell the difference between a save it has already received, a newer server save, and a save that changed on both sides. A device can stop tracking one save without deleting the server copy. It can track the save again later.
Save responses include device sync information when a request has device context. The response can show all known device records and keeps the caller's record first for stable client use. If the caller has no record yet, the response includes a not-current placeholder. A successful download first records the server version that was served, then confirmation records the bytes the device actually holds. An ordinary upload protects newer server data unless the client asks to overwrite it. The client uses the reserved autosave slot for automatic progress, while a null slot remains an archival manual upload that is not paired with a device.
The browser also has a small unload path for progress that must leave while the page closes. It uses an in-place update when a save already exists and an overwrite upload when it must create a new version. Large save files do not use this path because a browser keepalive request has a fixed body limit. frontend/…/save.ts.
References: backend/…/device_save_sync.py• L16-44 backend/…/saves.py• L52-148 backend/…/saves.py• L447-615 backend/…/saves.py• L618-717 backend/…/saves.py• L862-897 backend/…/saves_handler.py• L83-121 frontend/…/save.ts• L13-20 frontend/…/save.ts• L63-118 frontend/…/save.ts• L142-175
Remote synchronization
Remote synchronization moves save data and play history between RomM and an authorized client device. The client first describes its current save set. The server compares it with current server saves and returns a plan that tells the client which items to upload, download, leave alone, or resolve as conflicts. It supports both device sync sessions and RetroArch Cloud Sync. See Remote library sync for the device workflow.
The synchronization flow is:
sequenceDiagram
participant Client
participant RomM
participant Device
Client->>RomM: Send save state
RomM->>RomM: Compare visible ROM and slot pairs
RomM-->>Client: Return sync operations
Client->>RomM: Complete operations
RomM->>RomM: Record sync result and play intervals
RomM-->>Device: Emit progress and result signals
Sync negotiation
A sync session groups one device's comparison and file operations. Stable slot names pair a client save with its server counterpart. A save without a slot remains an archival upload rather than being paired with a slotted save. The comparison uses content, modification time, and the device's last sync mark to avoid overwriting newer work without notice.
Snapshot channels add a history-aware view to this comparison. A channel's current version, retained branches, and the version known by the device can show whether a client copy is current, an older version, or a separate branch. A client copy that came from an earlier channel version is downloaded when the channel moved on. A copy that became a branch is reported as a conflict. A protected current save cannot be rewritten in place by a device upload.
Negotiation applies the caller's ROM visibility to server saves and deletion records. A client save on a hidden ROM is treated as if its ROM is not available, so it does not create a visible conflict or pair with a hidden server save. This keeps sync from becoming a side door to hidden library content.
A client can limit negotiation to the ROMs installed on the device. That limit controls which downloads appear. It is not a deletion signal, so leaving a ROM out does not remove or unlink its server saves. The server also considers the ROMs named by client saves so those saves are not mistaken for out-of-scope uploads. Clients can also limit pairing to emulators or RetroArch cores that they can load.
The server records the sync session from pending or active work to completed, failed, or cancelled. It keeps operation counts, completion time, and failure details so the client can distinguish a finished run from one that stopped early. Only one active run is selected for a device and user, which prevents overlapping work from reporting as one sync.
After the client completes its work, the sync session stores success and failure counts. The same completion can carry play intervals from the device. This links offline play back to the user's play history.
References: backend/…/__init__.py• L68-145 backend/…/__init__.py• L188-464 backend/…/__init__.py• L467-537 backend/…/comparison.py• L17-219 backend/…/saves_handler.py• L83-121 backend/…/sync_sessions_handler.py• L14-192
RetroArch Cloud Sync
RetroArch Cloud Sync presents the user's RomM saves and states through RetroArch's file and manifest model. The service resolves a client path to a visible ROM by its file name and the platform set supported by the selected RetroArch core. It keeps core names compatible with both systems and returns a manifest with content hashes so RetroArch can compare local and server data.
The service supports normal save files, emulator states, state screenshots, and RetroArch's user-level configuration, thumbnail, and system files. It also groups PSP memory-stick save folders as one bounded save archive. State files are exposed under canonical RetroArch slot names, so a state made by the web player can still resolve to the matching RetroArch slot. Upload, download, and delete operations update the same user-owned save, state, or screenshot records used by the other players.
PSP folder files can arrive before the service can identify their ROM. The service holds those files until the folder resolves through its serial or title data. It then combines the folder into one save archive and exposes each member in the manifest. Member count and expanded size limits keep a malformed or oversized folder from becoming an unbounded transfer.
The RetroArch flow is:
flowchart LR
RA[RetroArch client] --> Manifest[Request manifest]
Manifest --> RomM[RomM Cloud Sync]
RomM --> Visible[Visible saves, states, and user files]
Visible --> Hashes[Content hashes]
Hashes --> Manifest
RA --> Files[Upload or download changed files]
Files --> RomM
RomM --> Library[User library assets]
The manifest is derived from RomM's current records. A client may send its manifest back, but the server does not treat that copy as authoritative. RomM maps equivalent core names to one RetroArch folder and uses that core's platform mapping when it resolves same-named games. It advertises one canonical state or save path for that shared identity. For a slotted RetroArch save, the service can expose the compatible current version of the user's autosave channel rather than an older lineage head. A channel-held save remains readable but cannot be replaced or removed through Cloud Sync. Stream-captured states remain history records rather than writable Cloud Sync targets, so a client does not overwrite or delete the capture that the player may still use. Manifest hashes are read from the stored files and cached by file identity; a changed file or a missing file causes the service to refresh its view. Access checks still apply to each ROM and to the user's asset area, so a file name collision or a hidden ROM cannot expose another library item. See Remote library sync for the broader remote synchronization model.
References: backend/…/retroarch.py• L123-177 backend/…/retroarch.py• L404-479 backend/…/retroarch.py• L580-733 backend/…/retroarch.py• L805-912 backend/…/sync_handler.py• L63-79 backend/…/sync_handler.py• L207-379 backend/…/sync_handler.py• L386-576 backend/…/sync_handler.py• L856-932 backend/…/sync_handler.py• L1039-1243 backend/…/emulator_names.py• L117-180 backend/…/psp.py• L1-5 backend/…/psp.py• L49-67 backend/…/psp.py• L68-111 backend/…/psp.py• L229-317 backend/…/psp.py• L363-493 backend/…/psp.py• L624-672
Sync transport
Remote clients can use a direct sync session or a server-triggered push-pull run. The server exposes sync status as durable session data and sends progress events over the realtime channel. This separates long file transfer from the request that starts it while still giving a client a live view of the work.
Push-pull runs use an SSH connection with SFTP to inspect configured save folders and move save files in both directions. The server first checks trusted host data. It uses a key mounted for the device when one exists and falls back to the device password when it does not. A key path supplied in device configuration is not used. Downloads are hashed before the sync plan uses them, so the transport can report the same save identity as the server-side comparison. The details of SSH transport, folder watching, and push-pull execution belong to Remote library sync.
This page treats direct sync and push-pull sync as one client service: a device exchanges saves with the server and reports the play data it collected. The transport must not decide which copy wins. The sync session remains responsible for that plan and for recording the result.
References: backend/…/sync.py• L425-455 backend/…/sync.py• L458-504 backend/…/sync.py• L1-127 backend/…/ssh_handler.py• L42-118 backend/…/ssh_handler.py• L120-207
WebDAV library browsing
The sync service also provides a read-only WebDAV view for generic clients that mount the library sync URL. It lists visible platforms and ROMs as browsable collections and files. A multi-file ROM appears as one downloadable archive so a client can treat each game as one file.
The view applies the caller's platform and ROM permissions while it builds the listing. It omits empty platforms and returns file size and update time for visible ROMs. RetroArch itself does not browse this view; the surface supports generic WebDAV clients without adding a write path to the library.
References: backend/…/browser.py• L1-15 backend/…/browser.py• L38-89 backend/…/browser.py• L92-129
Streaming services
Streaming services let the web client use a native emulator that runs outside the web process. The server maps a ROM to its platform and to a configured emulator container or container pool. Configuration resolves each usable platform and container pair into a common set of stream, save, and control capabilities. The client receives the container's stream address and uses the server as the control point for the active session.
Streaming sessions
Each container can serve one active session at a time. A claim is atomic, so two users cannot start games on the same container at once. Containers with the same emulator, protocol, core, memory-card behavior, and save-picker behavior form a pool. Claims try the first compatible pool in configuration order. A later incompatible pool is not a fallback for a game claim. The claim belongs to the user who made it and expires when heartbeats stop. Normal control calls keep it alive. The session owner also determines where states and saves are filed. A scoped administrator with users.write may control another user's session without changing that ownership. Non-owners cannot drive the session, while administrators with that scope may control another user's session under their elevated role. A player can also join a host's explicitly shared session without gaining control.
The streaming configuration is caller-scoped. It lists visible platform targets and sends the player the slot, memory-card, save-picker, live-state, import, and disc-swap capabilities for those targets. If a caller has no streaming grant, the service hides usable streaming targets instead of treating ROM read access as permission to start a remote emulator. backend/…/streaming.py.
Claims identify both the selected container and the time at which the claim was made. This keeps an old tab from acting on a later session after a takeover or a second play request. Pool lookup finds a user's active session across the pool. An administrator must name a container when more than one other session could match.
The claim response means that the container is reserved, not that the game is ready. Launch work can continue after the request returns. The player follows progress and ready or failed events, then uses status checks to recover from a missed event. The launch now keeps the claim alive while extraction and archive setup run. Each request carries the container and claim time when needed, so an old tab cannot control a later claim on the same container.
The launch request supplies a ROM identity rather than a filesystem path. The server checks ROM and platform visibility, resolves a suitable container from the platform's first compatible pool, and validates any selected resume state, save archive, or memory card before reserving it. Platform capability data defines valid state slots, autosave behavior, memory-card support, disc actions, and import kinds for the player. It also reduces the ROM language and the user's interface locale to broker language codes. Unknown values are omitted so the emulator can use its own default.
A long launch runs separately from the request. The client receives launch progress and then a ready or failed event, with status polling as a fallback. The claim remains held during extraction and file preparation, so another player cannot take the container before the first game is ready. The client can ask to adopt or discard a memory card when the container still holds one. A missing or unreachable broker aborts the launch and releases the claim rather than leaving an unusable reservation.
The service recovers abandoned sessions only when a new claim needs the container. It keeps a draining claim during stop and state collection so a new game cannot start over a running emulator or old memory card. The service also supports an administrator desktop session for container setup. A desktop session uses the same exclusive container ownership as a game but has no ROM, save, or play history attached. Desktop setup and fleet views require scoped administrator permissions rather than the administrator role alone. backend/…/streaming.py.
References: backend/…/access.py• L26-77 backend/…/access.py• L157-261 backend/…/access.py• L264-325 backend/…/broker.py• L26-53 backend/…/broker.py• L57-81 backend/…/capabilities.py• L180-259 backend/…/config.py• L159-233 backend/…/config.py• L296-338 backend/…/config.py• L612-771 backend/…/imports.py• L178-232 backend/…/launch.py• L41-224 backend/…/session_store.py• L33-73 backend/…/session_store.py• L191-248 backend/…/session_store.py• L288-357 backend/…/session_store.py• L397-465 backend/…/webstation.py• L157-253 backend/…/streaming.py• L338-388 backend/…/streaming.py• L397-438 backend/…/streaming.py• L834-1141 backend/…/streaming.py• L1268-1350 backend/…/streaming.py• L1635-1781 backend/…/streaming.py• L1784-1860 frontend/…/streaming.ts• L24-109 frontend/…/Stream.vue• L603-778
Streaming controls
The active stream supports the controls needed during a remote game: volume, mute, manual save state, load state, disc swap where supported, fullscreen, and save-and-exit. Platform capability data tells the client which save and media choices are valid. The client does not maintain a second set of slot rules.
The server refreshes session liveness during control calls and heartbeats. Save state requests start a background pull into the library, while load requests affect only the active emulator. State captures keep a history so a player can choose an earlier resume point. In-game save archives are restored before launch and pulled after exit. Webstation sessions use an export queue for exit archives, and RomM collects only the archive produced by the matching broker session. RetroArch exit archives can be unpacked into the library's save and state records when their manifest is complete; otherwise the archive remains as one save asset. A whole memory card can use the same boundary as one owned asset when the container opts into card sync. Save-and-exit uses the platform's autosave slot, waits for the emulator to stop when needed, collects the exit state or saves, records play time, clears live activity, and then makes the container available again. A joined viewer can watch and adjust its own stream view, but only the session owner can change emulator state or end the session. The client exposes these controls through one streaming service and uses platform capabilities to choose valid slots and media actions.
Disc changes stay inside the active ROM's base-game playlist. The service rejects a file from another ROM, a patch or translation, or a file that is not a valid base-game playlist entry before it reaches the emulator. This keeps multi-disc play tied to the game that owns the session and prevents non-disc variants from becoming swap targets. backend/…/streaming.py.
An ordinary release follows the same cleanup boundary and can run after the response so the player can leave at once. The claim remains held until the emulator is stopped and its card or exit data is safe to collect. Browser unload requests use a keepalive path so a page close can still request save-and-exit or release.
References: backend/…/archive.py• L7-44 backend/…/background.py• L1-10 backend/…/commands.py• L17-214 backend/…/memory_cards.py• L195-225 backend/…/memory_cards.py• L257-348 backend/…/saves.py• L103-235 backend/…/saves.py• L262-449 backend/…/saves.py• L452-506 backend/…/states.py• L358-451 backend/…/states.py• L455-537 backend/…/webstation.py• L345-441 backend/…/webstation.py• L489-560 backend/…/lifecycle.py• L114-220 backend/…/lifecycle.py• L371-439 backend/…/streaming.py• L1144-1264 backend/…/streaming.py• L1430-1583 backend/…/streaming.py• L1586-1633 frontend/…/streaming.ts• L147-187 frontend/…/streaming.ts• L204-252 frontend/…/Stream.vue• L1040-1174 frontend/…/Stream.vue• L1280-1374
Streaming teardown
Streaming teardown is the shared end-of-session process for player release, save-and-exit, administrator release, and abandoned sessions. It stops the emulator before it reads or wipes a synchronized memory card. It then records the owner's play time, clears live activity, files the exit state and saves, and releases the container claim.
The order protects both the old player's data and the next player's isolation. A drain marker keeps a container reserved while a long stop or state pull finishes. Save collection can run in a background worker, but the marker and per-ROM wait prevent the next claim from restoring data before the prior exit pull has filed it. If the browser disappears, a stale heartbeat allows the next claim to finish the same cleanup instead of leaving the container permanently occupied. The browser also sends save-and-exit or release through keepalive requests during page unload, so a normal page exit can still reach the cleanup boundary after the page starts to close.
References: backend/…/lifecycle.py• L39-126 backend/…/lifecycle.py• L129-220 backend/…/lifecycle.py• L371-457 backend/…/lifecycle.py• L459-531 backend/…/session_store.py• L330-430 backend/…/saves.py• L30-100 backend/…/streaming.py• L1144-1264 backend/…/streaming.py• L1586-1633 frontend/…/streaming.ts• L204-231
Multiplayer and streaming
Multiplayer services provide two forms of shared play. Netplay is shared browser play through a room and a realtime connection. Remote streaming can expose one native emulator session for other users to join. Both paths keep low-latency play separate from durable play history and save synchronization. See Netplay and streaming for the room and signaling workflow.
Netplay rooms
Room state lives outside an individual browser connection. A room can therefore survive normal socket handling until its players leave. The first player becomes the owner. If that player leaves while others remain, ownership moves to another player. An empty room is removed immediately. Periodic cleanup removes any empty rooms left behind.
The room list is scoped to a visible ROM and to the caller's emulation permission. It shows only rooms for the requested game that still have capacity. A caller without emulation read access receives no room list, so ROM visibility alone does not expose multiplayer activity.
References: backend/…/netplay_handler.py• L7-47 backend/…/netplay.py• L16-77 backend/…/netplay.py• L24-112 backend/…/netplay.py• L114-150 backend/…/cleanup_netplay.py• L6-30
Remote streaming rooms
A streaming host opts into multiplayer when the session starts. Other users can discover visible joinable sessions and request a room URL. The join path checks the host's ROM visibility and gives the joiner viewing access without granting control over emulator state or release. The player keeps host and joiner lifecycles separate: leaving a joined view does not stop the host's emulator or file collection.
References: backend/…/streaming.py• L1353-1427 backend/…/streaming.py• L1784-1827 backend/…/access.py• L46-116 backend/…/webstation.py• L277-298 frontend/…/streaming.ts• L133-145 frontend/…/Stream.vue• L137-164 frontend/…/Stream.vue• L788-800 frontend/…/Stream.vue• L1040-1089
Realtime play data
The socket path carries WebRTC negotiation messages to a selected peer and broadcasts game data to the other members of a netplay room. Input, snapshots, and general data messages are room events rather than durable library records. Streaming room membership uses the remote broker's room URL instead of turning stream traffic into library records.
The browser emulator's core selection can change when netplay needs a different EmulatorJS resource. Player configuration and multiplayer capability must therefore remain aligned.
References: backend/…/netplay.py• L152-224 backend/…/streaming.py• L917-920 backend/…/webstation.py• L277-298 frontend/…/EmulatorJS.vue• L252-280 frontend/…/index.ts• L591-610
Service boundaries
The player-facing systems share a ROM and user identity, but they do not share the same kind of state. Play sessions are durable history. Live activity and netplay messages are transient signals. Save records and sync marks describe durable game data. Streaming claims describe temporary ownership of an emulator container.
These boundaries explain why one player exit can perform several separate actions: stop the emulator, evacuate a memory card, flush a play interval, clear live activity, file exit state and saves, and release the container. The lifecycle keeps these actions ordered so a failed step does not silently change the meaning of another. A failed play flush can leave history stale, while a failed claim release can leave a container reserved for recovery.
References: backend/…/lifecycle.py• L108-173 backend/…/lifecycle.py• L249-371 backend/…/session_store.py• L198-255 backend/…/play_sessions.py• L25-139 frontend/…/EmulatorJS.vue• L402-443 frontend/…/JsDos.vue• L121-179 frontend/…/Stream.vue• L187-219
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the browser play gate aligned with each player route. A new engine must have matching platform support, file rules, and a valid runtime before the play action can offer it.
- Keep the common player shell's launch and exit contract aligned with every browser player. The shell must not leave input capture or a pending save behind when a player is unmounted.
- Keep runtime fallback rules aligned with the asset base used for emulator payloads. A local-versus-CDN change must not load the wrapper from one source and its emulator data from another.
- Keep library game-length bounds in seconds at the API boundary. Convert user-facing time values before building the ROM query and omit an unset bound so an open range stays open.
- Keep library readiness and supported-platform data aligned with the setup flow. A ready result must describe the platform choices that the player and catalog can use.
- Keep save and state selection separate when changing resume behavior. A state can change the in-game timeline that a later save writes back to a selected slot.
- Keep save version, dedupe, retention, and device conflict rules aligned between the multipart save API and every caller. An overwrite upload must remain an explicit choice, and an unload upload must use the same slot and device meaning as a normal upload.
- Keep snapshot-channel holds aligned with save upload, pruning, and sync comparison. A held current must not be overwritten or pruned as ordinary save history, and a client change must become a conflict or a new version at the channel boundary.
- Keep save visibility checks aligned across list, identifier, summary, per-save, content, confirmation, mutation, deletion, and device-tracking routes. A shared save must not bypass the ROM visibility boundary.
- Keep save response device summaries aligned with device tracking. When a caller asks with device context, preserve the caller-first ordering, the not-yet-tracked placeholder, and the distinction between the served server version and confirmed device bytes.
- Keep the play-session contract aligned between browser exit, streaming teardown, and sync completion. All paths must preserve ROM, device or container, save-slot, time, and duration data.
- Keep play-session batch validation and duplicate detection aligned with every producer. A producer must preserve the user, device, ROM, start-time identity, valid time order, and non-negative duration when it retries an interval.
- Keep save slot pairing rules aligned across negotiation, save upload, device sync status, and player controls. A null slot is an archive and is not a paired sync slot.
- Keep sync negotiation's visibility filter aligned with its deletion and conflict maps. A hidden client ROM must not be paired, reported as a conflict, or used to expose a hidden server save.
- Keep sync channel current, branch, and device-base rules aligned with the comparison result. A client copy from a removed current must not be uploaded as new progress, while a valid change from the device base must remain uploadable.
- Keep emulator and core filters aligned with the save records they can load. A client must not receive a save from an emulator or core that it did not advertise as supported.
- Keep the client save-slot contract aligned with device sync. Automatic progress uses
autosave, while the 255-character limit and explicit overwrite path must remain compatible with the server. - Keep sync session ownership and status transitions aligned across direct sync, background push-pull, progress events, and cancellation. A device must not report an old active session as the current run.
- Keep RetroArch path, manifest, and asset resolution aligned. Core aliases must share one folder and slot identity, channel currents must resolve only when the core can load them, and file names, screenshots, PSP save bundles, and user-level blobs must resolve to the same visible library assets for GET, PUT, and DELETE.
- Keep stream-captured state history separate from RetroArch Cloud Sync write targets. A capture may be served for the slot, but client uploads and deletes must continue to operate on the ordinary state record behind that slot.
- Keep RetroArch manifest hashing bounded and tied to file identity. A changed size or modification time must not reuse a stale digest, and an unreadable or missing asset must not be advertised as usable.
- Keep PSP folder buffering and bundle limits aligned with manifest and file operations. Files received before ROM resolution must not disappear, and a partial or oversized folder must not become an invalid save archive.
- Keep PSP metadata parsing bounded when changing folder resolution. Reject oversized
PARAM.SFOdata and ignore overlong titles before they become ROM search input. - Keep SSH trust and authentication inputs aligned with push-pull device setup. The server must use the known-hosts file and the key mounted for the same device, or use the configured password when no device key exists. A client-provided key path must not become an alternate credential source.
- Keep remote save metadata aligned with sync planning. Platform mapping, file path, modification time, size, and content hash must describe the same remote file used for download or upload.
- Keep WebDAV listing names aligned with the library content route. Platform slugs, ROM display names, multi-file archive names, URL escaping, and visibility filters must describe the same downloadable ROM that the mounted client can request.
- Keep streaming platform capabilities as one contract shared by the backend and the player UI. Do not add a second slot range or media rule in the client.
- Keep disc-swap validation tied to the session ROM's base-game playlist. A patch, translation, media file, file from another ROM, or file outside the base playlist must not reach the broker.
- Keep streaming container pools compatible when changing emulator, protocol, memory-card, core, save-picker, import, or disc-swap settings. A later incompatible pool is not a fallback for game claims.
- Keep streaming session ownership, ROM visibility, and permission scopes aligned. The owner controls the session and owns its saved data, scoped administrators need the required users permission for administrative actions, and ROM and platform visibility still limits what another caller can see.
- Keep streaming claim responses aligned with launch socket events and memory-card prompts. A 202 claim reserves the container first, while the browser must wait for the ready or failed event before treating the game as running.
- Keep the container-and-claim-stamp contract intact when changing session fields. Heartbeats, disc changes, launch stamps, drain markers, and releases must not let an old tab overwrite a newer claim or resurrect a deleted one.
- Preserve the order of streaming teardown. Stop the emulator before card evacuation, collect exit data before releasing the claim, and keep a drain marker while a pull is active.
- Keep unload requests equivalent to normal save-and-exit and release requests. They must preserve same-origin credentials, CSRF protection, container selection, and the server's autosave default.
- Keep streaming claim, heartbeat, join, and control scopes aligned with kiosk identity and scoped administrator rules. A shared synthetic user must not be allowed to own concurrent sessions that cannot be separated, and an administrator role without the required users scope must not control another user's session.
- Keep broker language inputs aligned with the shared RomM language values. Preserve region codes when known and omit unknown values so a launch falls back instead of sending an invalid code.
- Keep broker response limits and import refusal handling aligned with the player error contract. A bounded transfer must fail clearly instead of consuming unbounded memory or looking like a successful launch.
- Keep broker archive manifests aligned with archive readers and import writers. Member paths, save or state kinds, source labels, and bounded reads must describe the same files that launch and exit processing can safely use.
- Keep RetroArch exit archive parsing aligned with state history and save storage. A raw exit can be split only when its manifest, core, save file, and state names are all valid; otherwise retain the complete archive.
- Keep RetroArch core aliases aligned across web-player emulator names, sync folder names, state grouping, save lineages, and core platform mapping. A shared folder must not expose duplicate or mismatched assets.
- Keep netplay room membership and socket session data consistent for both explicit leave and disconnect paths. Otherwise stale players can block room capacity.
- Keep the netplay room list aligned with ROM visibility, emulation permission, game identity, and room capacity. A caller must not see rooms for a hidden game or a game it cannot play.
- Keep live activity events separate from durable play-session ingestion. A heartbeat or presence change must not replace the final play interval.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A ROM has no file or a DOS file is not a valid bundle | The browser can show a play action for a player that cannot boot the game | Apply the shared play gate before offering a browser player |
| A caller sends a game-length bound in hours instead of the API's seconds | The library returns the wrong games for the requested play-time range | Convert bounds to seconds and test both closed and open ranges at the API boundary |
| A local emulator asset returns an HTML app page | The runtime does not load even though the request looks successful | Check that the asset is JavaScript before injecting it, then use the known fallback |
| A user leaves DOS play while the final save is pending or unconfirmed | Recent browser changes can be lost or the user can trigger duplicate exit work | Block repeat exits and require an explicit discard choice after save failure |
| A play-session batch is empty, too large, or contains a non-positive time span | The request is rejected and no interval from that batch is accepted | Enforce the batch limit and validate every entry before shared ingestion |
| A client sends a play interval with an end time too far in the future | The interval is rejected and does not update play history | Validate time order and the server-side future limit before ingest |
| A retried interval changes its user, device, ROM, or start-time identity | The same offline or remote play can appear as multiple history records | Preserve the play-session identity across retries and compare it before insert |
| A device uploads an older save without overwrite after the server changed it | The upload is rejected instead of replacing newer server data | Compare the device sync mark with the current save and handle the conflict before retrying |
| A client confirms a download against the current server hash after the server has moved on | The device can be marked against the wrong version or remain falsely stale | Confirm the version recorded when the file was served, and use the current hash only when no served baseline exists |
| A client retries the same slotted save or lets a slot grow without a retention limit | Duplicate versions waste storage or old progress remains longer than intended | Use content-hash dedupe and apply the server and client slot-retention limits |
| A channel-held save is uploaded as an ordinary replacement | Snapshot history can be overwritten or the device can lose the channel's current | Treat held saves as protected and negotiate the upload as a conflict or new version |
| A channel current cannot be loaded by the selected RetroArch core | The client can receive a path whose bytes the core cannot use | Serve the newest compatible lineage version when the channel current is not loadable |
| A client uses an unstable or null slot for a save that should follow one slot | Negotiation treats the save as an archive or pairs it with the wrong server state | Use a stable non-null slot for synchronized saves |
| A client reports a version removed from a channel as new progress | A deleted or rolled-back version can return during the next sync | Compare the client hash with channel removal history before choosing upload |
| Automatic progress uses a different slot name or exceeds the server field limit | Device sync can stop pairing saves or reject the upload | Use the shared autosave slot and enforce the 255-character client limit |
| A caller requests a save or sync operation for a hidden ROM | The caller can learn about or change an asset outside its library view | Apply ROM visibility to every save route and to sync pairing, deletion, and conflict records |
| A RetroArch path contains traversal, an unsupported tree, or an overlong core name | The file is rejected instead of reaching a ROM or user asset | Accept only the supported save/state layout and safe path segments |
| Two visible ROMs share a file name and the path resolves without the core's platform mapping | A save or state can be shadowed, or a client can update a different game's asset | Resolve the visible ROM against the selected core's supported platforms before using fallback order |
| A RetroArch state or screenshot uses a non-canonical slot name | The client can miss the state or create a duplicate slot record | Map state names to the slot's newest asset and advertise the canonical name |
| A Cloud Sync client writes over or deletes a stream-captured state | The player can lose an earlier resume point or change history through a file-sync action | Serve the capture for the slot but direct writes and deletes to the non-capture state record |
| A RetroArch manifest includes an unreadable asset or a stale hash | The client can skip a needed transfer or request a file that is not present | Hash readable files with size and modification-time cache keys and mark missing assets |
| A PSP folder arrives before its ROM can be resolved | Its files can be lost or exposed under the wrong game | Buffer the folder by save name, then resolve it through the serial map or normalized title |
| A PSP save folder exceeds bundle limits or cannot resolve to a visible PSP ROM | The save cannot be merged safely and remains unavailable to the client | Bound bundle members and size, then use the serial map or normalized title match |
A PSP PARAM.SFO file or title is abnormally large | ROM matching can consume excessive worker memory or time | Reject files over the format-safe size and ignore titles over the defined field length |
| A device starts a second sync while its first run is still active | Progress and final status can describe different runs | Select and cancel active sessions by the same user and device identity |
| Push-pull starts without a trusted hosts file or without a device key or password | Remote save discovery and transfer cannot start | Require the known-hosts file and resolve the device's mounted key before using password fallback |
A device supplies an ssh_key_path for another mounted key | The device could authenticate as another device or the configured path is silently ignored | Resolve keys only from the server's device-key directory and document password fallback |
| A remote save path is missing or points to a non-file entry | That save is skipped and the device plan can be incomplete | Treat missing folders as a warning and accept only regular files with the configured extension |
| A downloaded remote save is compared without its content hash | The sync plan can treat changed content as unchanged or create a false conflict | Hash the downloaded file before it enters comparison |
| A WebDAV listing includes a hidden platform or ROM | A mounted client can discover content outside the caller's library access | Apply the caller's platform and ROM visibility filters while building the listing |
| A WebDAV display name does not match the content download name | The client sees a file that cannot be downloaded through the mounted path | Use the same single-file or multi-file archive naming rule as the content endpoint |
| A public state belongs to a ROM hidden from the caller | The caller could use the shared asset to discover or access a hidden game | Apply ROM visibility checks to state downloads and streaming resume choices |
A caller tries to control another user's streaming session without users.write scoped administrator access | The remote emulator or its saved data could be changed by the wrong user | Check session ownership and the scoped administrator permission before control, then use the session owner for saved-data records |
An administrator has the role but lacks the required users.read or users.write scope | Fleet views, desktop setup, force release, or another user's control is denied | Match each administrative route to its required scoped administrator permission |
| An old streaming tab sends a control call after its container has a new claim | The old player could change or release the new player's session | Bind the request to both the named container and its claim timestamp |
| Two users claim the same streaming container | One launch is refused and the existing user's session stays active | Use the atomic session claim and show the occupied-session result |
| A configured container has no valid stream host or reachable broker | The container appears in fleet data but no game can claim it | Require a valid stream host and broker address before adding it to a claim pool |
| A memory card needs a decision but the retry omits the choice | Launch remains blocked or the wrong card can be used | Surface the adopt-or-discard response and replay the choice on the claim |
| A streaming broker is unreachable during launch | The player cannot start and the server must not leave a stale claim | Remove the claim when launch fails and return a broker availability error |
| A caller lists netplay rooms without emulation permission or for a hidden ROM | The caller can learn about rooms it cannot join | Check ROM visibility and emulation read access before returning matching rooms |
Key files
| File | Why to read it |
|---|---|
| frontend/…/PlayerShell.vue | Defines the shared launch, running-stage, navigation, and quit boundary for browser players. |
| frontend/…/index.ts | Defines when a ROM is eligible for each browser player route. |
| frontend/…/rom.ts | Defines the library-facing requests that select ROMs for play and carry play-related library filters to the service. |
| frontend/…/setup.ts | Defines the readiness and platform information used before the library can serve player choices. |
| frontend/…/EmulatorJS.vue | Shows browser emulator setup, save and state selection, live activity, and play-session boundaries. |
| frontend/…/JsDos.vue | Shows DOS bundle loading, account-scoped browser changes, final save handling, and route exit behavior. |
| frontend/…/Ruffle.vue | Shows the Flash player path and its independent fullscreen and play-session lifecycle. |
| frontend/…/Stream.vue | Shows how a ROM becomes a remote stream and how controls save, stop, join, or release the remote session. |
| frontend/…/save.ts | Defines the client contract for save versions, device-aware updates, unload uploads, archival uploads, and visibility changes. |
| frontend/…/streaming.ts | Defines the client contract for streaming claims, launch events, controls, memory-card decisions, joins, and unload cleanup. |
| backend/…/saves.py | Defines save upload, snapshot-aware versioning, download confirmation, device-aware status, ROM visibility, conflict protection, and tracking boundaries shared by players and sync clients. |
| backend/…/__init__.py | Defines device sync negotiation, visible-ROM filtering, snapshot-aware comparisons, completion, play-session return, and push-pull launch boundaries. |
| backend/…/comparison.py | Defines how ordinary save baselines and snapshot-channel history become upload, download, conflict, delete, or no-op decisions. |
| backend/…/retroarch.py | Defines the RetroArch WebDAV contract for manifests, visible ROM resolution, save and state transfer, screenshots, and deletes. |
| backend/…/sync_handler.py | Maps RetroArch paths and core aliases to visible ROM assets and canonical save, state, and screenshot records. |
| backend/…/psp.py | Defines PSP folder matching, buffering, bounded bundles, and per-file manifest exposure. |
| backend/…/device_save_sync.py | Defines the per-device baseline used to compare server saves with device copies. |
| backend/…/user.py | Defines account roles, permission-group identity, kiosk identity, and user-owned player data. |
| backend/…/netplay.py | Defines the permission and ROM visibility checks for the list of joinable browser play rooms. |
| backend/…/streaming.py | Shows how scoped permissions protect launch, join, control, fleet, desktop, and release actions. |
| backend/…/access.py | Shows how session ownership, ROM and platform visibility, scoped administrator access, claim stamps, and container lookup protect streaming actions. |