Search code examples
angulartypescriptsignalrasp.net-core-signalr

SignalR connection negotiation fails


I'm trying to use SignalR in an Angular application. I'm using the Typescript client @aspnet/signalr.

What I get in the console is

Information: Normalizing '/api/signalr?connectionData=%5B%7B%22name%22%3A%22myhub%22%7D%5D' to 'http://server:port/api/signalr?connectionData=%5B%7B%22name%22%3A%22myhub%22%7D%5D'.

Debug: Starting HubConnection.

Debug: Starting connection with transfer format 'Text'.

Debug: Sending negotiation request: http://server:port/api/signalr/negotiate?connectionData=%5B%7B%22name%22%3A%22kanbanhub%22%7D%5D

Error: Failed to start the connection: TypeError: Cannot read property 'length' of undefined

The error seems to come from the line if (!(_i < transports_1.length)) return [3 /*break*/, 9]; in HttpConnection. It could be related to the fact that the negotiation response does not contain the availableTransports array.

{
    "Url":"/api/signalr",
    "ConnectionToken":"XXX",
    "ConnectionId":"XXX",
    "KeepAliveTimeout":20.0,
    "DisconnectTimeout":30.0,
    "ConnectionTimeout":110.0,
    "TryWebSockets":false,
    "ProtocolVersion":"1.2",
    "TransportConnectTimeout":5.0,
    "LongPollDelay":0.0
}

Any idea why?


Solution

  • It seems that the problem is that I'm using ASP.NET Core SignalR on client side and ASP.NET SignalR on server side, which are incompatible.

    Instead of @aspnet/signalr I should use signalr.