mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 17:00:03 +08:00
32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using MQTTnet.Client.Receiving;
|
|
|
|
namespace MQTTnet.Extensions.Rpc
|
|
{
|
|
public sealed class RpcAwareApplicationMessageReceivedHandler : IMqttApplicationMessageReceivedHandler
|
|
{
|
|
readonly Func<MqttApplicationMessageReceivedEventArgs, Task> _handleReceivedApplicationMessageAsync;
|
|
|
|
public RpcAwareApplicationMessageReceivedHandler(
|
|
IMqttApplicationMessageReceivedHandler originalHandler,
|
|
Func<MqttApplicationMessageReceivedEventArgs, Task> handleReceivedApplicationMessageAsync)
|
|
{
|
|
OriginalHandler = originalHandler;
|
|
_handleReceivedApplicationMessageAsync = handleReceivedApplicationMessageAsync ?? throw new ArgumentNullException(nameof(handleReceivedApplicationMessageAsync));
|
|
}
|
|
|
|
public IMqttApplicationMessageReceivedHandler OriginalHandler { get; }
|
|
|
|
public Task HandleApplicationMessageReceivedAsync(MqttApplicationMessageReceivedEventArgs eventArgs)
|
|
{
|
|
if (OriginalHandler != null)
|
|
{
|
|
return OriginalHandler.HandleApplicationMessageReceivedAsync(eventArgs);
|
|
}
|
|
|
|
return _handleReceivedApplicationMessageAsync(eventArgs);
|
|
}
|
|
}
|
|
}
|