Skip to content

Commit e13392b

Browse files
feat: adding ability to observe the creation of observable
1 parent dae64fe commit e13392b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Nullinside.Api.Common/Twitch/TwitchClientProxy.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public class TwitchClientProxy : ITwitchClientProxy {
6767
/// The callback(s) to invoke when a channel receives a ban message.
6868
/// </summary>
6969
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;
7075

7176
/// <summary>
7277
/// The web socket to connect to twitch chat with.
@@ -93,6 +98,7 @@ public static TwitchClientProxy Instance {
9398
get {
9499
if (null == instance) {
95100
instance = new TwitchClientProxy();
101+
onInstanceCreated?.Invoke(instance);
96102
}
97103

98104
return instance;
@@ -164,6 +170,17 @@ public async Task AddMessageCallback(string channel, Action<OnMessageReceivedArg
164170
public void RemoveMessageCallback(Action<OnMessageReceivedArgs> callback) {
165171
onMessageReceived -= callback;
166172
}
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+
}
167184

168185
/// <inheritdoc />
169186
public async Task AddBannedCallback(string channel, Action<OnUserBannedArgs> callback) {
@@ -408,8 +425,11 @@ private void TwitchChatClient_OnUserBanned(object? sender, OnUserBannedArgs e) {
408425
/// <param name="disposing">True if called directly, false if called from the destructor.</param>
409426
protected virtual void Dispose(bool disposing) {
410427
if (disposing) {
428+
client?.Disconnect();
411429
twitchChatClientReconnect?.Dispose();
412430
socket?.Dispose();
413431
}
432+
433+
instance = null;
414434
}
415435
}

0 commit comments

Comments
 (0)