Skip to content

Commit

Permalink
Add new options for _MqttClientOptionsBuilder_.
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed May 10, 2019
1 parent 1a8bcae commit b02f308
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions Build/MQTTnet.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
40 changes: 39 additions & 1 deletion Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ public MqttClientOptionsBuilder WithTcpServer(string server, int? port = null)
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
Expand All @@ -151,6 +161,15 @@ public MqttClientOptionsBuilder WithProxy(string address, string username = null
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
Expand All @@ -163,9 +182,19 @@ public MqttClientOptionsBuilder WithWebSocketServer(string uri, MqttClientOption
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;
}

Expand All @@ -174,6 +203,15 @@ public MqttClientOptionsBuilder WithTls()
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)
Expand Down

0 comments on commit b02f308

Please sign in to comment.