Base solution for your next web application
Open Closed

Registering custom signalr hubs in asp zero #5248


User avatar
0
strix20 created

I'm looking for some guidance on this. I'm really confused by the 5.5 implementation of AbpCommonHub and ChatHub, because they appear to simply override each other.

Both set abp.signalr.connect and then call abp.signalr.connect if autoconnect is enable.

But if it is not, then how do we connect to both? In this case it appears that the common hub defined in abp.signalr-client.js will never start, thus breaking notifications.

Is this an oversight?

How do we extend an existing hub once it is registered? I need to add some methods to the common hub, in addition to defining a new hub of my own.

Also as an aside, now that the hubs are split into multiple endpoints and the dynamic proxies are gone, does anyone happen to know if multiple hub connections with retain the same connectionId?


5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    @strix20 things have been changed for new ASP.NET Core SignalR 1.0. Now, every hub uses a different connection with a different connection Id.

    Here is how the connection is started for a separate hub <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Mvc/wwwroot/Common/Scripts/Chat/chat.signalr.js#L87">https://github.com/aspnetzero/aspnet-ze ... alr.js#L87</a>.

    So, insteaf of using AbpCommonHub, you need to define your own hub similar to ChatHub and use it.

  • User Avatar
    0
    strix20 created

    That still doesn't explain how to start them properly.

    In the case of abpcommonhub and chathub, they both set the method abp.signalr.connect, thus overriding eachother and only allowing the chathub to connect when autostart is disabled.

  • User Avatar
    0
    aaron created
    Support Team

    In this case it appears that the common hub defined in abp.signalr-client.js will never start, thus breaking notifications.

    That is correct if abp.signalr.autoConnect was set to false. For now, try:

    // Before
    abp.signalr.connect = function () {
        ...
    }
    
    // After
    const connect = abp.signalr.connect;
    abp.signalr.connect = function () {
        connect && connect();
        ...
    }
    

    Actually, a custom SignalR client should ignore abp.signalr.autoConnect.

    How do we extend an existing hub once it is registered? I need to add some methods to the common hub, in addition to defining a new hub of my own.

    You cannot add methods to the common hub (on the server side). You might be able to add methods to the client:

    abp.signalr.hubs.common.on('myMethod', function () {
        ...
    });
    
  • User Avatar
    0
    strix20 created

    <cite>aaron: </cite>

    In this case it appears that the common hub defined in abp.signalr-client.js will never start, thus breaking notifications.

    That is correct if abp.signalr.autoConnect was set to false. For now, try:

    // Before
    abp.signalr.connect = function () {
       ...
    }
    
    // After
    const connect = abp.signalr.connect;
    abp.signalr.connect = function () {
       connect && connect();
       ...
    }
    

    Actually, a custom SignalR client should ignore abp.signalr.autoConnect.

    How do we extend an existing hub once it is registered? I need to add some methods to the common hub, in addition to defining a new hub of my own.

    You cannot add methods to the common hub (on the server side). You might be able to add methods to the client:

    abp.signalr.hubs.common.on('myMethod', function () {
       ...
    });
    

    There is also an issue of the duplication of the following in both files:

    abp.signalr.startConnection = startConnection;
    
        if (abp.signalr.autoConnect === undefined) {
            abp.signalr.autoConnect = true;
        }
    
    
    
        if (abp.signalr.autoConnect) {
            abp.signalr.connect();
        }
    

    This causes the signalR connection bootstrapping to occur twice when autoconnect is enabled.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Could you create an issue here <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/issues">https://github.com/aspnetzero/aspnet-zero-core/issues</a>, we will fix it for the next release.