angular-signalr-hub
angular-signalr-hub copied to clipboard
Wrong connection url
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:

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) {
}
});
});

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
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.
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)