diff --git a/README.md b/README.md index 7181d72..1a34eee 100644 --- a/README.md +++ b/README.md @@ -83,9 +83,10 @@ This project also listed at Open Collective (https://opencollective.com/mqttnet) This library is used in the following projects: +* HA4IoT (Open Source Home Automation system for .NET, ) * MQTT Client Rx (Wrapper for Reactive Extensions, ) * MQTT Tester (MQTT client test app for [Android](https://play.google.com/store/apps/details?id=com.liveowl.mqtttester) and [iOS](https://itunes.apple.com/us/app/mqtt-tester/id1278621826?mt=8)) -* HA4IoT (Open Source Home Automation system for .NET, ) +* Wirehome.Core (Open Source Home Automation system for .NET Core, ) If you use this library and want to see your project here please let me know. diff --git a/Source/MQTTnet/Client/MqttClientOptionsBuilder.cs b/Source/MQTTnet/Client/MqttClientOptionsBuilder.cs index c03e53a..85e2b4d 100644 --- a/Source/MQTTnet/Client/MqttClientOptionsBuilder.cs +++ b/Source/MQTTnet/Client/MqttClientOptionsBuilder.cs @@ -11,6 +11,7 @@ namespace MQTTnet.Client private MqttClientTcpOptions _tcpOptions; private MqttClientWebSocketOptions _webSocketOptions; private MqttClientOptionsBuilderTlsParameters _tlsParameters; + private MqttClientWebSocketProxyOptions _proxyOptions; public MqttClientOptionsBuilder WithProtocolVersion(MqttProtocolVersion value) { @@ -76,16 +77,9 @@ namespace MQTTnet.Client return this; } -#if NET452 || NET461 - public MqttClientOptionsBuilder WithProxy(string address, string username = null, string password = null, string domain = null, bool bypassOnLocal = false, string[] bypassList = null) { - if (_webSocketOptions == null) - { - throw new InvalidOperationException("A WebSocket channel must be set if MqttClientWebSocketProxy is configured."); - } - - _webSocketOptions.ProxyOptions = new MqttClientWebSocketProxyOptions + _proxyOptions = new MqttClientWebSocketProxyOptions { Address = address, Username = username, @@ -97,7 +91,6 @@ namespace MQTTnet.Client return this; } -#endif public MqttClientOptionsBuilder WithWebSocketServer(string uri) { @@ -120,7 +113,7 @@ namespace MQTTnet.Client return WithTls(new MqttClientOptionsBuilderTlsParameters { UseTls = true }); } - [Obsolete("Use method _WithTlps_ which accepts the _MqttClientOptionsBuilderTlsParameters_.")] + [Obsolete("Use method _WithTls_ which accepts the _MqttClientOptionsBuilderTlsParameters_.")] public MqttClientOptionsBuilder WithTls( bool allowUntrustedCertificates = false, bool ignoreCertificateChainErrors = false, @@ -141,13 +134,13 @@ namespace MQTTnet.Client public IMqttClientOptions Build() { - if (_tlsParameters != null) + if (_tcpOptions == null && _webSocketOptions == null) { - if (_tcpOptions == null && _webSocketOptions == null) - { - throw new InvalidOperationException("A channel (TCP or WebSocket) must be set if TLS is configured."); - } + throw new InvalidOperationException("A channel must be set."); + } + if (_tlsParameters != null) + { if (_tlsParameters?.UseTls == true) { var tlsOptions = new MqttClientTlsOptions @@ -172,6 +165,16 @@ namespace MQTTnet.Client } } + if (_proxyOptions != null) + { + if (_webSocketOptions == null) + { + throw new InvalidOperationException("Proxies are only supported for WebSocket connections."); + } + + _webSocketOptions.ProxyOptions = _proxyOptions; + } + _options.ChannelOptions = (IMqttClientChannelOptions)_tcpOptions ?? _webSocketOptions; return _options; diff --git a/Source/MQTTnet/Client/MqttClientWebSocketProxyOptions.cs b/Source/MQTTnet/Client/MqttClientWebSocketProxyOptions.cs index 0ac9df1..13b1366 100644 --- a/Source/MQTTnet/Client/MqttClientWebSocketProxyOptions.cs +++ b/Source/MQTTnet/Client/MqttClientWebSocketProxyOptions.cs @@ -10,7 +10,7 @@ public string Domain { get; set; } - public bool BypassOnLocal { get; set; } = true; + public bool BypassOnLocal { get; set; } public string[] BypassList { get; set; } }