Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: how does server push notification to client #831

Open
SunHowe opened this issue Sep 5, 2024 · 1 comment
Open

Question: how does server push notification to client #831

SunHowe opened this issue Sep 5, 2024 · 1 comment

Comments

@SunHowe
Copy link

SunHowe commented Sep 5, 2024

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();
            }
        }
    }
@licentia88
Copy link

well what happens in the OnConnected method is that you are actually subscribing to a group named global and than you can broadcast to entire group, or to specific individual(s), so yes, you need use Group.AddAsync method.

what kind of subscribe/publish are you looking for ? Perhaps the technology you are looking for is

https://github.com/Cysharp/MessagePipe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants