@@ -99,6 +99,8 @@ namespace Discord.API | |||||
{ | { | ||||
_loginCancelToken?.Dispose(); | _loginCancelToken?.Dispose(); | ||||
_connectCancelToken?.Dispose(); | _connectCancelToken?.Dispose(); | ||||
(_restClient as IDisposable)?.Dispose(); | |||||
(_gatewayClient as IDisposable)?.Dispose(); | |||||
} | } | ||||
_isDisposed = true; | _isDisposed = true; | ||||
} | } | ||||
@@ -1,5 +1,4 @@ | |||||
using Discord.API.Rest; | using Discord.API.Rest; | ||||
using Discord.Extensions; | |||||
using Discord.Logging; | using Discord.Logging; | ||||
using Discord.Net; | using Discord.Net; | ||||
using Discord.Net.Queue; | using Discord.Net.Queue; | ||||
@@ -56,7 +55,7 @@ namespace Discord | |||||
if (bucket == null && id != null) | if (bucket == null && id != null) | ||||
await _queueLogger.WarningAsync($"Unknown rate limit bucket \"{id ?? "null"}\"").ConfigureAwait(false); | await _queueLogger.WarningAsync($"Unknown rate limit bucket \"{id ?? "null"}\"").ConfigureAwait(false); | ||||
}; | }; | ||||
ApiClient = new API.DiscordApiClient(config.RestClientProvider, (config as DiscordSocketConfig)?.WebSocketProvider, requestQueue: _requestQueue); | ApiClient = new API.DiscordApiClient(config.RestClientProvider, (config as DiscordSocketConfig)?.WebSocketProvider, requestQueue: _requestQueue); | ||||
ApiClient.SentRequest += async (method, endpoint, millis) => await _restLogger.VerboseAsync($"{method} {endpoint}: {millis} ms").ConfigureAwait(false); | ApiClient.SentRequest += async (method, endpoint, millis) => await _restLogger.VerboseAsync($"{method} {endpoint}: {millis} ms").ConfigureAwait(false); | ||||
} | } | ||||
@@ -256,10 +255,11 @@ namespace Discord | |||||
return models.Select(x => new VoiceRegion(x)).Where(x => x.Id == id).FirstOrDefault(); | return models.Select(x => new VoiceRegion(x)).Where(x => x.Id == id).FirstOrDefault(); | ||||
} | } | ||||
internal void Dispose(bool disposing) | |||||
internal virtual void Dispose(bool disposing) | |||||
{ | { | ||||
if (!_isDisposed) | if (!_isDisposed) | ||||
_isDisposed = true; | _isDisposed = true; | ||||
ApiClient.Dispose(); | |||||
} | } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public void Dispose() => Dispose(true); | public void Dispose() => Dispose(true); | ||||
@@ -47,8 +47,7 @@ namespace Discord | |||||
public ConnectionState ConnectionState { get; private set; } | public ConnectionState ConnectionState { get; private set; } | ||||
/// <summary> Gets the estimated round-trip latency, in milliseconds, to the gateway server. </summary> | /// <summary> Gets the estimated round-trip latency, in milliseconds, to the gateway server. </summary> | ||||
public int Latency { get; private set; } | public int Latency { get; private set; } | ||||
internal IWebSocketClient GatewaySocket { get; private set; } | |||||
internal int MessageCacheSize { get; private set; } | internal int MessageCacheSize { get; private set; } | ||||
internal DataStore DataStore { get; private set; } | internal DataStore DataStore { get; private set; } | ||||
@@ -97,7 +96,6 @@ namespace Discord | |||||
else | else | ||||
await _gatewayLogger.WarningAsync($"Connection Closed").ConfigureAwait(false); | await _gatewayLogger.WarningAsync($"Connection Closed").ConfigureAwait(false); | ||||
}; | }; | ||||
GatewaySocket = config.WebSocketProvider(); | |||||
_voiceRegions = ImmutableDictionary.Create<string, VoiceRegion>(); | _voiceRegions = ImmutableDictionary.Create<string, VoiceRegion>(); | ||||
_largeGuilds = new ConcurrentQueue<ulong>(); | _largeGuilds = new ConcurrentQueue<ulong>(); | ||||
@@ -1,4 +1,5 @@ | |||||
using Discord.API; | using Discord.API; | ||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.IO; | using System.IO; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
@@ -6,7 +7,7 @@ using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
//TODO: Add docstrings | //TODO: Add docstrings | ||||
public interface IDiscordClient | |||||
public interface IDiscordClient : IDisposable | |||||
{ | { | ||||
LoginState LoginState { get; } | LoginState LoginState { get; } | ||||
ConnectionState ConnectionState { get; } | ConnectionState ConnectionState { get; } | ||||