Loading & switching games
Load registry releases or local projects, and switch games without disconnecting players.
A room runs one game at a time, but it doesn't have to be the same game all day. A room can switch games while players stay connected, which is how a room offers a choice of games or updates to a new release without kicking anyone out.
Where a game comes from
The game option of Room.launch, and room.load, accept three kinds of
source:
game value | Source |
|---|---|
"ns/slug@version" | a registry release, authorized by the room's credential and cached by digest |
{ path: "<dir>" } | a game project, built in memory exactly like disko publish --dry-run |
{ path: "<file>.tgz" } | a local archive, for example from disko publish --dry-run --out |
Use a registry release in production. The two local forms are for
development and testing: they skip the registry and its access checks, and
ignore the game address in their game.json. All three go through the same
checks as publishing, so a game that loads locally will also publish.
Relative paths resolve from the current directory.
Switching games
room.load(game, options?) replaces the running game with another. The switch
is all-or-nothing: the new game is fully prepared before it takes over, so if
anything goes wrong, nothing changes for the players.
On success, load resolves to the new game's { reference, path, digest }
once it's Ready. On failure it rejects with a DiskoError (game_not_found,
game_removed, game_invalid, game_build_failed or game_start_failed),
and the previous game keeps running:
options.players sets the new game's name policy, as the players launch
option does for the first game. It does not carry over: without it, the new
game uses { name: "display" }. room.game always describes the loaded game,
including the permissions it declares.
Access and deprecation
A room can only load releases its owner is allowed to read, and that's checked every time, so taking away access takes effect on the next load.
A room re-authorizes every registry load, even from its cache. A private release the room's owner cannot read fails with
game_not_found, the same as a missing one; a release taken down fails withgame_removed.Revoking access never stops a room already running that game.
A deprecated release loads normally; the warning appears in
game-loadedand the log: