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.

MqttCommunicationAdapterFactory.cs 1017 B

преди 7 години
123456789101112131415161718192021222324252627
  1. using System;
  2. using MQTTnet.Core.Adapter;
  3. using MQTTnet.Core.Client;
  4. using MQTTnet.Core.Serializer;
  5. namespace MQTTnet.Implementations
  6. {
  7. public class MqttCommunicationAdapterFactory : IMqttCommunicationAdapterFactory
  8. {
  9. public IMqttCommunicationAdapter CreateMqttCommunicationAdapter(MqttClientOptions options)
  10. {
  11. if (options == null) throw new ArgumentNullException(nameof(options));
  12. if (options is MqttClientTcpOptions tcpOptions)
  13. {
  14. return new MqttChannelCommunicationAdapter(new MqttTcpChannel(tcpOptions), new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion });
  15. }
  16. if (options is MqttClientWebSocketOptions webSocketOptions)
  17. {
  18. return new MqttChannelCommunicationAdapter(new MqttWebSocketChannel(webSocketOptions), new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion });
  19. }
  20. throw new NotSupportedException();
  21. }
  22. }
  23. }