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

37 lines
1.3 KiB

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