Selaa lähdekoodia

Add the ClientId to the application message interceptor.

release/3.x.x
Christian Kratky 7 vuotta sitten
vanhempi
commit
f91d935708
4 muutettua tiedostoa jossa 17 lisäystä ja 9 poistoa
  1. +1
    -0
      Build/MQTTnet.nuspec
  2. +1
    -1
      Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs
  3. +8
    -0
      Frameworks/MQTTnet.NetStandard/Server/MqttApplicationMessageInterceptorContext.cs
  4. +7
    -8
      Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs

+ 1
- 0
Build/MQTTnet.nuspec Näytä tiedosto

@@ -20,6 +20,7 @@
* [Client] Fixed an issue in _ManagedClient_ which prevents changing the QoS of an existing subscription (BREAKING CHANGE!).
* [Client] Fixed an issue in _MqttClientOptionsBuilder_ which prevents adding TLS options to the client options when calling _Build()_. (Thanks to @cvellan).
* [Client] Added an overload for subscribing at both clients which reduces required code.
* [Client] Added the _ClientId_ to the application message interceptor context.
* [Server] The application message interceptor can now delete any received application message.
* [Server] Added a ConnectionValidator context to align with other APIs (BREAKING CHANGE! Please find new example in Wiki).
* [Server] Added an interface for the _MqttServerOptions_.


+ 1
- 1
Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs Näytä tiedosto

@@ -145,7 +145,7 @@ namespace MQTTnet.Implementations

var sslStream = new SslStream(new NetworkStream(clientSocket));
await sslStream.AuthenticateAsServerAsync(_tlsCertificate, false, SslProtocols.Tls12, false).ConfigureAwait(false);
var clientAdapter = new MqttChannelAdapter(new MqttTcpChannel(clientSocket, sslStream), new MqttPacketSerializer(), _logger);
ClientAccepted?.Invoke(this, new MqttServerAdapterClientAcceptedEventArgs(clientAdapter));
}


+ 8
- 0
Frameworks/MQTTnet.NetStandard/Server/MqttApplicationMessageInterceptorContext.cs Näytä tiedosto

@@ -2,6 +2,14 @@
{
public class MqttApplicationMessageInterceptorContext
{
public MqttApplicationMessageInterceptorContext(string clientId, MqttApplicationMessage applicationMessage)
{
ClientId = clientId;
ApplicationMessage = applicationMessage;
}

public string ClientId { get; }

public MqttApplicationMessage ApplicationMessage { get; set; }
}
}

+ 7
- 8
Frameworks/MQTTnet.NetStandard/Server/MqttClientSessionsManager.cs Näytä tiedosto

@@ -136,7 +136,7 @@ namespace MQTTnet.Server
{
try
{
applicationMessage = InterceptApplicationMessage(applicationMessage);
applicationMessage = InterceptApplicationMessage(senderClientSession, applicationMessage);
if (applicationMessage == null)
{
return;
@@ -168,17 +168,16 @@ namespace MQTTnet.Server
}
}

private MqttApplicationMessage InterceptApplicationMessage(MqttApplicationMessage applicationMessage)
private MqttApplicationMessage InterceptApplicationMessage(MqttClientSession senderClientSession, MqttApplicationMessage applicationMessage)
{
if (_options.ApplicationMessageInterceptor == null)
{
return applicationMessage;
}

var interceptorContext = new MqttApplicationMessageInterceptorContext
{
ApplicationMessage = applicationMessage
};
var interceptorContext = new MqttApplicationMessageInterceptorContext(
senderClientSession.ClientId,
applicationMessage);

_options.ApplicationMessageInterceptor(interceptorContext);
return interceptorContext.ApplicationMessage;
@@ -190,7 +189,7 @@ namespace MQTTnet.Server
{
return MqttConnectReturnCode.ConnectionAccepted;
}
var context = new MqttConnectionValidatorContext(
connectPacket.ClientId,
connectPacket.Username,
@@ -210,7 +209,7 @@ namespace MQTTnet.Server
if (isSessionPresent)
{
if (connectPacket.CleanSession)
{
{
_sessions.Remove(connectPacket.ClientId);

await clientSession.StopAsync().ConfigureAwait(false);


Ladataan…
Peruuta
Tallenna