|
@@ -191,34 +191,30 @@ namespace MQTTnet.Core.Client |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private async void ProcessReceivedPacketAsync(MqttBasePacket mqttPacket) |
|
|
|
|
|
|
|
|
private Task ProcessReceivedPacketAsync(MqttBasePacket mqttPacket) |
|
|
{ |
|
|
{ |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
if (mqttPacket is MqttPingReqPacket) |
|
|
if (mqttPacket is MqttPingReqPacket) |
|
|
{ |
|
|
{ |
|
|
await SendAsync(new MqttPingRespPacket()); |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
return SendAsync(new MqttPingRespPacket()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (mqttPacket is MqttDisconnectPacket) |
|
|
if (mqttPacket is MqttDisconnectPacket) |
|
|
{ |
|
|
{ |
|
|
await DisconnectAsync(); |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
return DisconnectAsync(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var publishPacket = mqttPacket as MqttPublishPacket; |
|
|
var publishPacket = mqttPacket as MqttPublishPacket; |
|
|
if (publishPacket != null) |
|
|
if (publishPacket != null) |
|
|
{ |
|
|
{ |
|
|
await ProcessReceivedPublishPacket(publishPacket); |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
return ProcessReceivedPublishPacket(publishPacket); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var pubRelPacket = mqttPacket as MqttPubRelPacket; |
|
|
var pubRelPacket = mqttPacket as MqttPubRelPacket; |
|
|
if (pubRelPacket != null) |
|
|
if (pubRelPacket != null) |
|
|
{ |
|
|
{ |
|
|
await ProcessReceivedPubRelPacket(pubRelPacket); |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
return ProcessReceivedPubRelPacket(pubRelPacket); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
_packetDispatcher.Dispatch(mqttPacket); |
|
|
_packetDispatcher.Dispatch(mqttPacket); |
|
@@ -227,6 +223,8 @@ namespace MQTTnet.Core.Client |
|
|
{ |
|
|
{ |
|
|
MqttTrace.Error(nameof(MqttClient), exception, "Error while processing received packet."); |
|
|
MqttTrace.Error(nameof(MqttClient), exception, "Error while processing received packet."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return Task.FromResult(0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void FireApplicationMessageReceivedEvent(MqttPublishPacket publishPacket) |
|
|
private void FireApplicationMessageReceivedEvent(MqttPublishPacket publishPacket) |
|
@@ -246,25 +244,27 @@ namespace MQTTnet.Core.Client |
|
|
ApplicationMessageReceived?.Invoke(this, new MqttApplicationMessageReceivedEventArgs(applicationMessage)); |
|
|
ApplicationMessageReceived?.Invoke(this, new MqttApplicationMessageReceivedEventArgs(applicationMessage)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private async Task ProcessReceivedPublishPacket(MqttPublishPacket publishPacket) |
|
|
|
|
|
|
|
|
private Task ProcessReceivedPublishPacket(MqttPublishPacket publishPacket) |
|
|
{ |
|
|
{ |
|
|
if (publishPacket.QualityOfServiceLevel == MqttQualityOfServiceLevel.AtMostOnce) |
|
|
if (publishPacket.QualityOfServiceLevel == MqttQualityOfServiceLevel.AtMostOnce) |
|
|
{ |
|
|
{ |
|
|
FireApplicationMessageReceivedEvent(publishPacket); |
|
|
FireApplicationMessageReceivedEvent(publishPacket); |
|
|
|
|
|
return Task.FromResult(0); |
|
|
} |
|
|
} |
|
|
else |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (publishPacket.QualityOfServiceLevel == MqttQualityOfServiceLevel.AtLeastOnce) |
|
|
{ |
|
|
{ |
|
|
if (publishPacket.QualityOfServiceLevel == MqttQualityOfServiceLevel.AtLeastOnce) |
|
|
|
|
|
{ |
|
|
|
|
|
FireApplicationMessageReceivedEvent(publishPacket); |
|
|
|
|
|
await SendAsync(new MqttPubAckPacket { PacketIdentifier = publishPacket.PacketIdentifier }); |
|
|
|
|
|
} |
|
|
|
|
|
else if (publishPacket.QualityOfServiceLevel == MqttQualityOfServiceLevel.ExactlyOnce) |
|
|
|
|
|
{ |
|
|
|
|
|
_pendingExactlyOncePublishPackets[publishPacket.PacketIdentifier] = publishPacket; |
|
|
|
|
|
await SendAsync(new MqttPubRecPacket { PacketIdentifier = publishPacket.PacketIdentifier }); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
FireApplicationMessageReceivedEvent(publishPacket); |
|
|
|
|
|
return SendAsync(new MqttPubAckPacket { PacketIdentifier = publishPacket.PacketIdentifier }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (publishPacket.QualityOfServiceLevel == MqttQualityOfServiceLevel.ExactlyOnce) |
|
|
|
|
|
{ |
|
|
|
|
|
_pendingExactlyOncePublishPackets[publishPacket.PacketIdentifier] = publishPacket; |
|
|
|
|
|
return SendAsync(new MqttPubRecPacket { PacketIdentifier = publishPacket.PacketIdentifier }); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
throw new InvalidOperationException(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private async Task ProcessReceivedPubRelPacket(MqttPubRelPacket pubRelPacket) |
|
|
private async Task ProcessReceivedPubRelPacket(MqttPubRelPacket pubRelPacket) |
|
|