@@ -67,6 +67,11 @@ public class TwitchClientProxy : ITwitchClientProxy {
67
67
/// The callback(s) to invoke when a channel receives a ban message.
68
68
/// </summary>
69
69
private Action < OnUserBannedArgs > ? onUserBanReceived ;
70
+
71
+ /// <summary>
72
+ /// The callback(s) to invoke when a new instance is created.
73
+ /// </summary>
74
+ private static Action < TwitchClientProxy > ? onInstanceCreated ;
70
75
71
76
/// <summary>
72
77
/// The web socket to connect to twitch chat with.
@@ -93,6 +98,7 @@ public static TwitchClientProxy Instance {
93
98
get {
94
99
if ( null == instance ) {
95
100
instance = new TwitchClientProxy ( ) ;
101
+ onInstanceCreated ? . Invoke ( instance ) ;
96
102
}
97
103
98
104
return instance ;
@@ -164,6 +170,17 @@ public async Task AddMessageCallback(string channel, Action<OnMessageReceivedArg
164
170
public void RemoveMessageCallback ( Action < OnMessageReceivedArgs > callback ) {
165
171
onMessageReceived -= callback ;
166
172
}
173
+
174
+ /// <inheritdoc />
175
+ public void AddInstanceCallback ( Action < TwitchClientProxy > callback ) {
176
+ onInstanceCreated -= callback ;
177
+ onInstanceCreated += callback ;
178
+ }
179
+
180
+ /// <inheritdoc />
181
+ public void RemoveInstanceCallback ( Action < TwitchClientProxy > callback ) {
182
+ onInstanceCreated -= callback ;
183
+ }
167
184
168
185
/// <inheritdoc />
169
186
public async Task AddBannedCallback ( string channel , Action < OnUserBannedArgs > callback ) {
@@ -408,8 +425,11 @@ private void TwitchChatClient_OnUserBanned(object? sender, OnUserBannedArgs e) {
408
425
/// <param name="disposing">True if called directly, false if called from the destructor.</param>
409
426
protected virtual void Dispose ( bool disposing ) {
410
427
if ( disposing ) {
428
+ client ? . Disconnect ( ) ;
411
429
twitchChatClientReconnect ? . Dispose ( ) ;
412
430
socket ? . Dispose ( ) ;
413
431
}
432
+
433
+ instance = null ;
414
434
}
415
435
}
0 commit comments