Leaderboard: top() method

Available since @irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room host

The top() method of the Leaderboard interface resolves with a page of the best entries of a period, best first.

Syntax

top()
top(options)

Parameters

options Optional

An object with any of these properties:

period
The period, as the Leaderboard page describes. Defaults to "all".
limit
The most entries in the page, from 1 to 100. Defaults to 20.
after
The next of the page before, for the page after it.

Return value

A Promise that resolves with { entries, next }. next is null on the last page. Each entry is an object with these properties:

rank
Its rank, from 1.
player
The player’s ID.
score
The score the period keeps for the player.
meta
The meta the last submit gave.
updated
When the entry was last written, in wall-clock milliseconds.

Exceptions

The promise rejects with a DataError.

Description

top() is never cached, so call it on an event or every few seconds rather than every tick.

Examples

Showing today’s top ten in the lobby

// daily.ts
import { defineRoom } from "@irtio/room";

export default defineRoom({
  async onJoin(room, connection) {
    const { entries } = await room.leaderboard("points").top({ period: "day", limit: 10 });
    room.send(connection, { type: "today", top: entries.map((e) => ({ rank: e.rank, player: e.player, score: e.score })) });
  },
});

See also

Runtime availability

Hosted roomsirt dev@irtio/testingSelf-hosted room host
top()0.10.10.10.1