What means skipNegotiation in SignalR HubConnection?

Viewed 2533

What is the diference between

this.hubConnection = new signalR.HubConnectionBuilder()
  .withUrl(environment.API_URL + "invoicinghub", {
    skipNegotiation: true,
    transport: signalR.HttpTransportType.WebSockets
  })
  .withAutomaticReconnect([0, 2000, 10000, 30000, null])
  .build();

and

this.hubConnection = new signalR.HubConnectionBuilder()
  .withUrl(environment.API_URL + "invoicinghub", {     
    transport: signalR.HttpTransportType.WebSockets
  })
  .withAutomaticReconnect([0, 2000, 10000, 30000, null])
  .build();

What does this skipNegotiation : true.

Thanks!

1 Answers

In SignalR, the client first sends a negotiation request to the server and the server responds with a redirect URL and an access token if there is one.

Client Request

{
  "connectionId":"807809a5-31bf-470d-9e23-afaee35d8a0d",
  "availableTransports":[
    {
      "transport": "WebSockets",
      "transferFormats": [ "Text", "Binary" ]
    },
    {
      "transport": "ServerSentEvents",
      "transferFormats": [ "Text" ]
    },
    {
      "transport": "LongPolling",
      "transferFormats": [ "Text", "Binary" ]
    }
  ]
}

Server Response

{
    "url":"https://test.service.signalr.net/client/?hub=chat&...",
    "accessToken":"<a typical JWT token>"
}

Only after receiving the response from the server does the client establish a connection.

In SignalR Core, but not in SignalR ASP, this requires sticky sessions. To avoid using sticky sessions, the client needs to skip negotiation but is restricted to only using websockets without Azure.

Sources:

Related