Skip to content

RemoteSession beta ​

Class of @v12-engine/engine

ts
export declare class RemoteSession implements GameSession

A player's seat at a world that runs elsewhere, over a transport (see connect). It rebuilds what the host sends as changes (Delta) into whole snapshots, keeping the objects of what did not change, says which ticks it got, and answers the screen's questions from those and its own copy of the map (ClientWorld). No debug access, and no checkpoints: those belong to a simulation in the page

Members ​

constructor ​

ts
constructor(transport: Transport, welcome: Extract<GameHostMessage, {
        type: 'welcome';
    }>, registry: Registry, map: ClientWorld, 
    limits?: PlayerLimits);

Constructs a new instance of the RemoteSession class

alpha ​

ts
alpha: number;

How far, 0..1, the shown tick is between the last two snapshots, for blending the drawing

cameras ​

ts
readonly cameras: readonly MapCamera[];

The map's named camera positions from the welcome

camps ​

ts
camps(): readonly CampInfo[];

The creep camps as the newest frame has them

can ​

ts
readonly can: SessionCan;

A seat over a wire can none of what a game in this page can (SessionCan), but the debug tools' view of the world for a player the host lets use them (inspect, said over the wire)

canPlace ​

ts
canPlace(unitType: string, point: Vec2): boolean;

Whether the player could build this here, as far as they can tell: on their copy of the map, with the structures they know, on ground they have explored. The game's own say (the canPlace hook) is the host's: it may still refuse

debugView ​

ts
protected get debugView(): SessionDebug | undefined;

The debug tools' view of the world, for a player the host lets use them (the welcome's debug)

delay ​

ts
get delay(): number;

How far behind the newest snapshot the screen is shown, in ticks: about two snapshots, and room for the jitter

disconnected ​

ts
get disconnected(): boolean;

Whether the host has gone

dispose ​

ts
dispose(): void;

Stops pinging, closes the connection and frees the navigation made from the ground

doodads ​

ts
readonly doodads: readonly MapDoodad[];

The map's scenery objects from the welcome

environment ​

ts
readonly environment?: MapEnvironment;

The map's look (sky, mist, light) from the welcome, when it has one

failure ​

ts
failure: {
        message: string;
    } | null;

Why the game ended on an error in its rules, once the host said so

findPath ​

ts
findPath(from: Vec2, to: Vec2, flying?: boolean): Vec2[] | null;

A path over the ground the player has, on the air layer when flying; null when there is none

fog ​

ts
fog(): FogState;

The team's fog as built from what the host sent

formationPlaces ​

ts
formationPlaces(units: readonly (FormationUnit & {
        readonly flying?: boolean;
    })[], point: Vec2, facing?: number, formation?: string): Map<EntityId, Vec2>;

Where a group would stand sent to a point in a formation, rows when none is named: the rules are the host's (GameSession.formationPlaces)

interval ​

ts
protected interval: number;

Ticks between two snapshots, evened out

jitter ​

ts
protected jitter: number;

How far off the time snapshots arrive at is from the ticks between them, in seconds, evened out

limits ​

ts
protected readonly limits: PlayerLimits;

How much it keeps and how often it asks (ConnectOptions)

observer ​

ts
readonly observer: boolean;

Whether the player only watches, and sees everything

onDisconnect ​

ts
onDisconnect?: () => void;

Told when the connection drops, not by this side's leaving (dispose): to try again (resume), or to say the game is lost

onPause ​

ts
onPause?: (pause: {
        player?: PlayerId;
        until?: number;
    } | null) => void;

Told each time the server pauses the game or lets it go on

onServer ​

ts
onServer?: ConnectOptions['onServer'];

Told of what the host says besides the game: a server's messages (see ConnectOptions.onServer)

paths ​

ts
readonly paths: readonly MapPath[];

The map's named paths from the welcome

pause ​

ts
pause: {
        player?: PlayerId;
        until?: number;
    } | null;

The game paused by the server, for everyone: by a player (player, until a time at most, in Date.now()'s milliseconds) or an admin (neither). Null while it goes on

ping ​

ts
ping?: number;

Milliseconds a message takes to the host and back, evened out: measured every couple of seconds

placeCells ​

ts
placeCells(unitType: string, point: Vec2): readonly boolean[] | undefined;

Which cells of a building's ground are in the way, as canPlace sees them: on the player's copy of the map, explored

playerId ​

ts
readonly playerId: PlayerId;

The player this seat plays, as the host welcomed it

receive ​

ts
receive(message: HostToPlayer): void;

Takes in a message of the host's: what the transport hands it, and what came in while the session was made

regions ​

ts
readonly regions: readonly MapRegion[];

The map's named regions from the welcome

registry ​

ts
readonly registry: Registry;

The definitions of the game, from the rules the player connected with

resume ​

ts
resume(transport: Transport): Promise<void>;

Goes on with the same game over a new connection, once the host has welcomed it there again (a server does, to who comes back with their seat's token): everything known sent again, and the screen catches up. What the host says besides the game before the welcome goes to onServer; a refused fails it with the reason, as does a connection that closes first, or a host that runs another game

send ​

ts
send(command: PlayerCommand): number;

Sends a command to the host and returns the number it was given, which the host's answer names; does nothing once closed

shownAt ​

ts
get shownAt(): number;

The tick the screen is shown at, between two snapshots: behind the newest by delay

snapshot ​

ts
snapshot(): Snapshot;

The newest snapshot the host sent

takeGame ​

ts
takeGame(game: Rules): void;

Takes a new version of the game into this screen's registry (hot reload, a game in a worker): its definitions as the new version has them, what the host changed of them while it ran over them again

team ​

ts
team: number;

The team of that player; updated when a snapshot says it changed

tell ​

ts
tell(message: {
        type: string;
    } & Record<string, unknown>): void;

Says something to the server beside the game: a lobby's message ({ type: 'resume' })

terrain ​

ts
readonly terrain: Terrain;

The ground, built from the welcome and the parts the host sent

tickRate ​

ts
readonly tickRate: number;

Simulation ticks per second the host runs at, from the welcome

update ​

ts
update(dt: number): Snapshot[];

Lets the screen's clock go on by dt, and gives out the snapshots it has come to, oldest first: the screen draws between the last two (alpha). The time is the host's: the clock follows the snapshots, not the other way around

waiting ​

ts
get waiting(): number;

Snapshots come in and not yet given to the screen (update): a few normally, never more than a few seconds of them, however long the screen does not ask