Skip to content

Commit

Permalink
Merge pull request #1132 from qzwzqty/master
Browse files Browse the repository at this point in the history
Passes the Endpoint of the client before it disconnected
  • Loading branch information
chkr1011 authored Apr 2, 2021
2 parents 324fb7e + 85b339e commit 10f7d80
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions Source/MQTTnet/Server/MqttClientSessionsManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MQTTnet.Adapter;
using MQTTnet.Adapter;
using MQTTnet.Diagnostics;
using MQTTnet.Exceptions;
using MQTTnet.Formatter;
Expand Down Expand Up @@ -237,11 +237,13 @@ public async Task CleanUpClient(string clientId, IMqttChannelAdapter channelAdap
}
}

var endpoint = channelAdapter.Endpoint;

await SafeCleanupChannelAsync(channelAdapter).ConfigureAwait(false);

if (clientId != null)
{
await _eventDispatcher.SafeNotifyClientDisconnectedAsync(clientId, disconnectType).ConfigureAwait(false);
await _eventDispatcher.SafeNotifyClientDisconnectedAsync(clientId, disconnectType, endpoint).ConfigureAwait(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using System;

namespace MQTTnet.Server
{
public class MqttServerClientDisconnectedEventArgs : EventArgs
{
public MqttServerClientDisconnectedEventArgs(string clientId, MqttClientDisconnectType disconnectType)
public MqttServerClientDisconnectedEventArgs(string clientId, MqttClientDisconnectType disconnectType, string endpoint)
{
ClientId = clientId ?? throw new ArgumentNullException(nameof(clientId));
DisconnectType = disconnectType;
Endpoint = endpoint;
}

/// <summary>
Expand All @@ -17,5 +18,7 @@ public MqttServerClientDisconnectedEventArgs(string clientId, MqttClientDisconne
public string ClientId { get; }

public MqttClientDisconnectType DisconnectType { get; }

public string Endpoint { get; }
}
}
6 changes: 3 additions & 3 deletions Source/MQTTnet/Server/MqttServerEventDispatcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MQTTnet.Client.Receiving;
using MQTTnet.Client.Receiving;
using MQTTnet.Diagnostics;
using System;
using System.Threading.Tasks;
Expand Down Expand Up @@ -44,7 +44,7 @@ public async Task SafeNotifyClientConnectedAsync(string clientId)
}
}

public async Task SafeNotifyClientDisconnectedAsync(string clientId, MqttClientDisconnectType disconnectType)
public async Task SafeNotifyClientDisconnectedAsync(string clientId, MqttClientDisconnectType disconnectType, string endpoint)
{
try
{
Expand All @@ -54,7 +54,7 @@ public async Task SafeNotifyClientDisconnectedAsync(string clientId, MqttClientD
return;
}

await handler.HandleClientDisconnectedAsync(new MqttServerClientDisconnectedEventArgs(clientId, disconnectType)).ConfigureAwait(false);
await handler.HandleClientDisconnectedAsync(new MqttServerClientDisconnectedEventArgs(clientId, disconnectType, endpoint)).ConfigureAwait(false);
}
catch (Exception exception)
{
Expand Down

0 comments on commit 10f7d80

Please sign in to comment.