MagicOnion
MagicOnion copied to clipboard
Question: how does server push notification to client
Can I only push messages from the server to a client in the following way? Is any way to push notification without Group.AddAsync
?
public interface IGameHub : IStreamingHub<IGameHub, IGameHubReceiver>{}
public interface IGameHubReceiver
{
void OnReceiveMessage(Message message);
}
public sealed class GameHub : StreamingHubBase<IGameHub, IGameHubReceiver>, IGameHub
{
private IGroup group;
private bool isConnected = false;
protected override async ValueTask OnConnected()
{
isConnected = true;
group = await Group.AddAsync("Global");
}
protected override ValueTask OnDisconnected()
{
isConnected = false;
return ValueTask.CompletedTask;
}
private async ValueTask LoopLogic()
{
while (isConnected)
{
BroadcastToSelf(group).OnReceiveMessage("Some message");
await Task.Yield();
}
}
}