Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Nullinside.Api.Common/Twitch/ITwitchClientProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,18 @@ public interface ITwitchClientProxy : IDisposable, IAsyncDisposable {
/// <param name="callback">The callback to remove.</param>
/// <returns>An asynchronous task.</returns>
void RemoveRaidCallback(string channel, Action<OnRaidNotificationArgs> callback);

/// <summary>
/// Adds a callback for being disconnected from the twitch chat server.
/// </summary>
/// <param name="callback">The callback to invoke.</param>
/// <returns>An asynchronous task.</returns>
void AddDisconnectedCallback(Action callback);

/// <summary>
/// Removes a callback for being disconnected from the twitch chat server.
/// </summary>
/// <param name="callback">The callback to remove.</param>
/// <returns>An asynchronous task.</returns>
void RemoveDisconnectedCallback(Action callback);
}
26 changes: 20 additions & 6 deletions src/Nullinside.Api.Common/Twitch/TwitchClientProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public class TwitchClientProxy : ITwitchClientProxy {
/// The callback(s) to invoke when a channel receives a ban message.
/// </summary>
private readonly Dictionary<string, Action<OnUserBannedArgs>?> _onUserBanReceived = new();

/// <summary>
/// The callback(s) to invoke when the twitch chat client is disconnected from twitch chat.
/// </summary>
private Action? _onDisconnected;

/// <summary>
/// A timer used to re-connect the Twitch chat client.
Expand All @@ -73,6 +78,9 @@ public class TwitchClientProxy : ITwitchClientProxy {
/// </summary>
private WebSocketClient? _socket;

/// <summary>
/// The twitch OAuth token to use to connect.
/// </summary>
private string? _twitchOAuthToken;

/// <summary>
Expand Down Expand Up @@ -227,6 +235,17 @@ public void RemoveBannedCallback(string channel, Action<OnUserBannedArgs> callba
_onUserBanReceived.Remove(channel);
}
}

/// <inheritdoc />
public void AddDisconnectedCallback(Action callback) {
_onDisconnected -= callback;
_onDisconnected += callback;
}

/// <inheritdoc />
public void RemoveDisconnectedCallback(Action callback) {
_onDisconnected -= callback;
}

/// <inheritdoc />
public async Task AddRaidCallback(string channel, Action<OnRaidNotificationArgs> callback) {
Expand Down Expand Up @@ -356,12 +375,7 @@ private Task<bool> Connect() {
_client.OnRaidNotification += TwitchChatClient_OnRaidNotification;
_client.OnDisconnected += (sender, args) => {
LOG.Error("Twitch Client Disconnected");
try {
_client.Reconnect();
}
catch (Exception ex) {
LOG.Error("Twitch Client Reconnect Error", ex);
}
_onDisconnected?.Invoke();
};
_client.OnConnectionError += (sender, args) => {
LOG.Error($"Twitch Client Connection Error: {args.Error.Message}");
Expand Down