Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

37 rindas
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, IMqttNetLogger 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. }