Skip to content

API Overview

This page lists the public API surface of SignalARRR across all packages.

Server API (Cocoar.SignalARRR.Server)

Registration

csharp
// IServiceCollection extension
services.AddSignalARRR(options => options
    .AddServerMethodsFrom(assembly));

// IEndpointRouteBuilder extension
app.MapHARRRController<THub>(path);
app.MapHARRRController<THub>(path, configureOptions);

HARRR (Hub base class)

MemberTypeDescription
ServiceProviderIServiceProviderDI container
LoggerILogger?Logger instance
ClientContextClientContextCurrent client context
OnConnectedAsync()TaskClient connected (registers in ClientManager)
OnDisconnectedAsync(Exception?)TaskClient disconnected (unregisters)

Hub methods (wire protocol — called by clients internally):

MethodDescription
InvokeMessage(ClientRequestMessage)Fire-and-forget
InvokeMessageResult(ClientRequestMessage)Returns result
SendMessage(ClientRequestMessage)Fire-and-forget (async void)
StreamMessage(ClientRequestMessage, CancellationToken)Server-to-client stream
StreamItemToServer(Guid, object)Client-to-server stream item
StreamCompleteToServer(Guid, string?)Client-to-server stream completion

ServerMethods / ServerMethods<T>

PropertyTypeDescription
ClientContextClientContextCurrent client context
ContextHubCallerContextSignalR caller context
ClientsIHubCallerClientsClient connections
GroupsIGroupManagerGroup management
LoggerILoggerLogger

ClientContext

PropertyTypeDescription
IdstringConnection ID
HARRRTypeTypeHub type
RemoteIpIPAddress?Client IP
UserClaimsPrincipalAuthenticated user
UserValidUntilDateTimeToken expiration
ConnectedAtDateTimeConnection time
ReconnectedAtList<DateTime>Reconnection history
AttributesClientAttributesCustom key-value storage
ConnectedToUriHub URL
MethodDescription
GetTypedMethods<T>()Get typed proxy to call this client
TryAuthenticate(MethodInfo)Validate token, challenge if expired

ClientManager

MethodDescription
GetClientById(string)Get client by connection ID
GetAllClients()All connected clients
GetAllClients(predicate)Filter clients
GetHARRRClients<T>()Clients for a specific hub type
GetHARRRClients<T>(predicate)Filter clients for a hub type

Client API (Cocoar.SignalARRR.Client)

HARRRConnection

Static methodDescription
Create(Action<HubConnectionBuilder>, options?)Create from builder
Create(HubConnection, options?)Wrap existing connection
MethodDescription
GetTypedMethods<T>()Get typed proxy for a contract interface
InvokeCoreAsync<T>(message, ct)Call server, await typed result
SendCoreAsync(message, ct)Fire-and-forget
StreamAsyncCore<T>(message, ct)Server-to-client stream
OnServerRequest(name, handler)Register server-to-client handler
StartAsync(ct)Connect
StopAsync(ct)Disconnect
DisposeAsync()Dispose
AsSignalRHubConnection()Access raw HubConnection
PropertyTypeDescription
ConnectionIdstring?Connection ID
StateHubConnectionStateConnection state
ServerTimeoutTimeSpanServer timeout
KeepAliveIntervalTimeSpanKeepalive interval
HandshakeTimeoutTimeSpanHandshake timeout
EventDescription
ClosedFires when connection closes
ReconnectingFires when reconnecting
ReconnectedFires when reconnected

TypeScript API (@cocoar/signalarrr)

HARRRConnection

ts
class HARRRConnection {
    static create(builderOrConnection, options?): HARRRConnection

    invoke<T>(methodName: string, ...args: unknown[]): Promise<T>
    send(methodName: string, ...args: unknown[]): Promise<void>
    stream<T>(methodName: string, ...args: unknown[]): IStreamResult<T>

    onServerMethod(methodName: string, handler: (...args) => unknown): this

    start(): Promise<void>
    stop(): Promise<void>
    asSignalRHubConnection(): signalR.HubConnection

    onClose(callback: (error?) => void): void
    onReconnecting(callback: (error?) => void): void
    onReconnected(callback: (connectionId?) => void): void

    connectionId: string | null
    state: HubConnectionState
    baseUrl: string
    serverTimeoutInMilliseconds: number
    keepAliveIntervalInMilliseconds: number
}

Exported types

ts
export { HARRRConnection } from './harrr-connection.js'
export { HARRRConnectionOptions } from './harrr-connection-options.js'
export type { ClientRequestMessage } from './models/client-request-message.js'
export type { ServerRequestMessage } from './models/server-request-message.js'
export type { CancellationTokenReference } from './models/cancellation-token-reference.js'

Common types (Cocoar.SignalARRR.Common)

ClientRequestMessage

PropertyTypeDescription
MethodstringMethod name (ClassName.MethodName)
Argumentsobject[]Method arguments
Authorizationstring?Bearer token
GenericArgumentsstring[]Generic type arguments

ServerRequestMessage

PropertyTypeDescription
IdGuidCorrelation ID for reply
MethodstringMethod name
Argumentsobject[]Method arguments
GenericArgumentsstring[]Generic type arguments
CancellationGuidGuid?Cancellation correlation ID
StreamIdGuid?Stream correlation ID

Attributes

AttributeDescription
[SignalARRRContract]Marks an interface for proxy generation
[MessageName(string)]Override the default method name

Next steps

Released under the Apache-2.0 License.