feat(Auth.Client): Erstellt, um Client (Consumer) Ereignisse von SignalR zu behandeln.

- Erstellt ClientParams um AuthClient zu konfigurieren.
 - Erstellt ClientEvents, um Ereignisse im Client zu konfigurieren.
This commit is contained in:
Developer 02
2025-01-24 14:51:02 +01:00
parent a2f4fcfbe0
commit bf12c889f3
5 changed files with 56 additions and 2 deletions

View File

@@ -0,0 +1,32 @@
using DigitalData.Auth.Abstractions;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace DigitalData.Auth.Client;
public class AuthClient : IAuthClient
{
private readonly HubConnection _connection;
private readonly ILogger? _logger;
private readonly ClientParams _params;
public AuthClient(IOptions<ClientParams> paramsOptions, HubConnectionBuilder connectionBuilder, ILogger<AuthClient>? logger = null)
{
_connection = connectionBuilder
.WithUrl(paramsOptions.Value.Url)
.Build();
_connection.On<string, string>(nameof(ReceiveMessage), ReceiveMessage);
_logger = logger;
_params = paramsOptions.Value;
}
public async Task StartAsync() => await _connection.StartAsync();
public Task ReceiveMessage(string user, string message) => _params.Events.OnMessageReceived(user, message, _logger);
}