Replay: message event

Available since @irtio/client 5.0BrowsersNode

The message event of the Replay interface fires for each broadcast the room recorded, when play() or step() passes the tick it was sent in.

Syntax

addEventListener("message", (event) => {})

Event type

A RoomMessageEvent. It extends Event and adds these properties:

data Read only
The message: JSON parsed, or a Uint8Array for a binary message.
unreliable Read only
true if the room sent the message as unreliable.
from Read only
undefined, since the room sent every message in a replay.

Description

A room records its broadcasts only when it starts the recording with messages: true, and never what it sends with Room.send(); see Room.record(). A seek() skips the messages between the two ticks.

The messages of a tick fire before its entity callbacks and its tick event.

Examples

Replaying the kill feed

A shooter broadcasts each kill, so its replay viewer shows the kill feed as the match plays.

// kill-feed.ts
import type { Replay } from "@irtio/client/replay";

interface Kill {
  type: "kill";
  by: string;
  victim: string;
}

export function killFeed(replay: Replay, post: (line: string) => void): void {
  replay.addEventListener("message", ({ data }) => {
    const m = data as Partial<Kill>;
    if (m.type === "kill") post(`${m.by} took out ${m.victim}`);
  });
}

See also

Runtime availability

BrowsersNode
message event5.05.0