Browse Source

Merge pull request #1132 from qzwzqty/master

Passes the Endpoint of the client before it disconnected
release/3.x.x
Christian 3 years ago
committed by GitHub
parent
commit
10f7d809f2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 7 deletions
  1. +4
    -2
      Source/MQTTnet/Server/MqttClientSessionsManager.cs
  2. +5
    -2
      Source/MQTTnet/Server/MqttServerClientDisconnectedEventArgs.cs
  3. +3
    -3
      Source/MQTTnet/Server/MqttServerEventDispatcher.cs

+ 4
- 2
Source/MQTTnet/Server/MqttClientSessionsManager.cs View File

@@ -1,4 +1,4 @@
using MQTTnet.Adapter;
using MQTTnet.Adapter;
using MQTTnet.Diagnostics; using MQTTnet.Diagnostics;
using MQTTnet.Exceptions; using MQTTnet.Exceptions;
using MQTTnet.Formatter; using MQTTnet.Formatter;
@@ -237,11 +237,13 @@ namespace MQTTnet.Server
} }
} }


var endpoint = channelAdapter.Endpoint;

await SafeCleanupChannelAsync(channelAdapter).ConfigureAwait(false); await SafeCleanupChannelAsync(channelAdapter).ConfigureAwait(false);


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




+ 5
- 2
Source/MQTTnet/Server/MqttServerClientDisconnectedEventArgs.cs View File

@@ -1,13 +1,14 @@
using System;
using System;


namespace MQTTnet.Server namespace MQTTnet.Server
{ {
public class MqttServerClientDisconnectedEventArgs : EventArgs 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)); ClientId = clientId ?? throw new ArgumentNullException(nameof(clientId));
DisconnectType = disconnectType; DisconnectType = disconnectType;
Endpoint = endpoint;
} }


/// <summary> /// <summary>
@@ -17,5 +18,7 @@ namespace MQTTnet.Server
public string ClientId { get; } public string ClientId { get; }


public MqttClientDisconnectType DisconnectType { get; } public MqttClientDisconnectType DisconnectType { get; }

public string Endpoint { get; }
} }
} }

+ 3
- 3
Source/MQTTnet/Server/MqttServerEventDispatcher.cs View File

@@ -1,4 +1,4 @@
using MQTTnet.Client.Receiving;
using MQTTnet.Client.Receiving;
using MQTTnet.Diagnostics; using MQTTnet.Diagnostics;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -44,7 +44,7 @@ namespace MQTTnet.Server
} }
} }


public async Task SafeNotifyClientDisconnectedAsync(string clientId, MqttClientDisconnectType disconnectType)
public async Task SafeNotifyClientDisconnectedAsync(string clientId, MqttClientDisconnectType disconnectType, string endpoint)
{ {
try try
{ {
@@ -54,7 +54,7 @@ namespace MQTTnet.Server
return; return;
} }


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


Loading…
Cancel
Save