Search code examples
javascriptasp.net-core.net-coresignalrasp.net-core-signalr

signalR core define transport


Before the final release of signalR core. I was able to send the transport when defining a new HubConnection (JavaScript)

var cnn = new signalR.HubConnection("/myhub", 
                                         {transport : signalrR.TransportType.LongPolling});

this doesn't work anymore. And i was not able to find any documentation / sample yet.

A sample or a link to the documentation would be much appreciated.


Solution

  • Here is a sample adapted from HubConnectionBuilder.test.ts:

    const builder = new signalR.HubConnectionBuilder()
        .withUrl("/myhub", signalR.HttpTransportType.WebSockets)
        .build();
    

    withUrl also accepts IHttpConnectionOptions so this would work too:

    const builder = new signalR.HubConnectionBuilder()
        .withUrl("/myhub", { transport: signalR.HttpTransportType.WebSockets })
        .build();