Replay: play() method

Available since @irtio/client 5.0BrowsersNode

The play() method of the Replay interface plays the replay from the tick shown, a tick at a time at speed times the room’s tick rate, until the last tick or pause().

Syntax

play()

Parameters

None.

Return value

None (undefined).

Exceptions

None.

Description

Each tick played is shown as step() shows it: a message event fires for each broadcast recorded in it, then the entity and presence callbacks, then the tick event. At the last tick, playback stops and the ended event fires.

play() does nothing while the replay is playing or at its last tick. To play again from the start, seek() to firstTick first. A change to speed takes effect from the next tick.

Examples

Toggling playback with the space bar

A replay viewer plays and pauses with the space bar, and starts over once the replay has ended.

// space-to-play.ts
import type { Replay } from "@irtio/client/replay";

export function bindSpace(replay: Replay): void {
  addEventListener("keydown", (e) => {
    if (e.code !== "Space") return;
    e.preventDefault();
    if (replay.playing) return replay.pause();
    if (replay.tick === replay.lastTick) replay.seek(replay.firstTick);
    replay.play();
  });
}

See also

Runtime availability

BrowsersNode
play()5.05.0