Browse Source

Add new options for _MqttClientOptionsBuilder_.

release/3.x.x
Christian Kratky 5 years ago
parent
commit
b02f30844c
2 changed files with 40 additions and 1 deletions
  1. +1
    -0
      Build/MQTTnet.nuspec
  2. +39
    -1
      Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs

+ 1
- 0
Build/MQTTnet.nuspec View File

@@ -14,6 +14,7 @@
* [Core] Fixed missing properties from PUBLISH packet in _MqttApplicationMessage_ (thanks to @pcbing).
* [Core] Fixed wrong encoding of PUBREL and PUBCOMP packets for MQTTv5 (thanks to @perphilipp).
* [Client] Added the authentication result to the disconnected handler (only set when connecting failed).
* [Client] Added new overloads for _MqttClientOptionsBuilder_.
* [Server] Fixed a bug which returns wrong flag for existing session in CONNACK packet (thanks to @avengerstark).
* [nuget] .NET Framework builds are now using 4.5.2 or 4.6.1 builds instead of netstandard 2.0.
</releaseNotes>


+ 39
- 1
Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs View File

@@ -136,6 +136,16 @@ namespace MQTTnet.Client.Options
return this;
}

public MqttClientOptionsBuilder WithTcpServer(Action<MqttClientTcpOptions> optionsBuilder)
{
if (optionsBuilder == null) throw new ArgumentNullException(nameof(optionsBuilder));

_tcpOptions = new MqttClientTcpOptions();
optionsBuilder.Invoke(_tcpOptions);

return this;
}

public MqttClientOptionsBuilder WithProxy(string address, string username = null, string password = null, string domain = null, bool bypassOnLocal = false, string[] bypassList = null)
{
_proxyOptions = new MqttClientWebSocketProxyOptions
@@ -151,6 +161,15 @@ namespace MQTTnet.Client.Options
return this;
}

public MqttClientOptionsBuilder WithProxy(Action<MqttClientWebSocketProxyOptions> optionsBuilder)
{
if (optionsBuilder == null) throw new ArgumentNullException(nameof(optionsBuilder));

_proxyOptions = new MqttClientWebSocketProxyOptions();
optionsBuilder(_proxyOptions);
return this;
}

public MqttClientOptionsBuilder WithWebSocketServer(string uri, MqttClientOptionsBuilderWebSocketParameters parameters = null)
{
_webSocketOptions = new MqttClientWebSocketOptions
@@ -163,9 +182,19 @@ namespace MQTTnet.Client.Options
return this;
}

public MqttClientOptionsBuilder WithWebSocketServer(Action<MqttClientWebSocketOptions> optionsBuilder)
{
if (optionsBuilder == null) throw new ArgumentNullException(nameof(optionsBuilder));

_webSocketOptions = new MqttClientWebSocketOptions();
optionsBuilder.Invoke(_webSocketOptions);

return this;
}

public MqttClientOptionsBuilder WithTls(MqttClientOptionsBuilderTlsParameters parameters)
{
_tlsParameters = parameters ?? throw new ArgumentNullException(nameof(parameters));
_tlsParameters = parameters;
return this;
}

@@ -174,6 +203,15 @@ namespace MQTTnet.Client.Options
return WithTls(new MqttClientOptionsBuilderTlsParameters { UseTls = true });
}

public MqttClientOptionsBuilder WithTls(Action<MqttClientOptionsBuilderTlsParameters> optionsBuilder)
{
if (optionsBuilder == null) throw new ArgumentNullException(nameof(optionsBuilder));

_tlsParameters = new MqttClientOptionsBuilderTlsParameters();
optionsBuilder(_tlsParameters);
return this;
}

public IMqttClientOptions Build()
{
if (_tcpOptions == null && _webSocketOptions == null)


Loading…
Cancel
Save