mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-17 01:33:03 +08:00
33 lines
1.3 KiB
C#
33 lines
1.3 KiB
C#
using System;
|
|
using MQTTnet.Core.Adapter;
|
|
using MQTTnet.Core.Client;
|
|
using MQTTnet.Core.Serializer;
|
|
|
|
namespace MQTTnet.Implementations
|
|
{
|
|
public class MqttCommunicationAdapterFactory : IMqttCommunicationAdapterFactory
|
|
{
|
|
public IMqttCommunicationAdapter CreateMqttCommunicationAdapter(IMqttClientOptions options)
|
|
{
|
|
if (options == null) throw new ArgumentNullException(nameof(options));
|
|
|
|
if (options is MqttClientTcpOptions tcpOptions)
|
|
{
|
|
return new MqttChannelCommunicationAdapter(new MqttTcpChannel(tcpOptions), new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion });
|
|
}
|
|
|
|
if (options is MqttClientWebSocketOptions webSocketOptions)
|
|
{
|
|
return new MqttChannelCommunicationAdapter(new MqttWebSocketChannel(webSocketOptions), new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion });
|
|
}
|
|
|
|
if (options is MqttClientManagedOptions queuedOptions)
|
|
{
|
|
return new MqttChannelCommunicationAdapter(new MqttTcpChannel(queuedOptions), new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion });
|
|
}
|
|
|
|
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
} |