[apibrk] change: Specify WebSocket close code (#1500)

* API breaking change: Specify WebSocket close code

Should fix #1479 and help overall with resuming sessions.

* Also try to resume on missed heartbeats
This commit is contained in:
Monica S
2020-04-25 12:12:57 +01:00
committed by GitHub
parent 6d8e216545
commit ed869bd78b
7 changed files with 48 additions and 31 deletions

View File

@@ -40,7 +40,7 @@ namespace Discord.Net.Providers.WS4Net
{
if (disposing)
{
DisconnectInternalAsync(true).GetAwaiter().GetResult();
DisconnectInternalAsync(isDisposing: true).GetAwaiter().GetResult();
_lock?.Dispose();
_cancelTokenSource?.Dispose();
}
@@ -92,19 +92,19 @@ namespace Discord.Net.Providers.WS4Net
_waitUntilConnect.Wait(_cancelToken);
}
public async Task DisconnectAsync()
public async Task DisconnectAsync(int closeCode = 1000)
{
await _lock.WaitAsync().ConfigureAwait(false);
try
{
await DisconnectInternalAsync().ConfigureAwait(false);
await DisconnectInternalAsync(closeCode: closeCode).ConfigureAwait(false);
}
finally
{
_lock.Release();
}
}
private Task DisconnectInternalAsync(bool isDisposing = false)
private Task DisconnectInternalAsync(int closeCode = 1000, bool isDisposing = false)
{
_disconnectCancelTokenSource.Cancel();
if (_client == null)
@@ -112,7 +112,7 @@ namespace Discord.Net.Providers.WS4Net
if (_client.State == WebSocketState.Open)
{
try { _client.Close(1000, ""); }
try { _client.Close(closeCode, ""); }
catch { }
}