Skip to main content

Social

It is common for games to include social features for interactions between players. Each user on Jest can set up their profile with a username and a customizable avatar. This is an optional feature and some users may not have a profile yet and guest users will not have one. You should always account for that, and use reasonable fallbacks for displaying player info in your game.

Player profile

After the SDK is initialized, you can get the current user's profile, otherwise the call will throw an error. See SDK initialization for more information.

function exampleGetProfile() {
const profile = JestSDK.social.getProfile();

return {
username: profile?.username ?? "You",
avatarUrl:
profile?.avatarUrl ??
"https://jest.com/public/avatar/avatar-placeholder.webp",
};
}

The method will work for both registered and guest players. For guest players or players who haven't set their profile up yet, the profile or parts of it will be null.

You should always account for that, and use reasonable fallbacks for displaying player info in your game.

Placeholder avatar

The placeholder avatar.

To ensure a good experience for users, the requested avatar can be 64x64, 128x128, 256x256, 512x512, or 1000x1000 pixels. Use the size that best fits your UI for the least amount of network traffic and the best visual quality.

JestSDK.social.getProfile({ avatarSize: 128 });

JestSDK.social.getProfile()

getProfile(options?: {
avatarSize: 64 | 128 | 256 | 512 | 1000
}): {
username: string;
avatarUrl: string | null;
} | null;

Options:

NameTypeDescription
avatarSize64 | 128 | 256 | 512 | 1000The size of the avatar to fetch. Defaults to 1000.

Returns:

NameTypeDescription
usernamestringThe username of the currently logged in player.
avatarUrlstring | nullThe URL of the avatar of the currently logged in player.

Bots

When games need to fill in some player slots with bots, we recommend using bot avatars. There are enough unique combinations to ensure that it's unlikely for two usernames to have the same avatar. You can request them using the getBotAvatar method. They are generated deterministically, so the same username will always return the same avatar.

The avatar sizes are the same as for player avatars: 64x64, 128x128, 256x256, 512x512, and 1000x1000 pixels. It is recommended to request the smallest size that fits your UI for the best performance, as this will minimize network traffic and improve loading times.

function getBots(usernames: string[]) {
const avatars = [];

for (const username of usernames) {
avatars.push({
username,
avatar: JestSDK.social.getBotAvatar({ username, size: 128 }),
});
}

return avatars;
}

getBots(["Hello", "Jest", "Bots"]);
512x512256x256128x12864x64

JestSDK.social.getBotAvatar()

getBotAvatar(
opts: {
username: string;
size?: 64 | 128 | 256 | 512 | 1000;
}
): string;

Options:

NameTypeDescription
usernamestringRequired. The username of the bot.
size64 | 128 | 256 | 512 | 1000Optional. The size of the avatar. Defaults to 1000.

Returns:

TypeDescription
stringThe URL of the bot avatar.