32 lines
963 B
C#
32 lines
963 B
C#
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 void ReceiveMessage(string user, string message) => _params.Events.OnMessageReceived(user, message, _logger);
|
|
} |