mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-25 23:53:07 +08:00
Add support for user properties in client connect.
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
* [Client] Fixed a memory leak when web socket based connections trying to reconnect with an offline server.
|
* [Client] Fixed a memory leak when web socket based connections trying to reconnect with an offline server.
|
||||||
* [Client] Fixed a memory leak when TCP based connections trying to reconnect with an offline server.
|
* [Client] Fixed a memory leak when TCP based connections trying to reconnect with an offline server.
|
||||||
* [Client] Fixed an issue when connecting to an invalid host (format).
|
* [Client] Fixed an issue when connecting to an invalid host (format).
|
||||||
|
* [Client] Added support for user properties in CONNECT packet.
|
||||||
* [ManagedClient] Added method to trigger PING/PONG manually (connection check etc.).
|
* [ManagedClient] Added method to trigger PING/PONG manually (connection check etc.).
|
||||||
* [MQTTnet.AspNetCore] improved compatibility with AspNetCore 3.1.
|
* [MQTTnet.AspNetCore] improved compatibility with AspNetCore 3.1.
|
||||||
* [MQTTnet.AspNetCore] Fixed several packaging issues with the Nuget package.
|
* [MQTTnet.AspNetCore] Fixed several packaging issues with the Nuget package.
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using MQTTnet.Client.ExtendedAuthenticationExchange;
|
||||||
using MQTTnet.Client.ExtendedAuthenticationExchange;
|
|
||||||
using MQTTnet.Formatter;
|
using MQTTnet.Formatter;
|
||||||
|
using MQTTnet.Packets;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace MQTTnet.Client.Options
|
namespace MQTTnet.Client.Options
|
||||||
{
|
{
|
||||||
@@ -12,11 +14,11 @@ namespace MQTTnet.Client.Options
|
|||||||
IMqttExtendedAuthenticationExchangeHandler ExtendedAuthenticationExchangeHandler { get; }
|
IMqttExtendedAuthenticationExchangeHandler ExtendedAuthenticationExchangeHandler { get; }
|
||||||
MqttProtocolVersion ProtocolVersion { get; }
|
MqttProtocolVersion ProtocolVersion { get; }
|
||||||
IMqttClientChannelOptions ChannelOptions { get; }
|
IMqttClientChannelOptions ChannelOptions { get; }
|
||||||
|
|
||||||
TimeSpan CommunicationTimeout { get; }
|
TimeSpan CommunicationTimeout { get; }
|
||||||
TimeSpan KeepAlivePeriod { get; }
|
TimeSpan KeepAlivePeriod { get; }
|
||||||
TimeSpan? KeepAliveSendInterval { get; }
|
TimeSpan? KeepAliveSendInterval { get; }
|
||||||
|
|
||||||
MqttApplicationMessage WillMessage { get; }
|
MqttApplicationMessage WillMessage { get; }
|
||||||
uint? WillDelayInterval { get; }
|
uint? WillDelayInterval { get; }
|
||||||
|
|
||||||
@@ -28,5 +30,6 @@ namespace MQTTnet.Client.Options
|
|||||||
bool? RequestResponseInformation { get; }
|
bool? RequestResponseInformation { get; }
|
||||||
uint? SessionExpiryInterval { get; }
|
uint? SessionExpiryInterval { get; }
|
||||||
ushort? TopicAliasMaximum { get; }
|
ushort? TopicAliasMaximum { get; }
|
||||||
|
List<MqttUserProperty> UserProperties { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using MQTTnet.Client.ExtendedAuthenticationExchange;
|
||||||
using MQTTnet.Client.ExtendedAuthenticationExchange;
|
|
||||||
using MQTTnet.Formatter;
|
using MQTTnet.Formatter;
|
||||||
|
using MQTTnet.Packets;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace MQTTnet.Client.Options
|
namespace MQTTnet.Client.Options
|
||||||
{
|
{
|
||||||
@@ -16,7 +18,7 @@ namespace MQTTnet.Client.Options
|
|||||||
public TimeSpan CommunicationTimeout { get; set; } = TimeSpan.FromSeconds(10);
|
public TimeSpan CommunicationTimeout { get; set; } = TimeSpan.FromSeconds(10);
|
||||||
public TimeSpan KeepAlivePeriod { get; set; } = TimeSpan.FromSeconds(15);
|
public TimeSpan KeepAlivePeriod { get; set; } = TimeSpan.FromSeconds(15);
|
||||||
public TimeSpan? KeepAliveSendInterval { get; set; }
|
public TimeSpan? KeepAliveSendInterval { get; set; }
|
||||||
|
|
||||||
public MqttApplicationMessage WillMessage { get; set; }
|
public MqttApplicationMessage WillMessage { get; set; }
|
||||||
public uint? WillDelayInterval { get; set; }
|
public uint? WillDelayInterval { get; set; }
|
||||||
|
|
||||||
@@ -29,5 +31,6 @@ namespace MQTTnet.Client.Options
|
|||||||
public bool? RequestResponseInformation { get; set; }
|
public bool? RequestResponseInformation { get; set; }
|
||||||
public uint? SessionExpiryInterval { get; set; }
|
public uint? SessionExpiryInterval { get; set; }
|
||||||
public ushort? TopicAliasMaximum { get; set; }
|
public ushort? TopicAliasMaximum { get; set; }
|
||||||
|
public List<MqttUserProperty> UserProperties { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using MQTTnet.Client.ExtendedAuthenticationExchange;
|
using MQTTnet.Client.ExtendedAuthenticationExchange;
|
||||||
using MQTTnet.Formatter;
|
using MQTTnet.Formatter;
|
||||||
|
using MQTTnet.Packets;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -116,6 +118,20 @@ namespace MQTTnet.Client.Options
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MqttClientOptionsBuilder WithUserProperty(string name, string value)
|
||||||
|
{
|
||||||
|
if (name is null) throw new ArgumentNullException(nameof(name));
|
||||||
|
if (value is null) throw new ArgumentNullException(nameof(value));
|
||||||
|
|
||||||
|
if (_options.UserProperties == null)
|
||||||
|
{
|
||||||
|
_options.UserProperties = new List<MqttUserProperty>();
|
||||||
|
}
|
||||||
|
|
||||||
|
_options.UserProperties.Add(new MqttUserProperty(name, value));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public MqttClientOptionsBuilder WithCredentials(string username, string password = null)
|
public MqttClientOptionsBuilder WithCredentials(string username, string password = null)
|
||||||
{
|
{
|
||||||
byte[] passwordBuffer = null;
|
byte[] passwordBuffer = null;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using System;
|
using MQTTnet.Client.Connecting;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using MQTTnet.Client.Connecting;
|
|
||||||
using MQTTnet.Client.Disconnecting;
|
using MQTTnet.Client.Disconnecting;
|
||||||
using MQTTnet.Client.Options;
|
using MQTTnet.Client.Options;
|
||||||
using MQTTnet.Client.Publishing;
|
using MQTTnet.Client.Publishing;
|
||||||
@@ -11,7 +8,9 @@ using MQTTnet.Exceptions;
|
|||||||
using MQTTnet.Packets;
|
using MQTTnet.Packets;
|
||||||
using MQTTnet.Protocol;
|
using MQTTnet.Protocol;
|
||||||
using MQTTnet.Server;
|
using MQTTnet.Server;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using MqttClientSubscribeResult = MQTTnet.Client.Subscribing.MqttClientSubscribeResult;
|
using MqttClientSubscribeResult = MQTTnet.Client.Subscribing.MqttClientSubscribeResult;
|
||||||
|
|
||||||
namespace MQTTnet.Formatter.V5
|
namespace MQTTnet.Formatter.V5
|
||||||
@@ -127,7 +126,8 @@ namespace MQTTnet.Formatter.V5
|
|||||||
RequestProblemInformation = options.RequestProblemInformation,
|
RequestProblemInformation = options.RequestProblemInformation,
|
||||||
RequestResponseInformation = options.RequestResponseInformation,
|
RequestResponseInformation = options.RequestResponseInformation,
|
||||||
SessionExpiryInterval = options.SessionExpiryInterval,
|
SessionExpiryInterval = options.SessionExpiryInterval,
|
||||||
TopicAliasMaximum = options.TopicAliasMaximum
|
TopicAliasMaximum = options.TopicAliasMaximum,
|
||||||
|
UserProperties = options.UserProperties
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -244,11 +244,11 @@ namespace MQTTnet.Formatter.V5
|
|||||||
{
|
{
|
||||||
// QoS 0 has no response. So we treat it as a success always.
|
// QoS 0 has no response. So we treat it as a success always.
|
||||||
// Both enums have the same values. So it can be easily converted.
|
// Both enums have the same values. So it can be easily converted.
|
||||||
result.ReasonCode = (MqttClientPublishReasonCode)pubAckPacket.ReasonCode;
|
result.ReasonCode = (MqttClientPublishReasonCode)pubAckPacket.ReasonCode;
|
||||||
|
|
||||||
result.PacketIdentifier = pubAckPacket.PacketIdentifier;
|
result.PacketIdentifier = pubAckPacket.PacketIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user