ClientLeaderboard: around() method
@irtio/client 5.0BrowsersNodeThe around() method of the ClientLeaderboard interface resolves with a player’s rank in a period and the entries either side of theirs, or undefined when the player has no entry there. The player is this client’s unless you name another.
Syntax
around()
around(options)
Parameters
optionsOptional-
An object with any of these properties:
player- A string: the player’s ID. Defaults to the player the client is.
period- A string: the period, as the Description section of
Leaderboarddescribes. Defaults to"all". count- A number: how many entries to give on each side of the player’s, from 0 to 10. Defaults to 2.
signal- An
AbortSignalthat aborts this call.
Return value
A Promise that resolves with { rank, entries }, or undefined. rank is the player’s rank, and entries holds the player’s entry with up to count on each side, each as top() gives them.
Exceptions
DataError- Rejects with this if the read fails, such as with
E_FORBIDDENwhen the board doesn’t haveclientRead: true,E_INVALIDfor acountout of range orE_UNKNOWNwhen the board isn’t declared. An aborted call rejects withE_UNAVAILABLE, namedAbortError, orTimeoutErrorfor anAbortSignal.timeout(), with the signal’s reason as itscause.
Description
Without a player, around() needs the client’s player ID, so a client without a token gets a guest first. With a player, it goes without a token until the client has one, as top() does, and with the project’s players.readLeaderboardsWithoutToken on it needs no guest.
around() is never cached.
Examples
Showing a friend’s rank
A profile screen shows where a friend stands this month, and says so when they haven’t played.
// friend-rank.ts
import { dataClient } from "@irtio/client";
const board = dataClient().leaderboard("points");
export async function friendRank(friend: string) {
const near = await board.around({ player: friend, period: "month", count: 1 });
return near ? `#${near.rank} this month` : "no games this month";
}
See also
ClientLeaderboard.top()Leaderboard.around(), the same from room code- Player data, collections and leaderboards
Runtime availability
| Browsers | Node | |
|---|---|---|
around() | 5.0 | 5.0 |