2024-03-15 08:27:35 -04:00
|
|
|
using CommonSocketLibrary.Abstract;
|
|
|
|
using CommonSocketLibrary.Common;
|
|
|
|
using HermesSocketLibrary.Socket.Data;
|
2024-06-16 20:19:31 -04:00
|
|
|
using Serilog;
|
2024-11-08 10:32:42 -05:00
|
|
|
using TwitchChatTTS.Hermes.Socket.Requests;
|
2024-03-15 08:27:35 -04:00
|
|
|
|
|
|
|
namespace TwitchChatTTS.Hermes.Socket.Handlers
|
|
|
|
{
|
|
|
|
public class RequestAckHandler : IWebSocketHandler
|
|
|
|
{
|
2024-11-08 10:32:42 -05:00
|
|
|
private readonly RequestAckManager _manager;
|
2024-03-15 08:27:35 -04:00
|
|
|
private readonly ILogger _logger;
|
2024-06-16 20:19:31 -04:00
|
|
|
|
2024-06-24 18:11:36 -04:00
|
|
|
public int OperationCode { get; } = 4;
|
2024-03-15 08:27:35 -04:00
|
|
|
|
2024-07-16 00:48:55 -04:00
|
|
|
|
|
|
|
public RequestAckHandler(
|
2024-11-08 10:32:42 -05:00
|
|
|
RequestAckManager manager,
|
2024-07-16 00:48:55 -04:00
|
|
|
ILogger logger
|
|
|
|
)
|
2024-06-16 20:19:31 -04:00
|
|
|
{
|
2024-11-08 10:32:42 -05:00
|
|
|
_manager = manager;
|
2024-03-15 08:27:35 -04:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2024-06-24 18:11:36 -04:00
|
|
|
public async Task Execute<Data>(SocketClient<WebSocketMessage> sender, Data data)
|
2024-03-15 08:27:35 -04:00
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
if (data is not RequestAckMessage message || message == null)
|
2024-03-15 08:27:35 -04:00
|
|
|
return;
|
2024-06-24 18:11:36 -04:00
|
|
|
if (message.Request == null)
|
2024-07-16 00:48:55 -04:00
|
|
|
{
|
|
|
|
_logger.Warning("Received a Hermes request message without a proper request.");
|
2024-03-15 08:27:35 -04:00
|
|
|
return;
|
2024-07-16 00:48:55 -04:00
|
|
|
}
|
2024-03-15 08:27:35 -04:00
|
|
|
|
2024-07-16 00:48:55 -04:00
|
|
|
_logger.Debug($"Received a Hermes request message [type: {message.Request.Type}][data: {string.Join(',', message.Request.Data?.Select(entry => entry.Key + '=' + entry.Value) ?? Array.Empty<string>())}]");
|
2024-11-08 10:32:42 -05:00
|
|
|
var json = message.Data?.ToString();
|
|
|
|
if (message.Request.Type == null || json == null)
|
2024-07-19 12:56:41 -04:00
|
|
|
{
|
2024-11-08 10:32:42 -05:00
|
|
|
return;
|
2024-07-16 00:48:55 -04:00
|
|
|
}
|
2024-11-08 10:32:42 -05:00
|
|
|
_manager.Fulfill(message.Request.Type, message.Request.RequestId, json, message.Request.Data);
|
2024-03-15 08:27:35 -04:00
|
|
|
}
|
|
|
|
}
|
2024-07-16 00:48:55 -04:00
|
|
|
|
|
|
|
public class HermesRequestData
|
|
|
|
{
|
|
|
|
public Action<IDictionary<string, object>?>? Callback { get; set; }
|
|
|
|
public IDictionary<string, object>? Data { get; set; }
|
|
|
|
}
|
2024-03-15 08:27:35 -04:00
|
|
|
}
|