mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-17 01:33:03 +08:00
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using System;
|
|
using MQTTnet.Adapter;
|
|
using MQTTnet.Client;
|
|
using MQTTnet.Diagnostics;
|
|
using MQTTnet.Formatter;
|
|
|
|
namespace MQTTnet.Implementations
|
|
{
|
|
public class MqttClientAdapterFactory : IMqttClientAdapterFactory
|
|
{
|
|
public IMqttChannelAdapter CreateClientAdapter(IMqttClientOptions options, IMqttNetChildLogger logger)
|
|
{
|
|
if (options == null) throw new ArgumentNullException(nameof(options));
|
|
|
|
switch (options.ChannelOptions)
|
|
{
|
|
case MqttClientTcpOptions _:
|
|
{
|
|
return new MqttChannelAdapter(new MqttTcpChannel(options), new MqttPacketFormatterAdapter(options.ProtocolVersion), logger);
|
|
}
|
|
|
|
case MqttClientWebSocketOptions webSocketOptions:
|
|
{
|
|
return new MqttChannelAdapter(new MqttWebSocketChannel(webSocketOptions), new MqttPacketFormatterAdapter(options.ProtocolVersion), logger);
|
|
}
|
|
|
|
default:
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|