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.
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:
| Name | Type | Description |
|---|---|---|
avatarSize | 64 | 128 | 256 | 512 | 1000 | The size of the avatar to fetch. Defaults to 1000. |
Returns:
| Name | Type | Description |
|---|---|---|
username | string | The username of the currently logged in player. |
avatarUrl | string | null | The 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"]);
| 512x512 | 256x256 | 128x128 | 64x64 |
|---|---|---|---|
JestSDK.social.getBotAvatar()
getBotAvatar(
opts: {
username: string;
size?: 64 | 128 | 256 | 512 | 1000;
}
): string;
Options:
| Name | Type | Description |
|---|---|---|
username | string | Required. The username of the bot. |
size | 64 | 128 | 256 | 512 | 1000 | Optional. The size of the avatar. Defaults to 1000. |
Returns:
| Type | Description |
|---|---|
string | The URL of the bot avatar. |