ソースを参照

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; }
}
}

読み込み中…
キャンセル
保存