Added support to test against Twitch's mocked websocket & webserver. Fixed some connection problems.

This commit is contained in:
Tom
2024-08-07 19:32:44 +00:00
parent 3d077181fa
commit 87f3623ed6
5 changed files with 40 additions and 15 deletions

View File

@@ -94,18 +94,20 @@ namespace TwitchChatTTS.Twitch.Socket
if (clientDisconnect)
await client.DisconnectAsync(new SocketDisconnectionEventArgs("Closed", "No need for a tertiary client."));
};
client.OnDisconnected += (s, e) =>
client.OnDisconnected += async (s, e) =>
{
bool reconnecting = false;
lock (_lock)
{
if (_identified?.UID == client.UID)
{
_logger.Debug($"Identified Twitch client has disconnected [client: {client.UID}][main: {_identified.UID}][backup: {_backup?.UID}]");
_logger.Warning($"Identified Twitch client has disconnected [client: {client.UID}][main: {_identified.UID}][backup: {_backup?.UID}]");
_identified = null;
reconnecting = true;
}
else if (_backup?.UID == client.UID)
{
_logger.Debug($"Backup Twitch client has disconnected [client: {client.UID}][main: {_identified?.UID}][backup: {_backup.UID}]");
_logger.Warning($"Backup Twitch client has disconnected [client: {client.UID}][main: {_identified?.UID}][backup: {_backup.UID}]");
_backup = null;
}
else if (client.ReceivedReconnecting)
@@ -115,6 +117,12 @@ namespace TwitchChatTTS.Twitch.Socket
else
_logger.Error($"Twitch client disconnected from unknown source [client: {client.UID}][main: {_identified?.UID}][backup: {_backup?.UID}]");
}
if (reconnecting)
{
var client = GetWorkingClient();
await client.Connect();
}
};
_logger.Debug("Created a Twitch websocket client.");