Leaderboard
Available since
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe Leaderboard interface of the Room API is a collection declared with leaderboard settings in irt.config.ts, holding one score per player for each period it keeps. room.leaderboard(name) returns one.
Instance properties
Leaderboard.name- The leaderboard’s name. Read only.
Instance methods
Leaderboard.submit()- Applies a player’s score to every period the board keeps.
Leaderboard.top()- Resolves with a page of the best entries of a period.
Leaderboard.around()- Resolves with a player’s rank and the entries either side.
Leaderboard.refresh()- Does nothing, since leaderboard reads aren’t cached.
Description
- Periods. A board keeps any of
"all","day","week"and"month", as itsperiodssetting declares, in UTC; weeks are ISO weeks from Monday. Aperiodargument is one of those for the current period, or a full name such as"day:2026-11-06","week:2026-W45"or"month:2026-11"for one of the three before it. - Ranks go by score in the board’s
order, then by the earliestupdated. - Nothing is cached: every
top()andaround()is a call. - Errors. Calls reject with a
DataError.
Examples
Scoring a finished run
// time-trial.ts
import { defineRoom } from "@irtio/room";
export default defineRoom({
async onMessage(room, connection, message) {
const m = message as { type?: string; ms?: number };
if (m.type !== "finished" || typeof m.ms !== "number") return;
await room.leaderboard("laps").submit(connection.player, m.ms, { meta: { track: "canyon" } });
const best = await room.leaderboard("laps").top({ period: "week", limit: 5 });
room.broadcast({ type: "standings", entries: best.entries });
},
});
See also
Runtime availability
| Hosted rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
Leaderboard | 0.1 | 0.1 | 0.1 | 0.1 |