Replay: privateOf() method
Available since
@irtio/client 5.0BrowsersNodeThe privateOf() method of the Replay interface returns a player’s private state at the tick shown, when the replay recorded private state.
Syntax
privateOf(player)
Parameters
player- A string: the player’s ID.
Return value
A read-only object with the private kind’s fields, or undefined if the replay holds no private state for the player at the tick shown, including when the recording didn’t record private state.
Exceptions
None.
Description
A room records private state only when it starts the recording with private: true; see Room.record(). Such a replay shows every player’s hand, so serve it only to those who may see it. The object is a copy of the values at the tick shown, so read it again after the tick changes.
Examples
Showing every hand after a poker game
A poker game’s replay viewer shows each player’s cards beside the table, read from their private state.
// hands.ts
import type { Replay } from "@irtio/client/replay";
export function hands(replay: Replay): Map<string, unknown> {
const out = new Map<string, unknown>();
for (const p of replay.presence) out.set(p.player, replay.privateOf(p.player)?.cards);
return out;
}
See also
Runtime availability
| Browsers | Node | |
|---|---|---|
privateOf() | 5.0 | 5.0 |