Replay: message event
Available since
@irtio/client 5.0BrowsersNodeThe 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:
dataRead only- The message: JSON parsed, or a
Uint8Arrayfor a binary message. unreliableRead onlytrueif the room sent the message as unreliable.fromRead onlyundefined, 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
messageevent, a liveRoomClient’sRoom.record()Room.broadcast()
Runtime availability
| Browsers | Node | |
|---|---|---|
message event | 5.0 | 5.0 |