mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 01:03:01 +08:00
30 lines
1.1 KiB
C#
30 lines
1.1 KiB
C#
using System;
|
|
using MQTTnet.Core.Adapter;
|
|
using MQTTnet.Core.Client;
|
|
using MQTTnet.Core.Diagnostics;
|
|
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)
|
|
{
|
|
var trace = new MqttNetTrace();
|
|
return new MqttChannelCommunicationAdapter(new MqttTcpChannel(tcpOptions), new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion }, trace);
|
|
}
|
|
|
|
if (options is MqttClientWebSocketOptions webSocketOptions)
|
|
{
|
|
var trace = new MqttNetTrace();
|
|
return new MqttChannelCommunicationAdapter(new MqttWebSocketChannel(webSocketOptions), new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion }, trace);
|
|
}
|
|
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
} |