mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-19 19:13:11 +08:00
Added support for websockets
This commit is contained in:
@@ -3,6 +3,7 @@ using MQTTnet.Core.Adapter;
|
||||
using MQTTnet.Core.Client;
|
||||
using MQTTnet.Core.Serializer;
|
||||
using MQTTnet.Implementations;
|
||||
using MQTTnet.Core.Channel;
|
||||
|
||||
namespace MQTTnet
|
||||
{
|
||||
@@ -12,7 +13,23 @@ namespace MQTTnet
|
||||
{
|
||||
if (options == null) throw new ArgumentNullException(nameof(options));
|
||||
|
||||
return new MqttClient(options, new MqttChannelCommunicationAdapter(new MqttTcpChannel(), new MqttPacketSerializer()));
|
||||
return new MqttClient(options, new MqttChannelCommunicationAdapter(GetMqttCommunicationChannel(options), new MqttPacketSerializer()));
|
||||
}
|
||||
|
||||
private IMqttCommunicationChannel GetMqttCommunicationChannel(MqttClientOptions options)
|
||||
{
|
||||
switch (options.ConnectionType)
|
||||
{
|
||||
case ConnectionTypes.TCP:
|
||||
case ConnectionTypes.TLS:
|
||||
return new MqttTcpChannel();
|
||||
case ConnectionTypes.WS:
|
||||
case ConnectionTypes.WSS:
|
||||
return new MqttWebSocketsChannel();
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user