2024-06-16 20:19:31 -04:00
|
|
|
using Serilog;
|
2024-03-12 14:05:27 -04:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using CommonSocketLibrary.Socket.Manager;
|
|
|
|
using CommonSocketLibrary.Common;
|
|
|
|
|
|
|
|
namespace TwitchChatTTS.OBS.Socket.Manager
|
|
|
|
{
|
|
|
|
public class OBSHandlerManager : WebSocketHandlerManager
|
|
|
|
{
|
2024-06-16 20:19:31 -04:00
|
|
|
public OBSHandlerManager(ILogger logger, IServiceProvider provider) : base(logger)
|
|
|
|
{
|
2024-03-12 14:05:27 -04:00
|
|
|
var basetype = typeof(IWebSocketHandler);
|
|
|
|
var assembly = GetType().Assembly;
|
|
|
|
var types = assembly.GetTypes().Where(t => t.IsClass && basetype.IsAssignableFrom(t) && t.AssemblyQualifiedName?.Contains(".OBS.") == true);
|
|
|
|
|
2024-06-16 20:19:31 -04:00
|
|
|
foreach (var type in types)
|
|
|
|
{
|
2024-03-12 14:05:27 -04:00
|
|
|
var key = "obs-" + type.Name.Replace("Handlers", "Hand#lers")
|
|
|
|
.Replace("Handler", "")
|
|
|
|
.Replace("Hand#lers", "Handlers")
|
|
|
|
.ToLower();
|
|
|
|
var handler = provider.GetKeyedService<IWebSocketHandler>(key);
|
2024-06-16 20:19:31 -04:00
|
|
|
if (handler == null)
|
|
|
|
{
|
|
|
|
logger.Error("Failed to find obs websocket handler: " + type.AssemblyQualifiedName);
|
2024-03-12 14:05:27 -04:00
|
|
|
continue;
|
|
|
|
}
|
2024-06-16 20:19:31 -04:00
|
|
|
|
2024-06-24 18:11:36 -04:00
|
|
|
_logger.Debug($"Linked type {type.AssemblyQualifiedName} to obs websocket handler {handler.GetType().AssemblyQualifiedName}.");
|
2024-03-12 14:05:27 -04:00
|
|
|
Add(handler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|