@@ -148,6 +148,9 @@ | |||||
<Compile Include="..\Discord.Net\Collections\Users.cs"> | <Compile Include="..\Discord.Net\Collections\Users.cs"> | ||||
<Link>Collections\Users.cs</Link> | <Link>Collections\Users.cs</Link> | ||||
</Compile> | </Compile> | ||||
<Compile Include="..\Discord.Net\DiscordAPIClient.cs"> | |||||
<Link>DiscordAPIClient.cs</Link> | |||||
</Compile> | |||||
<Compile Include="..\Discord.Net\DiscordClient.API.cs"> | <Compile Include="..\Discord.Net\DiscordClient.API.cs"> | ||||
<Link>DiscordClient.API.cs</Link> | <Link>DiscordClient.API.cs</Link> | ||||
</Compile> | </Compile> | ||||
@@ -163,17 +166,17 @@ | |||||
<Compile Include="..\Discord.Net\DiscordClientConfig.cs"> | <Compile Include="..\Discord.Net\DiscordClientConfig.cs"> | ||||
<Link>DiscordClientConfig.cs</Link> | <Link>DiscordClientConfig.cs</Link> | ||||
</Compile> | </Compile> | ||||
<Compile Include="..\Discord.Net\DiscordSimpleClient.cs"> | |||||
<Link>DiscordSimpleClient.cs</Link> | |||||
<Compile Include="..\Discord.Net\DiscordWebSocketClient.cs"> | |||||
<Link>DiscordWebSocketClient.cs</Link> | |||||
</Compile> | </Compile> | ||||
<Compile Include="..\Discord.Net\DiscordSimpleClient.Events.cs"> | |||||
<Link>DiscordSimpleClient.Events.cs</Link> | |||||
<Compile Include="..\Discord.Net\DiscordWebSocketClient.Events.cs"> | |||||
<Link>DiscordWebSocketClient.Events.cs</Link> | |||||
</Compile> | </Compile> | ||||
<Compile Include="..\Discord.Net\DiscordSimpleClient.Voice.cs"> | |||||
<Link>DiscordSimpleClient.Voice.cs</Link> | |||||
<Compile Include="..\Discord.Net\DiscordWebSocketClient.Voice.cs"> | |||||
<Link>DiscordWebSocketClient.Voice.cs</Link> | |||||
</Compile> | </Compile> | ||||
<Compile Include="..\Discord.Net\DiscordSimpleClientConfig.cs"> | |||||
<Link>DiscordSimpleClientConfig.cs</Link> | |||||
<Compile Include="..\Discord.Net\DiscordWebSocketClientConfig.cs"> | |||||
<Link>DiscordWebSocketClientConfig.cs</Link> | |||||
</Compile> | </Compile> | ||||
<Compile Include="..\Discord.Net\Helpers\EpochTime.cs"> | <Compile Include="..\Discord.Net\Helpers\EpochTime.cs"> | ||||
<Link>Helpers\EpochTime.cs</Link> | <Link>Helpers\EpochTime.cs</Link> | ||||
@@ -244,9 +247,6 @@ | |||||
<Compile Include="..\Discord.Net\Net\DataWebSockets.Events.cs"> | <Compile Include="..\Discord.Net\Net\DataWebSockets.Events.cs"> | ||||
<Link>Net\DataWebSockets.Events.cs</Link> | <Link>Net\DataWebSockets.Events.cs</Link> | ||||
</Compile> | </Compile> | ||||
<Compile Include="..\Discord.Net\Net\DiscordAPIClient.cs"> | |||||
<Link>Net\DiscordAPIClient.cs</Link> | |||||
</Compile> | |||||
<Compile Include="..\Discord.Net\Net\HttpException.cs"> | <Compile Include="..\Discord.Net\Net\HttpException.cs"> | ||||
<Link>Net\HttpException.cs</Link> | <Link>Net\HttpException.cs</Link> | ||||
</Compile> | </Compile> | ||||
@@ -1,11 +1,12 @@ | |||||
using Discord.API; | using Discord.API; | ||||
using Discord.Net; | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Threading; | using System.Threading; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord.Net | |||||
namespace Discord | |||||
{ | { | ||||
/// <summary> A lightweight wrapper around the Discord API. </summary> | /// <summary> A lightweight wrapper around the Discord API. </summary> | ||||
public class DiscordAPIClient | public class DiscordAPIClient |
@@ -12,13 +12,13 @@ using System.Threading.Tasks; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
/// <summary> Provides a connection to the DiscordApp service. </summary> | /// <summary> Provides a connection to the DiscordApp service. </summary> | ||||
public partial class DiscordClient : DiscordSimpleClient | |||||
public partial class DiscordClient : DiscordWebSocketClient | |||||
{ | { | ||||
protected readonly DiscordAPIClient _api; | protected readonly DiscordAPIClient _api; | ||||
private readonly Random _rand; | private readonly Random _rand; | ||||
private readonly JsonSerializer _serializer; | private readonly JsonSerializer _serializer; | ||||
private readonly ConcurrentQueue<Message> _pendingMessages; | private readonly ConcurrentQueue<Message> _pendingMessages; | ||||
private readonly ConcurrentDictionary<string, DiscordSimpleClient> _voiceClients; | |||||
private readonly ConcurrentDictionary<string, DiscordWebSocketClient> _voiceClients; | |||||
private bool _sentInitialLog; | private bool _sentInitialLog; | ||||
private uint _nextVoiceClientId; | private uint _nextVoiceClientId; | ||||
private string _status; | private string _status; | ||||
@@ -59,7 +59,7 @@ namespace Discord | |||||
if (Config.UseMessageQueue) | if (Config.UseMessageQueue) | ||||
_pendingMessages = new ConcurrentQueue<Message>(); | _pendingMessages = new ConcurrentQueue<Message>(); | ||||
if (Config.EnableVoiceMultiserver) | if (Config.EnableVoiceMultiserver) | ||||
_voiceClients = new ConcurrentDictionary<string, DiscordSimpleClient>(); | |||||
_voiceClients = new ConcurrentDictionary<string, DiscordWebSocketClient>(); | |||||
object cacheLock = new object(); | object cacheLock = new object(); | ||||
_channels = new Channels(this, cacheLock); | _channels = new Channels(this, cacheLock); | ||||
@@ -747,7 +747,7 @@ namespace Discord | |||||
return null; | return null; | ||||
} | } | ||||
DiscordSimpleClient client; | |||||
DiscordWebSocketClient client; | |||||
if (_voiceClients.TryGetValue(serverId, out client)) | if (_voiceClients.TryGetValue(serverId, out client)) | ||||
return client; | return client; | ||||
else | else | ||||
@@ -768,7 +768,7 @@ namespace Discord | |||||
config.EnableVoiceMultiserver = false; | config.EnableVoiceMultiserver = false; | ||||
config.VoiceOnly = true; | config.VoiceOnly = true; | ||||
config.VoiceClientId = unchecked(++_nextVoiceClientId); | config.VoiceClientId = unchecked(++_nextVoiceClientId); | ||||
return new DiscordSimpleClient(config, serverId); | |||||
return new DiscordWebSocketClient(config, serverId); | |||||
}); | }); | ||||
client.LogMessage += (s, e) => RaiseOnLog(e.Severity, e.Source, $"(#{client.Config.VoiceClientId}) {e.Message}"); | client.LogMessage += (s, e) => RaiseOnLog(e.Severity, e.Source, $"(#{client.Config.VoiceClientId}) {e.Message}"); | ||||
await client.Connect(_gateway, _token).ConfigureAwait(false); | await client.Connect(_gateway, _token).ConfigureAwait(false); | ||||
@@ -799,7 +799,7 @@ namespace Discord | |||||
if (Config.EnableVoiceMultiserver) | if (Config.EnableVoiceMultiserver) | ||||
{ | { | ||||
DiscordSimpleClient client; | |||||
DiscordWebSocketClient client; | |||||
if (_voiceClients.TryRemove(serverId, out client)) | if (_voiceClients.TryRemove(serverId, out client)) | ||||
await client.Disconnect(); | await client.Disconnect(); | ||||
} | } | ||||
@@ -1,6 +1,6 @@ | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
public class DiscordClientConfig : DiscordSimpleClientConfig | |||||
public class DiscordClientConfig : DiscordWebSocketClientConfig | |||||
{ | { | ||||
/// <summary> Gets or sets the time (in milliseconds) to wait when the message queue is empty before checking again. </summary> | /// <summary> Gets or sets the time (in milliseconds) to wait when the message queue is empty before checking again. </summary> | ||||
public int MessageQueueInterval { get { return _messageQueueInterval; } set { SetValue(ref _messageQueueInterval, value); } } | public int MessageQueueInterval { get { return _messageQueueInterval; } set { SetValue(ref _messageQueueInterval, value); } } | ||||
@@ -73,7 +73,7 @@ namespace Discord | |||||
} | } | ||||
} | } | ||||
public partial class DiscordSimpleClient | |||||
public partial class DiscordWebSocketClient | |||||
{ | { | ||||
public event EventHandler Connected; | public event EventHandler Connected; | ||||
private void RaiseConnected() | private void RaiseConnected() |
@@ -23,7 +23,7 @@ namespace Discord | |||||
Task WaitVoice(); | Task WaitVoice(); | ||||
} | } | ||||
public partial class DiscordSimpleClient : IDiscordVoiceClient | |||||
public partial class DiscordWebSocketClient : IDiscordVoiceClient | |||||
{ | { | ||||
IDiscordVoiceBuffer IDiscordVoiceClient.OutputBuffer => _voiceSocket.OutputBuffer; | IDiscordVoiceBuffer IDiscordVoiceClient.OutputBuffer => _voiceSocket.OutputBuffer; | ||||
@@ -17,7 +17,7 @@ namespace Discord | |||||
} | } | ||||
/// <summary> Provides a barebones connection to the Discord service </summary> | /// <summary> Provides a barebones connection to the Discord service </summary> | ||||
public partial class DiscordSimpleClient | |||||
public partial class DiscordWebSocketClient | |||||
{ | { | ||||
internal readonly DataWebSocket _dataSocket; | internal readonly DataWebSocket _dataSocket; | ||||
internal readonly VoiceWebSocket _voiceSocket; | internal readonly VoiceWebSocket _voiceSocket; | ||||
@@ -32,8 +32,8 @@ namespace Discord | |||||
private bool _wasDisconnectUnexpected; | private bool _wasDisconnectUnexpected; | ||||
/// <summary> Returns the configuration object used to make this client. Note that this object cannot be edited directly - to change the configuration of this client, use the DiscordClient(DiscordClientConfig config) constructor. </summary> | /// <summary> Returns the configuration object used to make this client. Note that this object cannot be edited directly - to change the configuration of this client, use the DiscordClient(DiscordClientConfig config) constructor. </summary> | ||||
public DiscordSimpleClientConfig Config => _config; | |||||
protected readonly DiscordSimpleClientConfig _config; | |||||
public DiscordWebSocketClientConfig Config => _config; | |||||
protected readonly DiscordWebSocketClientConfig _config; | |||||
/// <summary> Returns the id of the current logged-in user. </summary> | /// <summary> Returns the id of the current logged-in user. </summary> | ||||
public string CurrentUserId => _currentUserId; | public string CurrentUserId => _currentUserId; | ||||
@@ -50,9 +50,9 @@ namespace Discord | |||||
private CancellationToken _cancelToken; | private CancellationToken _cancelToken; | ||||
/// <summary> Initializes a new instance of the DiscordClient class. </summary> | /// <summary> Initializes a new instance of the DiscordClient class. </summary> | ||||
public DiscordSimpleClient(DiscordSimpleClientConfig config = null) | |||||
public DiscordWebSocketClient(DiscordWebSocketClientConfig config = null) | |||||
{ | { | ||||
_config = config ?? new DiscordSimpleClientConfig(); | |||||
_config = config ?? new DiscordWebSocketClientConfig(); | |||||
_config.Lock(); | _config.Lock(); | ||||
_enableVoice = _config.EnableVoice; | _enableVoice = _config.EnableVoice; | ||||
@@ -66,7 +66,7 @@ namespace Discord | |||||
if (_enableVoice) | if (_enableVoice) | ||||
_voiceSocket = CreateVoiceSocket(); | _voiceSocket = CreateVoiceSocket(); | ||||
} | } | ||||
internal DiscordSimpleClient(DiscordSimpleClientConfig config = null, string voiceServerId = null) | |||||
internal DiscordWebSocketClient(DiscordWebSocketClientConfig config = null, string voiceServerId = null) | |||||
: this(config) | : this(config) | ||||
{ | { | ||||
_voiceServerId = voiceServerId; | _voiceServerId = voiceServerId; |
@@ -12,7 +12,7 @@ namespace Discord | |||||
Both = Outgoing | Incoming | Both = Outgoing | Incoming | ||||
} | } | ||||
public class DiscordSimpleClientConfig | |||||
public class DiscordWebSocketClientConfig | |||||
{ | { | ||||
/// <summary> Specifies the minimum log level severity that will be sent to the LogMessage event. Warning: setting this to debug will really hurt performance but should help investigate any internal issues. </summary> | /// <summary> Specifies the minimum log level severity that will be sent to the LogMessage event. Warning: setting this to debug will really hurt performance but should help investigate any internal issues. </summary> | ||||
public LogMessageSeverity LogLevel { get { return _logLevel; } set { SetValue(ref _logLevel, value); } } | public LogMessageSeverity LogLevel { get { return _logLevel; } set { SetValue(ref _logLevel, value); } } |
@@ -13,7 +13,7 @@ namespace Discord.Net | |||||
public string SessionId => _sessionId; | public string SessionId => _sessionId; | ||||
private string _sessionId; | private string _sessionId; | ||||
public DataWebSocket(DiscordSimpleClient client) | |||||
public DataWebSocket(DiscordWebSocketClient client) | |||||
: base(client) | : base(client) | ||||
{ | { | ||||
} | } | ||||
@@ -45,7 +45,7 @@ namespace Discord.Net | |||||
public string CurrentChannelId => _channelId; | public string CurrentChannelId => _channelId; | ||||
public VoiceBuffer OutputBuffer => _sendBuffer; | public VoiceBuffer OutputBuffer => _sendBuffer; | ||||
public VoiceWebSocket(DiscordSimpleClient client) | |||||
public VoiceWebSocket(DiscordWebSocketClient client) | |||||
: base(client) | : base(client) | ||||
{ | { | ||||
_rand = new Random(); | _rand = new Random(); | ||||
@@ -34,7 +34,7 @@ namespace Discord.Net | |||||
internal abstract partial class WebSocket | internal abstract partial class WebSocket | ||||
{ | { | ||||
protected readonly IWebSocketEngine _engine; | protected readonly IWebSocketEngine _engine; | ||||
protected readonly DiscordSimpleClient _client; | |||||
protected readonly DiscordWebSocketClient _client; | |||||
protected readonly LogMessageSeverity _logLevel; | protected readonly LogMessageSeverity _logLevel; | ||||
protected readonly ManualResetEventSlim _connectedEvent; | protected readonly ManualResetEventSlim _connectedEvent; | ||||
@@ -56,7 +56,7 @@ namespace Discord.Net | |||||
public WebSocketState State => (WebSocketState)_state; | public WebSocketState State => (WebSocketState)_state; | ||||
protected int _state; | protected int _state; | ||||
public WebSocket(DiscordSimpleClient client) | |||||
public WebSocket(DiscordWebSocketClient client) | |||||
{ | { | ||||
_client = client; | _client = client; | ||||
_logLevel = client.Config.LogLevel; | _logLevel = client.Config.LogLevel; | ||||