Added missing websocket support for Redemptions and Actions. Fixed Ad Break actions. Cleaned some code.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System.Net.WebSockets;
|
||||
using System.Text.Json;
|
||||
using System.Timers;
|
||||
using CommonSocketLibrary.Abstract;
|
||||
@@ -9,6 +8,7 @@ using HermesSocketLibrary.Requests.Messages;
|
||||
using HermesSocketLibrary.Socket.Data;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Serilog;
|
||||
using TwitchChatTTS.Bus;
|
||||
using TwitchChatTTS.Hermes.Socket.Handlers;
|
||||
|
||||
namespace TwitchChatTTS.Hermes.Socket
|
||||
@@ -19,6 +19,7 @@ namespace TwitchChatTTS.Hermes.Socket
|
||||
|
||||
private readonly User _user;
|
||||
private readonly Configuration _configuration;
|
||||
private readonly ServiceBusCentral _bus;
|
||||
private readonly ICallbackManager<HermesRequestData> _callbackManager;
|
||||
private string URL;
|
||||
|
||||
@@ -33,10 +34,13 @@ namespace TwitchChatTTS.Hermes.Socket
|
||||
public bool LoggedIn { get; set; }
|
||||
public bool Ready { get; set; }
|
||||
|
||||
private bool _attempting;
|
||||
|
||||
|
||||
public HermesSocketClient(
|
||||
User user,
|
||||
Configuration configuration,
|
||||
ServiceBusCentral bus,
|
||||
ICallbackManager<HermesRequestData> callbackManager,
|
||||
[FromKeyedServices("hermes")] IBackoff backoff,
|
||||
[FromKeyedServices("hermes")] IEnumerable<IWebSocketHandler> handlers,
|
||||
@@ -50,6 +54,7 @@ namespace TwitchChatTTS.Hermes.Socket
|
||||
{
|
||||
_user = user;
|
||||
_configuration = configuration;
|
||||
_bus = bus;
|
||||
_callbackManager = callbackManager;
|
||||
_backoff = backoff;
|
||||
_heartbeatTimer = new System.Timers.Timer(TimeSpan.FromSeconds(15));
|
||||
@@ -59,6 +64,20 @@ namespace TwitchChatTTS.Hermes.Socket
|
||||
URL = $"wss://{BASE_URL}";
|
||||
|
||||
_lock = new object();
|
||||
|
||||
var ttsCreateUserVoice = _bus.GetTopic("tts.user.voice.create");
|
||||
ttsCreateUserVoice.Subscribe(new ServiceBusObserver(async data => await Send(3, new RequestMessage()
|
||||
{
|
||||
Type = "create_tts_user",
|
||||
Data = (IDictionary<string, object>) data.Value!
|
||||
}), logger));
|
||||
|
||||
var ttsUpdateUserVoice = _bus.GetTopic("tts.user.voice.update");
|
||||
ttsUpdateUserVoice.Subscribe(new ServiceBusObserver(async data => await Send(3, new RequestMessage()
|
||||
{
|
||||
Type = "update_tts_user",
|
||||
Data = (IDictionary<string, object>) data.Value!
|
||||
}), logger));
|
||||
}
|
||||
|
||||
|
||||
@@ -66,23 +85,29 @@ namespace TwitchChatTTS.Hermes.Socket
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (Connected)
|
||||
if (Connected || _attempting)
|
||||
return;
|
||||
|
||||
_attempting = true;
|
||||
}
|
||||
|
||||
_logger.Debug($"Attempting to connect to {URL}");
|
||||
await ConnectAsync(URL);
|
||||
_attempting = false;
|
||||
}
|
||||
|
||||
private async Task Disconnect()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (!Connected)
|
||||
if (!Connected || _attempting)
|
||||
return;
|
||||
|
||||
_attempting = true;
|
||||
}
|
||||
|
||||
await DisconnectAsync(new SocketDisconnectionEventArgs("Normal disconnection", "Disconnection was executed"));
|
||||
_attempting = false;
|
||||
}
|
||||
|
||||
public async Task CreateTTSVoice(string voiceName)
|
||||
|
||||
Reference in New Issue
Block a user