Cysharp / MagicOnion

Unified Realtime/API framework for .NET platform and Unity.
MIT License
3.8k stars 424 forks source link

Add StreamingHub OnConnected support #745

Closed riversdark0 closed 6 months ago

riversdark0 commented 6 months ago

In my project, I need send current game state to the client after the client connect or reconnect to the hub without client call the server, I tried overriding the StreamingHubBase.OnConnecting method, then send game state to the client in this method, but sometimes the following exception is thrown:

System.InvalidOperationException: Response headers can only be sent once per call. at Grpc.AspNetCore.Server.Internal.HttpContextServerCallContext.WriteResponseHeadersAsyncCore(Metadata responseHeaders) at Grpc.Core.ServerCallContext.WriteResponseHeadersAsync(Metadata responseHeaders) at MagicOnion.Server.Hubs.StreamingHubBase`2.HandleMessageAsync() in ./MagicOnion.Server/Hubs/StreamingHub.cs:line 164

So I think need add an OnConnected method and call it after sending headers and marker.

mayuki commented 6 months ago

Thank you for your contribution! It looks good to me.