Is there a way to get number of connections in Signalr hub group?

后端 未结 2 670
無奈伤痛
無奈伤痛 2021-01-02 16:29

Here is my problem, I want to track if user is online or offline and notify other clients about it. I\'m using hubs and implemented both IConnected and IDisconnect interface

相关标签:
2条回答
  • 2021-01-02 16:37

    There's not way to do this other than counting on your own.

    0 讨论(0)
  • 2021-01-02 16:37

    Found how to workaround:

    Rewrite ConnectionId, so in every tab you'd have the same ConnectionId:

     public class MyConnectionFactory : IConnectionIdGenerator
        {
            public string GenerateConnectionId(IRequest request)
            {
                return MyUserManager.Instance.CurrentUserID.ToString();
            }
        }
    

    Add to global.asax:

    GlobalHost.DependencyResolver.Register(typeof(IConnectionIdGenerator), () => new MyConnectionFactory());
    

    I managed to open as much tabs, as I could and all tabs get notifications.

    0 讨论(0)
提交回复
热议问题