RoomDefinition: privateRetention property
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe privateRetention property of a room definition sets how long a player’s private state is kept after the player was last connected, so a room many players pass through doesn’t keep everyone’s forever.
Value
A positive number of milliseconds, or "forever" to keep private state as long as the room. Defaults to PRIVATE_RETENTION, 24 hours.
Exceptions
defineRoom() throws a RangeError for a privateRetention that isn’t a positive number of milliseconds or "forever".
Description
Private state is kept by player ID, so a player who reconnects or rejoins within the retention gets theirs back. Once a player has been away for privateRetention of wall-clock time, hibernated time included, the room drops their private state. The room checks on wake and every 30 seconds.
Private state that room.private(player, { create: true }) made for a player who hasn’t connected counts its retention from when it was made. With "forever", private state made for an ID that never joins is never dropped, so create it only for IDs you trust.
Examples
Keeping a week of progress
// dungeon.ts
import { defineRoom, defineSchema, entity } from "@irtio/room";
const Progress = entity("progress", { floor: "u8", gold: "u32" });
export default defineRoom({
schema: defineSchema({ private: Progress }),
privateRetention: 7 * 24 * 3600_000,
onJoin(room, connection) {
const progress = room.private(connection);
if (progress.floor === 0) progress.floor = 1;
},
});
See also
Runtime availability
| Hosted rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
privateRetention | 0.1 | 0.1 | 0.1 | 0.1 |