You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

37 lines
1.2 KiB

  1. using System;
  2. using MQTTnet.Adapter;
  3. using MQTTnet.Client;
  4. using MQTTnet.Diagnostics;
  5. using MQTTnet.Serializer;
  6. namespace MQTTnet.Implementations
  7. {
  8. public class MqttClientAdapterFactory : IMqttClientAdapterFactory
  9. {
  10. public IMqttChannelAdapter CreateClientAdapter(IMqttClientOptions options, IMqttNetChildLogger logger)
  11. {
  12. if (options == null) throw new ArgumentNullException(nameof(options));
  13. var serializer = new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion };
  14. switch (options.ChannelOptions)
  15. {
  16. case MqttClientTcpOptions tcpOptions:
  17. {
  18. return new MqttChannelAdapter(new MqttTcpChannel(tcpOptions), serializer, logger);
  19. }
  20. case MqttClientWebSocketOptions webSocketOptions:
  21. {
  22. return new MqttChannelAdapter(new MqttWebSocketChannel(webSocketOptions), serializer, logger);
  23. }
  24. default:
  25. {
  26. throw new NotSupportedException();
  27. }
  28. }
  29. }
  30. }
  31. }