The OnConnected method is not called SignalR when I use shared connectivity in multiple hubs

We can create several hubs for different things, and for connecting to each hub we can create several client nodes with joint connection, so that one connection is made with all concentrators. Now the problem arises that the method associated with the hub does not rise with each code on the server-hub side.

public class Hub1 : Hub { public override Task OnConnected() { return base.OnConnected(); } } public class Hub2 : Hub { public override Task OnConnected() { return base.OnConnected(); } } 

let's say on the client side I create hub1 and hub2 with client-side methods defined on both hubs, then only one of the onConnected hubs is called on the server side. If I create client-side hubs with separate connections, then the OnConnected method is called. So, is there any other work if I want to use the same connection for each hub, but would also like to raise the Connected event of the individual hubs.

+5
source share
1 answer

I tested it by setting a debugging point on both hubs, and OnConnected is called on both hubs if you have any subscriptions for both hubs.

See here: Can I debug the OnConnected method in a SignalR hub?

In short: By design, if you do not have a hub subscription, then the javascript client cannot receive messages from the server, so OnConnected will not be called.

EDIT

See here Note:

Note. For JavaScript clients, you need to register at least one event before invoking the Start method to establish a connection.

More details here.

+5
source

Source: https://habr.com/ru/post/1232255/


All Articles