|
- using System;
- using MQTTnet.Adapter;
- using MQTTnet.Client;
- using MQTTnet.Diagnostics;
- using MQTTnet.Serializer;
-
- namespace MQTTnet.Implementations
- {
- public class MqttClientAdapterFactory : IMqttClientAdapterFactory
- {
- public IMqttChannelAdapter CreateClientAdapter(IMqttClientOptions options, IMqttNetLogger logger)
- {
- if (options == null) throw new ArgumentNullException(nameof(options));
-
- var serializer = new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion };
-
- switch (options.ChannelOptions)
- {
- case MqttClientTcpOptions tcpOptions:
- {
- return new MqttChannelAdapter(new MqttTcpChannel(tcpOptions), serializer, logger);
- }
-
- case MqttClientWebSocketOptions webSocketOptions:
- {
- return new MqttChannelAdapter(new MqttWebSocketChannel(webSocketOptions), serializer, logger);
- }
-
- default:
- {
- throw new NotSupportedException();
- }
- }
- }
- }
- }
|