mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-21 12:16:02 +08:00
Expose more properties to connection validator context.
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Client.Receiving;
|
||||
using MQTTnet.Diagnostics;
|
||||
|
||||
namespace MQTTnet.Server
|
||||
{
|
||||
public class MqttServerEventDispatcher
|
||||
{
|
||||
private readonly IMqttNetChildLogger _logger;
|
||||
|
||||
public MqttServerEventDispatcher(IMqttNetChildLogger logger)
|
||||
{
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
public IMqttServerClientConnectedHandler ClientConnectedHandler { get; set; }
|
||||
|
||||
public IMqttServerClientDisconnectedHandler ClientDisconnectedHandler { get; set; }
|
||||
@@ -26,15 +35,22 @@ namespace MQTTnet.Server
|
||||
return handler.HandleClientConnectedAsync(new MqttServerClientConnectedEventArgs(clientId));
|
||||
}
|
||||
|
||||
public Task HandleClientDisconnectedAsync(string clientId, MqttClientDisconnectType disconnectType)
|
||||
public async Task TryHandleClientDisconnectedAsync(string clientId, MqttClientDisconnectType disconnectType)
|
||||
{
|
||||
var handler = ClientDisconnectedHandler;
|
||||
if (handler == null)
|
||||
try
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
var handler = ClientDisconnectedHandler;
|
||||
if (handler == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return handler.HandleClientDisconnectedAsync(new MqttServerClientDisconnectedEventArgs(clientId, disconnectType));
|
||||
await handler.HandleClientDisconnectedAsync(new MqttServerClientDisconnectedEventArgs(clientId, disconnectType)).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
_logger.Error(exception, "Error while handling 'ClientDisconnected' event.");
|
||||
}
|
||||
}
|
||||
|
||||
public Task HandleClientSubscribedTopicAsync(string clientId, TopicFilter topicFilter)
|
||||
|
||||
Reference in New Issue
Block a user