Friends
Finding Friends
FindFriends(userIds) asks the server for the current online and room status of the given user ids.
It returns a Task<Result<std::vector<FriendInfo>>> with one entry per requested id.
Friends are identified purely by UserId, so friend queries only work when players authenticate with stable, known user ids.
The SDK does not store a friend graph, who is friends with whom lives in your backend or platform service; the server only reports the live status of the ids you pass in.
| Field | Type | Description |
|---|---|---|
UserId |
StringType |
The id this entry describes. |
IsOnline |
bool |
Whether the user is currently online. |
RoomName |
StringType |
The room the user is in, empty when not in a room. |
IsInRoom |
bool |
Whether the user is currently in a room. |
Look up two friends and join the first one who is in a room:
C++
Task<Result<void>> JoinAFriend(RealtimeClient& client)
{
std::vector<RealtimeCore::Common::StringType> friendIds = {PHOTON_STR("erwin"), PHOTON_STR("theodor")};
Result<std::vector<FriendInfo>> friends = co_await client.FindFriends(friendIds);
if (friends.IsErr())
{
co_return Result<void>::Err(friends.GetError());
}
for (const FriendInfo& info : friends.GetValue())
{
if (info.IsInRoom)
{
Result<MutableRoomView> joined = co_await client.JoinRoom(info.RoomName);
if (joined.IsErr())
{
co_return Result<void>::Err(joined.GetError());
}
co_return Result<void>::Ok();
}
}
co_return Result<void>::Err(ErrorCode::RoomNotFound, PHOTON_STR("No friend is in a room right now"));
}
The Friend List
GetFriendList() returns the most recently fetched results without a server round trip, and GetFriendListAge() reports the age of that snapshot in milliseconds.
Use the age to decide when a refresh warrants a new FindFriends() call instead of re-querying on every frame.