angular-signalr-hub icon indicating copy to clipboard operation
angular-signalr-hub copied to clipboard

Wrong connection url

Open Devqon opened this issue 10 years ago • 2 comments

I try using your library with typescript, so I have the following angular factory:

export class ChatFactory implements IChatFactory {

    public hub: ngSignalr.Hub;

    $inject = ["$rootScope", "Hub"];

    static factory($rootScope: angular.IRootScopeService, Hub: ngSignalr.HubFactory) {
        return new ChatFactory($rootScope, Hub);
    }

    constructor($rootScope: angular.IRootScopeService, Hub: ngSignalr.HubFactory) {

        var options: ngSignalr.HubOptions = {
            // options
        };
        this.hub = new Hub("chat", options);
    }
}

This results in an error, because the url isn't correct:

image

But the default way to initialize a hub works:

var chat = $.connection.chat;
$.connection.hub.start({ transport: 'auto'}, function () {
    chat.server.join()
        .done(function (success) {
            if (success === false) {
            }
        });
});

image

If I have to pass in the url, I have to pass it from the view through ng-init to the controller, to the service, and then initialize the hub with the given rootUrl. This still doesn't work though, with the same error message. What am I doing wrong here?

EDIT Postfixing the given rooturl with 'signalr/' does work, but I still don't know why the library would pick a different rooturl than the $.connection.hub

Devqon avatar Sep 15 '15 12:09 Devqon

Hey @Devqon looking at signalR's src, on line 2746 it appears the default url is '/signalr', since this module uses $.hubConnection to create a connection, it sets the url for signalR to that default.

I would suggest just setting the rootUrl in the options like you discovered in your edit.

JustMaier avatar Sep 16 '15 16:09 JustMaier

Yeah that works, but the real issue is that the 'normal' connection uses /OrchardLocal/signalr/negotia.. as default (which is correct, because /OrchardLocal is the baseurl), and through the angular-signalr-hub it uses /signalr/negotia.. (without the OrchardLocal part)

Devqon avatar Sep 17 '15 06:09 Devqon