mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Hopeful fix for invalid operation exception when reconnecting to Howl and Discord
This commit is contained in:
@@ -161,7 +161,16 @@ public class DiscordService
|
||||
"\"since\":0,\"activities\":[],\"afk\":false},\"compress\":false,\"client_state\":{\"guild_versions\":{}}}}";
|
||||
_logger.Debug(initPayload);
|
||||
_wsClient.SendInstant(initPayload).Wait(_cancellationToken);
|
||||
_heartbeatTask?.Dispose();
|
||||
if (_heartbeatTask != null)
|
||||
{
|
||||
_pingCts.Cancel();
|
||||
while (!_heartbeatTask.IsCompleted)
|
||||
{
|
||||
_logger.Debug("Waiting for heartbeat task to die");
|
||||
Task.Delay(TimeSpan.FromMilliseconds(100), _cancellationToken).Wait(_cancellationToken);
|
||||
}
|
||||
_heartbeatTask.Dispose();
|
||||
}
|
||||
_heartbeatInterval =
|
||||
TimeSpan.FromMilliseconds(packet.Data.GetProperty("heartbeat_interval").GetInt32());
|
||||
_heartbeatTask = Task.Run(HeartbeatTimer, _cancellationToken);
|
||||
|
||||
@@ -143,7 +143,17 @@ public class Howlgg
|
||||
// Received on initial connection
|
||||
var packetData = JsonSerializer.Deserialize<JsonElement>(message.Text.TrimStart('0'));
|
||||
_heartbeatInterval = TimeSpan.FromMilliseconds(packetData.GetProperty("pingInterval").GetInt32());
|
||||
_heartbeatTask?.Dispose();
|
||||
if (_heartbeatTask != null)
|
||||
{
|
||||
_pingCts.Cancel();
|
||||
while (!_heartbeatTask.IsCompleted)
|
||||
{
|
||||
_logger.Debug("Waiting for heartbeat task to die");
|
||||
Task.Delay(TimeSpan.FromMilliseconds(100), _cancellationToken).Wait(_cancellationToken);
|
||||
}
|
||||
_heartbeatTask.Dispose();
|
||||
}
|
||||
|
||||
_heartbeatTask = Task.Run(HeartbeatTimer, _cancellationToken);
|
||||
_logger.Info("Received connection packet from Howl.gg. Setting up heartbeat timer");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user