mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 17:00:03 +08:00
52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using MQTTnet.Adapter;
|
|
using MQTTnet.Client.Options;
|
|
using MQTTnet.Diagnostics;
|
|
using MQTTnet.Formatter;
|
|
using MQTTnet.Implementations;
|
|
using System;
|
|
using MQTTnet.Diagnostics.Logger;
|
|
|
|
namespace MQTTnet.Extensions.WebSocket4Net
|
|
{
|
|
public sealed class WebSocket4NetMqttClientAdapterFactory : IMqttClientAdapterFactory
|
|
{
|
|
readonly IMqttNetLogger _logger;
|
|
|
|
public WebSocket4NetMqttClientAdapterFactory(IMqttNetLogger logger)
|
|
{
|
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
|
}
|
|
|
|
public IMqttChannelAdapter CreateClientAdapter(IMqttClientOptions options)
|
|
{
|
|
if (options == null) throw new ArgumentNullException(nameof(options));
|
|
|
|
switch (options.ChannelOptions)
|
|
{
|
|
case MqttClientTcpOptions _:
|
|
{
|
|
return new MqttChannelAdapter(
|
|
new MqttTcpChannel(options),
|
|
new MqttPacketFormatterAdapter(options.ProtocolVersion),
|
|
options.PacketInspector,
|
|
_logger);
|
|
}
|
|
|
|
case MqttClientWebSocketOptions webSocketOptions:
|
|
{
|
|
return new MqttChannelAdapter(
|
|
new WebSocket4NetMqttChannel(options, webSocketOptions),
|
|
new MqttPacketFormatterAdapter(options.ProtocolVersion),
|
|
options.PacketInspector,
|
|
_logger);
|
|
}
|
|
|
|
default:
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|