瀏覽代碼

Add several new options to the WebSocket options

release/3.x.x
Christian Kratky 7 年之前
父節點
當前提交
84a647e712
共有 4 個檔案被更改,包括 75 行新增1 行删除
  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 查看文件

@@ -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] 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 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 a custom application message interceptor
</releaseNotes>


+ 32
- 0
Frameworks/MQTTnet.NetStandard/Implementations/MqttWebSocketChannel.cs 查看文件

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

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

_webSocket = new ClientWebSocket();
_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);
RawReceiveStream = new WebSocketStream(_webSocket);
}


+ 32
- 0
Frameworks/MQTTnet.UniversalWindows/Implementations/MqttWebSocketChannel.cs 查看文件

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

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

_webSocket = new ClientWebSocket();
_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);

RawReceiveStream = new WebSocketStream(_webSocket);


+ 10
- 1
MQTTnet.Core/Client/MqttClientWebSocketOptions.cs 查看文件

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

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

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

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

public CookieContainer CookieContainer { get; set; }
}
}

Loading…
取消
儲存