25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

27 lines
960 B

  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(IMqttClientChannelOptions options, IMqttNetLogger logger)
  11. {
  12. if (options == null) throw new ArgumentNullException(nameof(options));
  13. switch (options)
  14. {
  15. case MqttClientTcpOptions tcpOptions:
  16. return new MqttChannelAdapter(new MqttTcpChannel(tcpOptions), new MqttPacketSerializer(), logger);
  17. case MqttClientWebSocketOptions webSocketOptions:
  18. return new MqttChannelAdapter(new MqttWebSocketChannel(webSocketOptions), new MqttPacketSerializer(), logger);
  19. default:
  20. throw new NotSupportedException();
  21. }
  22. }
  23. }
  24. }