Skip to main content
Worker-safe. The canonical replay artifact and the tools to load and scrub it.

Install

Envelopes

SavedReplayEnvelope<TPlayers, TMatchData>

Serializable JSON artifact produced by a completed or in-progress match.

SavedReplayVersion

Currently 1. Bumps when the envelope format changes in an incompatible way.

SavedReplayMetadata

Arbitrary JSON attached to an envelope.

Creating envelopes

createSavedReplayEnvelope(options)

Build an envelope from explicit parts.

createSavedReplayFromSession(options)

Build an envelope from a LocalGameSession (or anything exposing getReplayData):

Serialization

  • serializeSavedReplay(envelope) — produce a JSON string.
  • parseSavedReplay(text) — parse a string back into an envelope, validating the version and shape.
  • parseSavedReplayValue(value) — parse a JSON value without going through text.
All three throw with clear errors on mismatch.

Timelines

ReplayTimeline<TGame>

In-memory replay, suitable for an inspector.

ReplayFrame<TGame>

ReplayBranch

A branching timeline created with addReplayBranch.

materializeReplay(game, options)

Replay an explicit action list against a fresh session:

materializeSavedReplay(game, envelope)

Shortcut: take an envelope, return a timeline.

ReplayMaterializeOptions<TGame>

Branching is layered on top with addReplayBranch after materialization — it is not an option on the materialize call.

Playback

createReplayCursor(timeline)

Cursor-based navigation.
Every method returns the new cursor state. ReplayCursorState<TGame> is { branch, currentFrame, isPlaying, speed }.

addReplayBranch(timeline, actionID, branchID, parentBranchID?)

Fork a new branch at a given action. Returns a new timeline.

See also