question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IOnlineClientManager.GetAllClients always returns zero

See original GitHub issue
  • Your Abp package version: 6.0.0
  • Your base framework: .NET Framework
using Abp.Dependency;
using Abp.Notifications;
using Abp.RealTime;
using Abp.Runtime.Session;
using Abp.Web.SignalR.Hubs;
using Microsoft.AspNet.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Test.Web
{
    public class ClientManager : Hub, ITransientDependency
    {
        private readonly IOnlineClientManager _onlineClientManager;
        private readonly IHubContext _hubContext; // Test purposes only

        public ClientManager(IOnlineClientManager onlineClientManager)
        {
            _onlineClientManager = onlineClientManager;
            _hubContext = GlobalHost.ConnectionManager.GetHubContext<AbpCommonHub>();
        }

        public override async Task OnConnected()
        {
            await base.OnConnected().ConfigureAwait(false);

            var client = new OnlineClient(Context.ConnectionId, "", 0, 0);
            _onlineClientManager.Add(client);
        }

        public override async Task OnDisconnected(bool stopCalled)
        {
            await base.OnDisconnected(stopCalled).ConfigureAwait(false);
            _onlineClientManager.Remove(Context.ConnectionId);
        }

        public List<IOnlineClient> GetOnlineUsers()
        {
            var allclients = _onlineClientManager.GetAllClients(); // Always returns 0!!!

            return allclients.ToList();
        }
    }
}

Startup.cs --> app.MapSignalR(); is invoked Web module --> Dependency on typeof(AbpWebSignalRModule) is specified SignalR packages are installed and referenced + JS scripts are properly bundled

OnConnected / OnDisconnected are never invoked. GetOnlineUsers() always returns an empty list.

Do I have to register my ClientManager in any way to make it work?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ismcagdascommented, Jul 15, 2021
1reaction
nandacciocommented, Jan 20, 2021

I found the issue, it was not on the back-end side.

I was referencing an old version of jquery.signalR in the script bundle. Fixing that reference solved all the problems. Closing this issue.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

IOnlineClientManager.GetAllClients always returns zero
Edited: My fault. I tested in the wrong environment. I created pr which fixed the error. All reactions.
Read more >
Dependency injection of IOnlineClientManager in Signal R ...
I am trying to inject IOnlineClientManager in my hub but it ... ... GetAllClients(); // Always returns 0 return Clients.Caller.
Read more >
How to Set the Expiration time for an user logon? #3891
I am using IOnlineClientManager to get all clients and sent real time message to them, is that if the user is out of...
Read more >
SignalR Integration document
ASP.NET Boilerplate provides the IOnlineClientManager to get information about online users (inject IOnlineClientManager and use the GetByUserIdOrNull, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found