ClientLeaderboard

Available since @irtio/client 5.0BrowsersNode

The ClientLeaderboard interface of the Client API is a leaderboard as a client sees it: the Room API’s Leaderboard, with submit() and around() for the player the client is. DataClient.leaderboard() and RoomClient.leaderboard() return one.

Instance properties

ClientLeaderboard.name
The board’s name, as irt.config.ts declares it. Read only.

Instance methods

ClientLeaderboard.submit()
Applies this player’s score to every period the board keeps.
ClientLeaderboard.top()
Resolves with a page of the best entries of a period.
ClientLeaderboard.around()
Resolves with a player’s rank and the entries either side, this player’s by default.

Description

Reading a board needs its clientRead: true, and submitting needs its clientWrite: "own". Periods, ranks and the keep rule are as the Description section of Leaderboard describes. Nothing is cached: every top() and around() is a call to the router.

A score a client submits can be faked: any player can send any number. Submit from room code, which decides the score, for any board that matters.

Examples

Submitting a run and showing the standings

After a run, the client submits the player’s points and shows the day’s top five.

// arcade-run.ts
import { dataClient } from "@irtio/client";

const board = dataClient().leaderboard("arcade");

export async function finishRun(points: number) {
  await board.submit(points);
  const { entries } = await board.top({ period: "day", limit: 5 });
  for (const e of entries) console.log(`${e.rank}. ${e.player} ${e.score}`);
}

See also

Runtime availability

BrowsersNode
ClientLeaderboard5.05.0