Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

37 wiersze
1.3 KiB

  1. using MQTTnet.Adapter;
  2. using MQTTnet.Client.Options;
  3. using MQTTnet.Diagnostics;
  4. using MQTTnet.Formatter;
  5. using MQTTnet.Implementations;
  6. using System;
  7. namespace MQTTnet.Extensions.WebSocket4Net
  8. {
  9. public class WebSocket4NetMqttClientAdapterFactory : IMqttClientAdapterFactory
  10. {
  11. public IMqttChannelAdapter CreateClientAdapter(IMqttClientOptions options, IMqttNetLogger 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. }