mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 01:03:01 +08:00
* Expose more options in disconnect options. * Expose more options in disconnect API. * Refactor code. * Expose user properties in disconnected event. * Expose more disconnect options in server. * Fix build errors * Add new samples. * Fix client cleanup * Fix merge conflicts
49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
// Licensed to the .NET Foundation under one or more agreements.
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using MQTTnet.Client;
|
|
using MQTTnet.Packets;
|
|
using MQTTnet.Protocol;
|
|
|
|
namespace MQTTnet.Formatter
|
|
{
|
|
public sealed class MqttDisconnectPacketFactory
|
|
{
|
|
readonly MqttDisconnectPacket _normalDisconnection = new MqttDisconnectPacket
|
|
{
|
|
ReasonCode = MqttDisconnectReasonCode.NormalDisconnection
|
|
};
|
|
|
|
public MqttDisconnectPacket Create(MqttDisconnectReasonCode reasonCode)
|
|
{
|
|
if (reasonCode == MqttDisconnectReasonCode.NormalDisconnection)
|
|
{
|
|
return _normalDisconnection;
|
|
}
|
|
|
|
return new MqttDisconnectPacket
|
|
{
|
|
ReasonCode = reasonCode
|
|
};
|
|
}
|
|
|
|
public MqttDisconnectPacket Create(MqttClientDisconnectOptions clientDisconnectOptions)
|
|
{
|
|
var packet = new MqttDisconnectPacket();
|
|
|
|
if (clientDisconnectOptions == null)
|
|
{
|
|
packet.ReasonCode = MqttDisconnectReasonCode.NormalDisconnection;
|
|
}
|
|
else
|
|
{
|
|
packet.ReasonCode = (MqttDisconnectReasonCode)clientDisconnectOptions.Reason;
|
|
packet.UserProperties = clientDisconnectOptions.UserProperties;
|
|
packet.SessionExpiryInterval = clientDisconnectOptions.SessionExpiryInterval;
|
|
}
|
|
|
|
return packet;
|
|
}
|
|
}
|
|
} |