Search code examples
signalrsignalr.clientasp.net-core-signalr

How can we get the transport method in javascript client for signalr core?


In older versions of signalR, you could do this to get the transport method being used:

$.connection.hub.transport.name

How is this done for signalR core?


Solution

  • On the HubConnectionBuilder, you can get the transport like so:

    this.connection = new signalR.HubConnectionBuilder()
        .withUrl(connectionUrl)
        .build();
    
    this.connection.connection.transport.constructor.name
    

    Perhaps not the best solution, but it seems to work well enough. Looks like the returned values could be:

    • WebSocketTransport
    • LongPollingTransport
    • ServerSentEventsTransport