Browse Source

Add several new options to the WebSocket options

release/3.x.x
Christian Kratky 7 years ago
parent
commit
84a647e712
4 changed files with 75 additions and 1 deletions
  1. +1
    -0
      Build/MQTTnet.nuspec
  2. +32
    -0
      Frameworks/MQTTnet.NetStandard/Implementations/MqttWebSocketChannel.cs
  3. +32
    -0
      Frameworks/MQTTnet.UniversalWindows/Implementations/MqttWebSocketChannel.cs
  4. +10
    -1
      MQTTnet.Core/Client/MqttClientWebSocketOptions.cs

+ 1
- 0
Build/MQTTnet.nuspec View File

@@ -16,6 +16,7 @@
* [Client] Added a first version of a managed client which will manage the connection, subscription etc. automatically (Thanks to @JTrotta) * [Client] Added a first version of a managed client which will manage the connection, subscription etc. automatically (Thanks to @JTrotta)
* [Client] The session state response from the server is now returned in the _ConnectAsync_ method and also part of the _Connected_ event args * [Client] The session state response from the server is now returned in the _ConnectAsync_ method and also part of the _Connected_ event args
* [Client] Added a _TopicFilterBuilder_ using a fluent API (Namespace Changes!) * [Client] Added a _TopicFilterBuilder_ using a fluent API (Namespace Changes!)
* [Client] Added several new options for the WebSocket channel (Thanks to @ChristianRiedl)
* [Server] Added support for WebSockets via ASP.NET Core 2.0 (Thanks to @ChristianRiedl) * [Server] Added support for WebSockets via ASP.NET Core 2.0 (Thanks to @ChristianRiedl)
* [Server] Added support for a custom application message interceptor * [Server] Added support for a custom application message interceptor
</releaseNotes> </releaseNotes>


+ 32
- 0
Frameworks/MQTTnet.NetStandard/Implementations/MqttWebSocketChannel.cs View File

@@ -3,6 +3,7 @@ using MQTTnet.Core.Client;
using System; using System;
using System.IO; using System.IO;
using System.Net.WebSockets; using System.Net.WebSockets;
using System.Security.Cryptography.X509Certificates;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;


@@ -32,6 +33,37 @@ namespace MQTTnet.Implementations


_webSocket = new ClientWebSocket(); _webSocket = new ClientWebSocket();
_webSocket.Options.KeepAliveInterval = _options.KeepAlivePeriod; _webSocket.Options.KeepAliveInterval = _options.KeepAlivePeriod;

if (_options.RequestHeaders != null)
{
foreach (var requestHeader in _options.RequestHeaders)
{
_webSocket.Options.SetRequestHeader(requestHeader.Key, requestHeader.Value);
}
}

if (_options.SubProtocols != null)
{
foreach (var subProtocol in _options.SubProtocols)
{
_webSocket.Options.AddSubProtocol(subProtocol);
}
}

if (_options.CookieContainer != null)
{
_webSocket.Options.Cookies = _options.CookieContainer;
}

if (_options.TlsOptions?.UseTls == true && _options.TlsOptions?.Certificates != null)
{
_webSocket.Options.ClientCertificates = new X509CertificateCollection();
foreach (var certificate in _options.TlsOptions.Certificates)
{
_webSocket.Options.ClientCertificates.Add(new X509Certificate(certificate));
}
}

await _webSocket.ConnectAsync(new Uri(uri), CancellationToken.None); await _webSocket.ConnectAsync(new Uri(uri), CancellationToken.None);
RawReceiveStream = new WebSocketStream(_webSocket); RawReceiveStream = new WebSocketStream(_webSocket);
} }


+ 32
- 0
Frameworks/MQTTnet.UniversalWindows/Implementations/MqttWebSocketChannel.cs View File

@@ -3,6 +3,7 @@ using MQTTnet.Core.Client;
using System; using System;
using System.IO; using System.IO;
using System.Net.WebSockets; using System.Net.WebSockets;
using System.Security.Cryptography.X509Certificates;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;


@@ -32,6 +33,37 @@ namespace MQTTnet.Implementations


_webSocket = new ClientWebSocket(); _webSocket = new ClientWebSocket();
_webSocket.Options.KeepAliveInterval = _options.KeepAlivePeriod; _webSocket.Options.KeepAliveInterval = _options.KeepAlivePeriod;

if (_options.RequestHeaders != null)
{
foreach (var requestHeader in _options.RequestHeaders)
{
_webSocket.Options.SetRequestHeader(requestHeader.Key, requestHeader.Value);
}
}

if (_options.SubProtocols != null)
{
foreach (var subProtocol in _options.SubProtocols)
{
_webSocket.Options.AddSubProtocol(subProtocol);
}
}

if (_options.CookieContainer != null)
{
_webSocket.Options.Cookies = _options.CookieContainer;
}

if (_options.TlsOptions?.UseTls == true && _options.TlsOptions?.Certificates != null)
{
_webSocket.Options.ClientCertificates = new X509CertificateCollection();
foreach (var certificate in _options.TlsOptions.Certificates)
{
_webSocket.Options.ClientCertificates.Add(new X509Certificate(certificate));
}
}

await _webSocket.ConnectAsync(new Uri(uri), CancellationToken.None).ConfigureAwait(false); await _webSocket.ConnectAsync(new Uri(uri), CancellationToken.None).ConfigureAwait(false);


RawReceiveStream = new WebSocketStream(_webSocket); RawReceiveStream = new WebSocketStream(_webSocket);


+ 10
- 1
MQTTnet.Core/Client/MqttClientWebSocketOptions.cs View File

@@ -1,7 +1,16 @@
namespace MQTTnet.Core.Client
using System.Collections.Generic;
using System.Net;

namespace MQTTnet.Core.Client
{ {
public class MqttClientWebSocketOptions : BaseMqttClientOptions public class MqttClientWebSocketOptions : BaseMqttClientOptions
{ {
public string Uri { get; set; } public string Uri { get; set; }

public IDictionary<string, string> RequestHeaders { get; set; }

public ICollection<string> SubProtocols { get; set; }

public CookieContainer CookieContainer { get; set; }
} }
} }

Loading…
Cancel
Save