HubConnectionBuilder class

A builder for configuring HubConnection instances.

Properties

httpConnectionOptions
logger
protocol
reconnectPolicy
url

Methods

build()

Creates a HubConnection from the configuration options specified in this builder.

configureLogging(ILogger)

Configures custom logging for the HubConnection.

configureLogging(LogLevel | string | ILogger)

Configures custom logging for the HubConnection.

configureLogging(LogLevel)

Configures console logging for the HubConnection.

configureLogging(string)

Configures custom logging for the HubConnection.

withAutomaticReconnect()

Configures the HubConnection to automatically attempt to reconnect if the connection is lost. By default, the client will wait 0, 2, 10 and 30 seconds respectively before trying up to 4 reconnect attempts.

withAutomaticReconnect(IRetryPolicy)

Configures the HubConnection to automatically attempt to reconnect if the connection is lost.

withAutomaticReconnect(number[])

Configures the HubConnection to automatically attempt to reconnect if the connection is lost.

withHubProtocol(IHubProtocol)

Configures the HubConnection to use the specified Hub Protocol.

withUrl(string)

Configures the HubConnection to use HTTP-based transports to connect to the specified URL. The transport will be selected automatically based on what the server and client support.

withUrl(string, HttpTransportType)

Configures the HubConnection to use the specified HTTP-based transport to connect to the specified URL.

withUrl(string, IHttpConnectionOptions)

Configures the HubConnection to use HTTP-based transports to connect to the specified URL.

Property Details

httpConnectionOptions

public httpConnectionOptions?: IHttpConnectionOptions

Property Value

logger

public logger?: ILogger

Property Value

protocol

public protocol?: IHubProtocol

Property Value

reconnectPolicy

public reconnectPolicy?: IRetryPolicy

Property Value

url

public url?: string

Property Value

string

Method Details

build()

Creates a HubConnection from the configuration options specified in this builder.

function build(): HubConnection

Returns

The configured {@link @microsoft/signalr.HubConnection}.

configureLogging(ILogger)

Configures custom logging for the HubConnection.

function configureLogging(logger: ILogger): HubConnectionBuilder

Parameters

logger
ILogger

An object implementing the ILogger interface, which will be used to write all log messages.

Returns

The {@link @microsoft/signalr.HubConnectionBuilder} instance, for chaining.

configureLogging(LogLevel | string | ILogger)

Configures custom logging for the HubConnection.

function configureLogging(logging: LogLevel | string | ILogger): HubConnectionBuilder

Parameters

logging

LogLevel | string | ILogger

A LogLevel, a string representing a LogLevel, or an object implementing the ILogger interface. See the documentation for client logging configuration for more details.

Returns

The {@link @microsoft/signalr.HubConnectionBuilder} instance, for chaining.

configureLogging(LogLevel)

Configures console logging for the HubConnection.

function configureLogging(logLevel: LogLevel): HubConnectionBuilder

Parameters

logLevel
LogLevel

The minimum level of messages to log. Anything at this level, or a more severe level, will be logged.

Returns

The {@link @microsoft/signalr.HubConnectionBuilder} instance, for chaining.

configureLogging(string)

Configures custom logging for the HubConnection.

function configureLogging(logLevel: string): HubConnectionBuilder

Parameters

logLevel

string

A string representing a LogLevel setting a minimum level of messages to log. See the documentation for client logging configuration for more details.

Returns

withAutomaticReconnect()

Configures the HubConnection to automatically attempt to reconnect if the connection is lost. By default, the client will wait 0, 2, 10 and 30 seconds respectively before trying up to 4 reconnect attempts.

function withAutomaticReconnect(): HubConnectionBuilder

Returns

withAutomaticReconnect(IRetryPolicy)

Configures the HubConnection to automatically attempt to reconnect if the connection is lost.

function withAutomaticReconnect(reconnectPolicy: IRetryPolicy): HubConnectionBuilder

Parameters

reconnectPolicy
IRetryPolicy

An <xref:%40microsoft%2FsignalR.IRetryPolicy> that controls the timing and number of reconnect attempts.

Returns

withAutomaticReconnect(number[])

Configures the HubConnection to automatically attempt to reconnect if the connection is lost.

function withAutomaticReconnect(retryDelays: number[]): HubConnectionBuilder

Parameters

retryDelays

number[]

An array containing the delays in milliseconds before trying each reconnect attempt. The length of the array represents how many failed reconnect attempts it takes before the client will stop attempting to reconnect.

Returns

withHubProtocol(IHubProtocol)

Configures the HubConnection to use the specified Hub Protocol.

function withHubProtocol(protocol: IHubProtocol): HubConnectionBuilder

Parameters

protocol
IHubProtocol

The IHubProtocol implementation to use.

Returns

withUrl(string)

Configures the HubConnection to use HTTP-based transports to connect to the specified URL. The transport will be selected automatically based on what the server and client support.

function withUrl(url: string): HubConnectionBuilder

Parameters

url

string

The URL the connection will use.

Returns

The {@link @microsoft/signalr.HubConnectionBuilder} instance, for chaining.

withUrl(string, HttpTransportType)

Configures the HubConnection to use the specified HTTP-based transport to connect to the specified URL.

function withUrl(url: string, transportType: HttpTransportType): HubConnectionBuilder

Parameters

url

string

The URL the connection will use.

transportType
HttpTransportType

The specific transport to use.

Returns

The {@link @microsoft/signalr.HubConnectionBuilder} instance, for chaining.

withUrl(string, IHttpConnectionOptions)

Configures the HubConnection to use HTTP-based transports to connect to the specified URL.

function withUrl(url: string, options: IHttpConnectionOptions): HubConnectionBuilder

Parameters

url

string

The URL the connection will use.

options
IHttpConnectionOptions

An options object used to configure the connection.

Returns

The {@link @microsoft/signalr.HubConnectionBuilder} instance, for chaining.