Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed Dec 2, 2024
2 parents 4aa4a12 + 6bf2b4e commit ef5b6c9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
35 changes: 25 additions & 10 deletions Source/MQTTnet/Options/MqttClientOptionsBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using MQTTnet.Formatter;
using MQTTnet.Packets;
using MQTTnet.Protocol;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Text;
using MQTTnet.Formatter;
using MQTTnet.Packets;
using MQTTnet.Protocol;

namespace MQTTnet;

Expand Down Expand Up @@ -138,20 +138,35 @@ public MqttClientOptionsBuilder WithConnectionUri(Uri uri)
{
case "tcp":
case "mqtt":
WithTcpServer(uri.Host, port);
WithTcpServer(uri.Host, port)
.WithAddressFamily(AddressFamily.Unspecified)
.WithProtocolType(ProtocolType.Tcp)
.WithTlsOptions(o => o.UseTls(false));
break;

case "mqtts":
WithTcpServer(uri.Host, port)
.WithTlsOptions(
o =>
{
});
.WithAddressFamily(AddressFamily.Unspecified)
.WithProtocolType(ProtocolType.Tcp)
.WithTlsOptions(o => o.UseTls(true));
break;

case "ws":
WithWebSocketServer(o => o.WithUri(uri.ToString()))
.WithTlsOptions(o => o.UseTls(false));
break;

case "wss":
WithWebSocketServer(o => o.WithUri(uri.ToString()));
WithWebSocketServer(o => o.WithUri(uri.ToString()))
.WithTlsOptions(o => o.UseTls(true));
break;

// unix:///path/to/socket
case "unix":
WithEndPoint(new UnixDomainSocketEndPoint(uri.AbsolutePath))
.WithAddressFamily(AddressFamily.Unix)
.WithProtocolType(ProtocolType.Unspecified)
.WithTlsOptions(o => o.UseTls(false));
break;

default:
Expand Down
6 changes: 6 additions & 0 deletions Source/MQTTnet/Options/MqttClientWebSocketOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public MqttClientWebSocketOptionsBuilder WithSubProtocols(ICollection<string> su

public MqttClientWebSocketOptionsBuilder WithUri(string uri)
{
var webSocketUri = new Uri(uri, UriKind.Absolute);
if (webSocketUri.Scheme != Uri.UriSchemeWs && webSocketUri.Scheme != Uri.UriSchemeWss)
{
throw new ArgumentException("The scheme of the WebSocket Uri must be ws or wss.");
}

_webSocketOptions.Uri = uri;
return this;
}
Expand Down

0 comments on commit ef5b6c9

Please sign in to comment.