Replay: state property
Available since
@irtio/client 5.0BrowsersNodeThe state read-only property of the Replay interface is the room’s shared state at the tick shown, as RoomClient.state is on a live client.
Value
A client entity of the schema’s state kind, with its fields as properties. Its fields are typed any, since the kinds a replay holds are known only once it’s loaded, so give them their types where you read them.
Description
The shared state is entity 0 of entities, so replay.entities.onChange(schema.state, callback) fires when it changes during playback.
Examples
Showing the score at the tick shown
A replay viewer shows the score after each tick.
// replay-score.ts
import type { Replay } from "@irtio/client/replay";
export function showScore(replay: Replay, label: HTMLElement): void {
replay.addEventListener("tick", () => {
const home: number = replay.state.home;
const away: number = replay.state.away;
label.textContent = `${home} : ${away}`;
});
}
See also
Runtime availability
| Browsers | Node | |
|---|---|---|
state | 5.0 | 5.0 |