mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 01:03:01 +08:00
# Conflicts: # Build/MQTTnet.nuspec # Source/MQTTnet/Server/Internal/MqttClientSessionsManager.cs
44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using MQTTnet.Adapter;
|
|
using MQTTnet.Formatter;
|
|
using MQTTnet.Implementations;
|
|
using System;
|
|
using MQTTnet.Client;
|
|
using MQTTnet.Diagnostics;
|
|
|
|
namespace MQTTnet.Extensions.WebSocket4Net
|
|
{
|
|
public sealed class WebSocket4NetMqttClientAdapterFactory : IMqttClientAdapterFactory
|
|
{
|
|
public IMqttChannelAdapter CreateClientAdapter(IMqttClientOptions options, IMqttNetLogger logger)
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|