HubConnection class
Represents a connection to a SignalR Hub.
Properties
base |
Sets a new url for the HubConnection. Note that the url can only be changed when the connection is in either the Disconnected or Reconnecting states. |
connection |
Represents the connection id of the <xref:HubConnection> on the server. The connection id will be null when the connection is either in the disconnected state or if the negotiation step was skipped. |
keep |
Default interval at which to ping the server. The default value is 15,000 milliseconds (15 seconds). Allows the server to detect hard disconnects (like when a client unplugs their computer). |
server |
The server timeout in milliseconds. If this timeout elapses without receiving any messages from the server, the connection will be terminated with an error. The default timeout value is 30,000 milliseconds (30 seconds). |
state | Indicates the state of the <xref:HubConnection> to the server. |
Methods
invoke(string, any[]) | Invokes a hub method on the server using the specified name and arguments. The Promise returned by this method resolves when the server indicates it has finished invoking the method. When the promise resolves, the server has finished invoking the method. If the server method returns a result, it is produced as the result of resolving the Promise. |
off(string) | Removes all handlers for the specified hub method. |
off(string, (args: any[]) => void) | Removes the specified handler for the specified hub method. You must pass the exact same Function instance as was previously passed to on(string, (args: any[]) => void). Passing a different instance (even if the function body is the same) will not remove the handler. |
on(string, (args: any[]) => void) | Registers a handler that will be invoked when the hub method with the specified method name is invoked. |
onclose((error?: Error) => void) | Registers a handler that will be invoked when the connection is closed. |
onreconnected((connection |
Registers a handler that will be invoked when the connection successfully reconnects. |
onreconnecting((error?: Error) => void) | Registers a handler that will be invoked when the connection starts reconnecting. |
send(string, any[]) | Invokes a hub method on the server using the specified name and arguments. Does not wait for a response from the receiver. The Promise returned by this method resolves when the client has sent the invocation to the server. The server may still be processing the invocation. |
start() | Starts the connection. |
stop() | Stops the connection. |
stream(string, any[]) | Invokes a streaming hub method on the server using the specified name and arguments. |
Property Details
baseUrl
Sets a new url for the HubConnection. Note that the url can only be changed when the connection is in either the Disconnected or Reconnecting states.
baseUrl: string
Property Value
connectionId
Represents the connection id of the <xref:HubConnection> on the server. The connection id will be null when the connection is either in the disconnected state or if the negotiation step was skipped.
connectionId: string | null
Property Value
keepAliveIntervalInMilliseconds
Default interval at which to ping the server. The default value is 15,000 milliseconds (15 seconds). Allows the server to detect hard disconnects (like when a client unplugs their computer).
keepAliveIntervalInMilliseconds: number
Property Value
serverTimeoutInMilliseconds
The server timeout in milliseconds. If this timeout elapses without receiving any messages from the server, the connection will be terminated with an error. The default timeout value is 30,000 milliseconds (30 seconds).
serverTimeoutInMilliseconds: number
Property Value
state
Indicates the state of the <xref:HubConnection> to the server.
state: HubConnectionState
Property Value
Method Details
invoke(string, any[])
Invokes a hub method on the server using the specified name and arguments. The Promise returned by this method resolves when the server indicates it has finished invoking the method. When the promise resolves, the server has finished invoking the method. If the server method returns a result, it is produced as the result of resolving the Promise.
function invoke<T>(methodName: string, args: any[])
Parameters
Returns
off(string)
Removes all handlers for the specified hub method.
function off(methodName: string)
Parameters
off(string, (args: any[]) => void)
Removes the specified handler for the specified hub method. You must pass the exact same Function instance as was previously passed to on(string, (args: any[]) => void). Passing a different instance (even if the function body is the same) will not remove the handler.
function off(methodName: string, method: (args: any[]) => void)
Parameters
- method
- (args: any) => void[]
The handler to remove. This must be the same Function instance as the one passed to on(string, (args: any[]) => void).
on(string, (args: any[]) => void)
Registers a handler that will be invoked when the hub method with the specified method name is invoked.
function on(methodName: string, newMethod: (args: any[]) => void)
Parameters
onclose((error?: Error) => void)
Registers a handler that will be invoked when the connection is closed.
function onclose(callback: (error?: Error) => void)
Parameters
onreconnected((connectionId?: string) => void)
Registers a handler that will be invoked when the connection successfully reconnects.
function onreconnected(callback: (connectionId?: string) => void)
Parameters
onreconnecting((error?: Error) => void)
Registers a handler that will be invoked when the connection starts reconnecting.
function onreconnecting(callback: (error?: Error) => void)
Parameters
send(string, any[])
Invokes a hub method on the server using the specified name and arguments. Does not wait for a response from the receiver. The Promise returned by this method resolves when the client has sent the invocation to the server. The server may still be processing the invocation.
function send(methodName: string, args: any[])
Parameters
Returns
start()
Starts the connection.
function start()
Returns
stop()
Stops the connection.
function stop()
Returns
stream(string, any[])
Invokes a streaming hub method on the server using the specified name and arguments.
function stream<T>(methodName: string, args: any[])