Groups
This document describes group-scoped messaging in the current PlayServ Unity SDK.
What groups mean in current SDK
In current client facade, a group is a routing scope represented by groupName string.
Group scope is used with event publish APIs:
PlayServ.PublishForGroup(groupName, eventPayload)PlayServ.PublishForUser(userId, eventPayload)
Event payload used in examples
using System;
using Playserv.Events;
[Event(EventType.All)]
[Serializable]
public struct SampleChatEvent
{
public string SenderId;
public string Text;
public long SentAtUnixMs;
}Publish to group
PlayServ.PublishForGroup("demo-group", new SampleChatEvent
{
SenderId = "player-001",
Text = "Hello group",
SentAtUnixMs = System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
});You can use composite names for match/session scopes:
var groupId = "match-42";
var scopedGroupName = $"GameSession:{groupId}";
PlayServ.PublishForGroup(scopedGroupName, new SampleChatEvent
{
SenderId = "player-001",
Text = "Hello match",
SentAtUnixMs = System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
});Subscribe to messages
var chatSubscription = PlayServ.Subscribe<SampleChatEvent>(evt =>
{
Debug.Log($"[{evt.SenderId}] {evt.Text}");
});
// later
chatSubscription.Dispose();User-targeted publish
PlayServ.PublishForUser("player-002", new SampleChatEvent
{
SenderId = "player-001",
Text = "Private message",
SentAtUnixMs = System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
});Group actions via RPC
If you need domain logic (permissions, join policy, moderation), implement it on backend RPC service and invoke from client:
PlayServ.Invoke(
nameof(NotificationService),
nameof(NotificationService.NotifyGroup),
new { groupName = "demo-group", message = "Group RPC call" });Example server-side RPC service:
[Rpc]
public sealed class NotificationService
{
public void NotifyGroup(string groupName, string message)
{
PlayServ.PublishForGroup(groupName, new NotificationEvent
{
EventId = System.Guid.NewGuid().ToString(),
Message = message,
Timestamp = System.DateTime.UtcNow,
EventType = "GroupNotification"
});
}
}Notification payload used in RPC example
using Playserv.Events;
public sealed class NotificationEvent : Event
{
}Current limitations
The current client SDK facade does not expose dedicated APIs for:
Group.Join()/Group.Leave()- group member list retrieval
- built-in join/leave lifecycle events
If your game requires these flows, implement them explicitly through backend RPC + events.
Summary
Groups in current SDK are event-routing scopes addressed by groupName. Group behavior policies are implemented on backend side and consumed through RPC and event streams.
Last updated on