Changed various locking mechanisms.
This commit is contained in:
@@ -17,15 +17,11 @@ namespace TwitchChatTTS.Twitch.Socket
|
||||
private readonly IDictionary<string, string> _subscriptions;
|
||||
private readonly IBackoff _backoff;
|
||||
private readonly Configuration _configuration;
|
||||
private bool _disconnected;
|
||||
private readonly object _lock;
|
||||
|
||||
public event EventHandler<EventArgs>? OnIdentified;
|
||||
|
||||
public string UID { get; }
|
||||
public string URL;
|
||||
public bool Connected { get; private set; }
|
||||
public bool Identified { get; private set; }
|
||||
public string? SessionId { get; private set; }
|
||||
public bool ReceivedReconnecting { get; set; }
|
||||
public bool TwitchReconnected { get; set; }
|
||||
@@ -46,13 +42,14 @@ namespace TwitchChatTTS.Twitch.Socket
|
||||
_backoff = backoff;
|
||||
_configuration = configuration;
|
||||
_subscriptions = new Dictionary<string, string>();
|
||||
_lock = new object();
|
||||
|
||||
_messageTypes = new Dictionary<string, Type>();
|
||||
_messageTypes.Add("session_keepalive", typeof(object));
|
||||
_messageTypes.Add("session_welcome", typeof(SessionWelcomeMessage));
|
||||
_messageTypes.Add("session_reconnect", typeof(SessionWelcomeMessage));
|
||||
_messageTypes.Add("notification", typeof(NotificationMessage));
|
||||
_messageTypes = new Dictionary<string, Type>
|
||||
{
|
||||
{ "session_keepalive", typeof(object) },
|
||||
{ "session_welcome", typeof(SessionWelcomeMessage) },
|
||||
{ "session_reconnect", typeof(SessionWelcomeMessage) },
|
||||
{ "notification", typeof(NotificationMessage) }
|
||||
};
|
||||
|
||||
UID = Guid.NewGuid().ToString("D");
|
||||
|
||||
@@ -88,25 +85,12 @@ namespace TwitchChatTTS.Twitch.Socket
|
||||
_logger.Information($"Initializing Twitch websocket client.");
|
||||
OnConnected += (sender, e) =>
|
||||
{
|
||||
Connected = true;
|
||||
_logger.Information("Twitch websocket client connected.");
|
||||
_disconnected = false;
|
||||
};
|
||||
|
||||
OnDisconnected += (sender, e) =>
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_disconnected)
|
||||
return;
|
||||
|
||||
_disconnected = true;
|
||||
}
|
||||
|
||||
_logger.Information($"Twitch websocket client disconnected [status: {e.Status}][reason: {e.Reason}][client: {UID}]");
|
||||
|
||||
Connected = false;
|
||||
Identified = false;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -126,7 +110,6 @@ namespace TwitchChatTTS.Twitch.Socket
|
||||
|
||||
public void Identify(string sessionId)
|
||||
{
|
||||
Identified = true;
|
||||
SessionId = sessionId;
|
||||
OnIdentified?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user