2024-03-12 14:05:27 -04:00
|
|
|
using CommonSocketLibrary.Abstract;
|
|
|
|
using CommonSocketLibrary.Common;
|
2024-06-16 20:19:31 -04:00
|
|
|
using Serilog;
|
2024-03-12 14:05:27 -04:00
|
|
|
using TwitchChatTTS.OBS.Socket.Data;
|
2024-07-12 13:36:09 -04:00
|
|
|
using TwitchChatTTS.OBS.Socket.Manager;
|
2024-03-12 14:05:27 -04:00
|
|
|
|
|
|
|
namespace TwitchChatTTS.OBS.Socket.Handlers
|
|
|
|
{
|
|
|
|
public class IdentifiedHandler : IWebSocketHandler
|
|
|
|
{
|
2024-07-12 13:36:09 -04:00
|
|
|
private readonly OBSManager _manager;
|
2024-06-24 18:11:36 -04:00
|
|
|
private readonly ILogger _logger;
|
|
|
|
public int OperationCode { get; } = 2;
|
2024-03-12 14:05:27 -04:00
|
|
|
|
2024-07-12 13:36:09 -04:00
|
|
|
public IdentifiedHandler(OBSManager manager, ILogger logger)
|
2024-06-16 20:19:31 -04:00
|
|
|
{
|
2024-07-12 13:36:09 -04:00
|
|
|
_manager = manager;
|
2024-06-24 18:11:36 -04:00
|
|
|
_logger = logger;
|
2024-03-12 14:05:27 -04:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:11:36 -04:00
|
|
|
public async Task Execute<Data>(SocketClient<WebSocketMessage> sender, Data data)
|
2024-03-12 14:05:27 -04:00
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
if (data is not IdentifiedMessage message || message == null)
|
2024-03-12 14:05:27 -04:00
|
|
|
return;
|
2024-06-16 20:19:31 -04:00
|
|
|
|
2024-07-16 00:48:55 -04:00
|
|
|
_manager.Connected = true;
|
2024-06-24 18:11:36 -04:00
|
|
|
_logger.Information("Connected to OBS via rpc version " + message.NegotiatedRpcVersion + ".");
|
2024-07-12 13:36:09 -04:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
await _manager.GetGroupList(async groups => await _manager.GetGroupSceneItemList(groups));
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
_logger.Error(e, "Failed to load OBS group info upon OBS identification.");
|
|
|
|
}
|
2024-07-16 00:48:55 -04:00
|
|
|
|
|
|
|
await _manager.UpdateStreamingState();
|
2024-03-12 14:05:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|