Nesco.SignalRUserManagement.Client
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Nesco.SignalRUserManagement.Client --version 1.0.0
NuGet\Install-Package Nesco.SignalRUserManagement.Client -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nesco.SignalRUserManagement.Client" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nesco.SignalRUserManagement.Client" Version="1.0.0" />
<PackageReference Include="Nesco.SignalRUserManagement.Client" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Nesco.SignalRUserManagement.Client --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Nesco.SignalRUserManagement.Client, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Nesco.SignalRUserManagement.Client@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Nesco.SignalRUserManagement.Client&version=1.0.0
#tool nuget:?package=Nesco.SignalRUserManagement.Client&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Nesco.SignalRUserManagement.Client
Client-side package for connecting to SignalR User Management hubs from Blazor WebAssembly applications.
Installation
dotnet add package Nesco.SignalRUserManagement.Client
Usage
1. Configure services in Program.cs
using Nesco.SignalRUserManagement.Client.Extensions;
builder.Services.AddUserManagementClient(options =>
{
options.BroadcastConnectionEvents = true;
options.ConnectionEventMethod = "UserConnectionEvent";
});
2. Initialize the connection
@inject UserConnectionClient ConnectionClient
protected override async Task OnInitializedAsync()
{
// Simple initialization
await ConnectionClient.InitializeAsync("https://yourserver.com/hubs/messaging");
// With authentication
await ConnectionClient.InitializeAsync(
"https://yourserver.com/hubs/messaging",
async () => await GetAccessTokenAsync());
// Subscribe to connection status changes
ConnectionClient.ConnectionStatusChanged += OnConnectionStatusChanged;
// Subscribe to user connection events
ConnectionClient.UserConnectionEventReceived += OnUserConnectionEvent;
// Register message handlers
ConnectionClient.On<string>("ReceiveNotification", async (message) =>
{
Console.WriteLine($"Received: {message}");
StateHasChanged();
});
}
private void OnConnectionStatusChanged(bool isConnected)
{
Console.WriteLine($"Connection status: {(isConnected ? "Connected" : "Disconnected")}");
StateHasChanged();
}
private Task OnUserConnectionEvent(UserConnectionEventArgs eventArgs)
{
Console.WriteLine($"User {eventArgs.UserId} {eventArgs.EventType}");
return Task.CompletedTask;
}
3. Send messages to the server
// Send a message to the server
await ConnectionClient.SendAsync("SendMessage", "Hello server!");
// Invoke a method and get a result
var result = await ConnectionClient.InvokeAsync<string>("GetServerTime");
4. Check connection status
bool isConnected = ConnectionClient.IsConnected;
string? connectionId = ConnectionClient.ConnectionId;
var state = ConnectionClient.ConnectionState;
5. Manual reconnection
if (!ConnectionClient.IsConnected)
{
await ConnectionClient.ReconnectAsync();
}
Complete Example
@page "/notifications"
@inject UserConnectionClient ConnectionClient
@implements IAsyncDisposable
<h3>Notifications</h3>
<p>Status: @(ConnectionClient.IsConnected ? "Connected" : "Disconnected")</p>
<p>Connection ID: @ConnectionClient.ConnectionId</p>
<ul>
@foreach (var notification in _notifications)
{
<li>@notification</li>
}
</ul>
@code {
private List<string> _notifications = new();
protected override async Task OnInitializedAsync()
{
// Initialize connection
await ConnectionClient.InitializeAsync(
"https://localhost:5004/hubs/messaging",
() => Task.FromResult(AccessToken));
// Subscribe to events
ConnectionClient.ConnectionStatusChanged += (isConnected) =>
{
StateHasChanged();
};
// Register message handlers
ConnectionClient.On<string>("ReceiveNotification", async (message) =>
{
_notifications.Add(message);
StateHasChanged();
});
ConnectionClient.On<UserConnectionEventArgs>("UserConnectionEvent", async (eventArgs) =>
{
_notifications.Add($"User {eventArgs.UserId} {eventArgs.EventType}");
StateHasChanged();
});
}
public async ValueTask DisposeAsync()
{
await ConnectionClient.StopAsync();
}
}
Features
- Automatic Reconnection: Automatically reconnects with exponential backoff
- Connection Events: Receive notifications when users connect/disconnect
- Type-safe Message Handling: Register strongly-typed message handlers
- Authentication Support: Integrate with JWT or other authentication mechanisms
- Connection Status Monitoring: Track connection state changes in real-time
- Manual Control: Start, stop, and reconnect as needed
Events
ConnectionStatusChanged
Raised when the connection state changes (connected/disconnected).
ConnectionClient.ConnectionStatusChanged += (isConnected) =>
{
Console.WriteLine($"Connection: {isConnected}");
};
UserConnectionEventReceived
Raised when another user connects or disconnects (if BroadcastConnectionEvents is enabled).
ConnectionClient.UserConnectionEventReceived += async (eventArgs) =>
{
Console.WriteLine($"{eventArgs.UserId} {eventArgs.EventType}");
};
Connection States
- Disconnected: No connection to the server
- Connecting: Connection is being established
- Connected: Successfully connected and can send/receive messages
- Reconnecting: Connection was lost and is being re-established
Notes
- The client automatically reconnects with exponential backoff (0s, 2s, 5s, 10s)
- All message handlers are executed asynchronously
- The service is registered as a singleton and can be injected anywhere
- Connection status changes trigger events that can update the UI
- Dispose the client properly to clean up resources
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.AspNetCore.SignalR.Client (>= 9.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.0)
- Nesco.SignalRUserManagement.Core (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Nesco.SignalRUserManagement.Client:
| Package | Downloads |
|---|---|
|
Nesco.SignalRCommunicator.Client.Dashboard
A ready-to-use Blazor WebAssembly dashboard component for SignalR client status, connection monitoring, and method invocation logging. |
GitHub repositories
This package is not used by any popular GitHub repositories.