SetPresenceAsync
method in Coherence.Cloud.FriendsService
Methods
public FriendsOperation SetPresenceAsync(string presence, CancellationToken cancellationToken = default)
Broadcasts online presence on this player account to its friends.
Parameters
| Type | Name | Description |
|---|---|---|
| string | presence | Pass null or empty string to clear online presence. coherence Cloud currently accepts up to 512 bytes of UTF-8 text without null characters, and fails a longer one with Coherence.Runtime.ErrorCode.PresencePayloadInvalid rather than truncating it. |
| CancellationToken | cancellationToken | Cancels the request. |
Returns
| Type | Description |
|---|---|
| FriendsOperation |
Remarks
Received through OnFriendPresenceChanged and Presence.
coherence Cloud currently accepts up to 120 presence updates a minute, counting SetAppearOfflineAsync(bool, CancellationToken), and fails the rest with Coherence.Runtime.ErrorCode.PresenceRateLimited.
Examples
using Coherence.Cloud;
using UnityEngine;
class FriendsPresence : MonoBehaviour
{
async void Start()
{
// Wait until a player account has logged in to coherence Cloud.
// The CoherenceCloudLogin component can be used for this.
PlayerAccount playerAccount = await PlayerAccount.GetMainAsync();
var friends = playerAccount.Services.Friends;
friends.OnFriendPresenceChanged += friend =>
{
if (!friend.IsOnline)
{
Debug.Log($"{friend.DisplayName} left. Last seen {friend.LastOnlineAt}.");
return;
}
Debug.Log($"{friend.DisplayName} is playing: {friend.Presence}");
};
await friends.RefreshFriendsAsync();
await friends.SetPresenceAsync("in the lobby");
foreach (var friend in friends.Friends)
{
if (friend.LobbyIds.Count == 0)
{
continue;
}
await playerAccount.Services.Lobbies.JoinLobbyAsync(friend.LobbyIds[0]);
break;
}
}
}
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | This service has been disposed. Thrown at the call site rather than reported through the returned request. |