Browse Source

Started adding multiserver voice support

pull/22/merge
RogueException 9 years ago
parent
commit
3b9729cb4d
7 changed files with 125 additions and 98 deletions
  1. +25
    -18
      src/Discord.Net.Audio/AudioClient.cs
  2. +51
    -31
      src/Discord.Net.Audio/AudioService.cs
  3. +2
    -2
      src/Discord.Net.Audio/Net/VoiceWebSocket.cs
  4. +6
    -5
      src/Discord.Net.Audio/SimpleAudioClient.cs
  5. +37
    -36
      src/Discord.Net/DiscordClient.cs
  6. +2
    -2
      src/Discord.Net/Net/WebSockets/GatewaySocket.cs
  7. +2
    -4
      src/Discord.Net/Net/WebSockets/WebSocket.cs

+ 25
- 18
src/Discord.Net.Audio/AudioClient.cs View File

@@ -59,24 +59,17 @@ namespace Discord.Audio
public AudioClient(AudioService service, int clientId, Server server, GatewaySocket gatewaySocket, Logger logger) public AudioClient(AudioService service, int clientId, Server server, GatewaySocket gatewaySocket, Logger logger)
{ {
Service = service; Service = service;
_serializer = service.Client.Serializer;
Id = clientId; Id = clientId;
GatewaySocket = gatewaySocket; GatewaySocket = gatewaySocket;
Logger = logger; Logger = logger;
OutputStream = new OutStream(this); OutputStream = new OutStream(this);


_connectionLock = new AsyncLock();
_serializer = new JsonSerializer();
_serializer.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
_serializer.Error += (s, e) =>
{
e.ErrorContext.Handled = true;
Logger.Error("Serialization Failed", e.ErrorContext.Error);
};
_connectionLock = new AsyncLock();


GatewaySocket.ReceivedDispatch += OnReceivedDispatch; GatewaySocket.ReceivedDispatch += OnReceivedDispatch;


VoiceSocket = new VoiceWebSocket(service.Client, this, _serializer, logger);
VoiceSocket = new VoiceWebSocket(service.Client, this, logger);
VoiceSocket.Server = server; VoiceSocket.Server = server;


/*_voiceSocket.Connected += (s, e) => RaiseVoiceConnected(); /*_voiceSocket.Connected += (s, e) => RaiseVoiceConnected();
@@ -124,27 +117,41 @@ namespace Discord.Audio
if (channel == VoiceSocket.Channel) return; if (channel == VoiceSocket.Channel) return;
if (VoiceSocket.Server == null) if (VoiceSocket.Server == null)
throw new InvalidOperationException("This client has been closed."); throw new InvalidOperationException("This client has been closed.");
using (await _connectionLock.LockAsync())
using (await _connectionLock.LockAsync().ConfigureAwait(false))
{ {
_cancelTokenSource = new CancellationTokenSource();
var cancelToken = _cancelTokenSource.Token;
VoiceSocket.ParentCancelToken = cancelToken;
VoiceSocket.Channel = channel; VoiceSocket.Channel = channel;


await Task.Run(() => await Task.Run(() =>
{ {
SendVoiceUpdate(); SendVoiceUpdate();
VoiceSocket.WaitForConnection(cancelToken);
VoiceSocket.WaitForConnection(_cancelTokenSource.Token);
}); });
} }
} }
public async Task Connect(bool connectGateway)
{
using (await _connectionLock.LockAsync().ConfigureAwait(false))
{
_cancelTokenSource = new CancellationTokenSource();
var cancelToken = _cancelTokenSource.Token;
VoiceSocket.ParentCancelToken = cancelToken;

if (connectGateway)
{
GatewaySocket.ParentCancelToken = cancelToken;
await GatewaySocket.Connect().ConfigureAwait(false);
GatewaySocket.WaitForConnection(cancelToken);
}
}
}

public async Task Disconnect() public async Task Disconnect()
{ {
using (await _connectionLock.LockAsync())
using (await _connectionLock.LockAsync().ConfigureAwait(false))
{ {
Service.RemoveClient(VoiceSocket.Server, this);
await Service.RemoveClient(VoiceSocket.Server, this).ConfigureAwait(false);
VoiceSocket.Channel = null; VoiceSocket.Channel = null;
SendVoiceUpdate(); SendVoiceUpdate();
await VoiceSocket.Disconnect(); await VoiceSocket.Disconnect();


+ 51
- 31
src/Discord.Net.Audio/AudioService.cs View File

@@ -1,4 +1,5 @@
using System;
using Discord.Net.WebSockets;
using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -10,7 +11,7 @@ namespace Discord.Audio
private AudioClient _defaultClient; private AudioClient _defaultClient;
private ConcurrentDictionary<ulong, IAudioClient> _voiceClients; private ConcurrentDictionary<ulong, IAudioClient> _voiceClients;
private ConcurrentDictionary<User, bool> _talkingUsers; private ConcurrentDictionary<User, bool> _talkingUsers;
//private int _nextClientId;
private int _nextClientId;


internal DiscordClient Client { get; private set; } internal DiscordClient Client { get; private set; }
public AudioServiceConfig Config { get; } public AudioServiceConfig Config { get; }
@@ -83,52 +84,71 @@ namespace Discord.Audio
return null; return null;
} }
} }
private Task<IAudioClient> CreateClient(Server server)
private async Task<IAudioClient> CreateClient(Server server)
{ {
throw new NotImplementedException();
/*var client = _voiceClients.GetOrAdd(server.Id, _ =>
{
int id = unchecked(++_nextClientId);
var logger = Client.Log.CreateLogger($"Voice #{id}");
var voiceClient = new DiscordAudioClient(this, id, logger, Client.GatewaySocket);
voiceClient.SetServerId(server.Id);
var client = _voiceClients.GetOrAdd(server.Id, _ => null); //Placeholder, so we can't have two clients connecting at once


voiceClient.VoiceSocket.OnPacket += (s, e) =>
{
RaiseOnPacket(e);
};
voiceClient.VoiceSocket.IsSpeaking += (s, e) =>
{
var user = server.GetUser(e.UserId);
RaiseUserIsSpeakingUpdated(user, e.IsSpeaking);
};

return voiceClient;
});
//await client.Connect(gatewaySocket.Host, _client.Token).ConfigureAwait(false);
return Task.FromResult(client);*/
if (client == null)
{
int id = unchecked(++_nextClientId);

var gatewayLogger = Client.Log.CreateLogger($"Gateway #{id}");
var gatewaySocket = new GatewaySocket(Client, gatewayLogger);
await gatewaySocket.Connect().ConfigureAwait(false);

var voiceLogger = Client.Log.CreateLogger($"Voice #{id}");
var voiceClient = new AudioClient(this, id, server, Client.GatewaySocket, voiceLogger);
await voiceClient.Connect(true).ConfigureAwait(false);

/*voiceClient.VoiceSocket.FrameReceived += (s, e) =>
{
OnFrameReceieved(e);
};
voiceClient.VoiceSocket.UserIsSpeaking += (s, e) =>
{
var user = server.GetUser(e.UserId);
OnUserIsSpeakingUpdated(user, e.IsSpeaking);
};*/

//Update the placeholder only it still exists (RemoveClient wasnt called)
if (!_voiceClients.TryUpdate(server.Id, voiceClient, null))
{
//If it was, cleanup
await voiceClient.Disconnect().ConfigureAwait(false); ;
await gatewaySocket.Disconnect().ConfigureAwait(false); ;
}
}
return client;
} }


//TODO: This isn't threadsafe //TODO: This isn't threadsafe
internal void RemoveClient(Server server, IAudioClient client)
internal async Task RemoveClient(Server server, IAudioClient client)
{ {
if (Config.EnableMultiserver && server != null) if (Config.EnableMultiserver && server != null)
_voiceClients.TryRemove(server.Id, out client);
{
if (_voiceClients.TryRemove(server.Id, out client))
{
await client.Disconnect();
await (client as AudioClient).GatewaySocket.Disconnect();
}
}
} }


public async Task<IAudioClient> Join(Channel channel) public async Task<IAudioClient> Join(Channel channel)
{ {
if (channel == null) throw new ArgumentNullException(nameof(channel)); if (channel == null) throw new ArgumentNullException(nameof(channel));

IAudioClient client;
if (!Config.EnableMultiserver) if (!Config.EnableMultiserver)
client = await (_defaultClient as SimpleAudioClient).Connect(channel).ConfigureAwait(false);
{
await (_defaultClient as SimpleAudioClient).Join(channel).ConfigureAwait(false);
return _defaultClient;
}
else else
{ {
client = await CreateClient(channel.Server).ConfigureAwait(false);
var client = await CreateClient(channel.Server).ConfigureAwait(false);
await client.Join(channel).ConfigureAwait(false); await client.Join(channel).ConfigureAwait(false);
return client;
} }
return client;
} }
public async Task Leave(Server server) public async Task Leave(Server server)


+ 2
- 2
src/Discord.Net.Audio/Net/VoiceWebSocket.cs View File

@@ -57,8 +57,8 @@ namespace Discord.Net.WebSockets
internal void OnFrameReceived(ulong userId, ulong channelId, byte[] buffer, int offset, int count) internal void OnFrameReceived(ulong userId, ulong channelId, byte[] buffer, int offset, int count)
=> FrameReceived(this, new InternalFrameEventArgs(userId, channelId, buffer, offset, count)); => FrameReceived(this, new InternalFrameEventArgs(userId, channelId, buffer, offset, count));


internal VoiceWebSocket(DiscordClient client, AudioClient audioClient, JsonSerializer serializer, Logger logger)
: base(client, serializer, logger)
internal VoiceWebSocket(DiscordClient client, AudioClient audioClient, Logger logger)
: base(client, logger)
{ {
_audioClient = audioClient; _audioClient = audioClient;
_config = client.Audio().Config; _config = client.Audio().Config;


+ 6
- 5
src/Discord.Net.Audio/SimpleAudioClient.cs View File

@@ -42,19 +42,19 @@ namespace Discord.Audio
//Only disconnects if is current a member of this server //Only disconnects if is current a member of this server
public async Task Leave(VirtualClient client) public async Task Leave(VirtualClient client)
{ {
using (await _connectionLock.LockAsync())
using (await _connectionLock.LockAsync().ConfigureAwait(false))
{ {
if (CurrentClient == client) if (CurrentClient == client)
{ {
CurrentClient = null; CurrentClient = null;
await Disconnect();
await Disconnect().ConfigureAwait(false);
} }
} }
} }


internal async Task<IAudioClient> Connect(Channel channel)
internal async Task<IAudioClient> Connect(Channel channel, bool connectGateway)
{ {
using (await _connectionLock.LockAsync())
using (await _connectionLock.LockAsync().ConfigureAwait(false))
{ {
bool changeServer = channel.Server != VoiceSocket.Server; bool changeServer = channel.Server != VoiceSocket.Server;
if (changeServer || CurrentClient == null) if (changeServer || CurrentClient == null)
@@ -62,8 +62,9 @@ namespace Discord.Audio
await Disconnect().ConfigureAwait(false); await Disconnect().ConfigureAwait(false);
CurrentClient = new VirtualClient(this); CurrentClient = new VirtualClient(this);
VoiceSocket.Server = channel.Server; VoiceSocket.Server = channel.Server;
await Connect(connectGateway).ConfigureAwait(false);
} }
await Join(channel);
await Join(channel).ConfigureAwait(false);
return CurrentClient; return CurrentClient;
} }
} }


+ 37
- 36
src/Discord.Net/DiscordClient.cs View File

@@ -30,10 +30,11 @@ namespace Discord
private readonly ConcurrentDictionary<ulong, Server> _servers; private readonly ConcurrentDictionary<ulong, Server> _servers;
private readonly ConcurrentDictionary<ulong, Channel> _channels; private readonly ConcurrentDictionary<ulong, Channel> _channels;
private readonly ConcurrentDictionary<ulong, Channel> _privateChannels; //Key = RecipientId private readonly ConcurrentDictionary<ulong, Channel> _privateChannels; //Key = RecipientId
private readonly JsonSerializer _serializer;
private Dictionary<string, Region> _regions; private Dictionary<string, Region> _regions;
private CancellationTokenSource _cancelTokenSource; private CancellationTokenSource _cancelTokenSource;


internal Logger Logger { get; }

/// <summary> Gets the configuration object used to make this client. </summary> /// <summary> Gets the configuration object used to make this client. </summary>
public DiscordConfig Config { get; } public DiscordConfig Config { get; }
/// <summary> Gets the log manager. </summary> /// <summary> Gets the log manager. </summary>
@@ -48,8 +49,8 @@ namespace Discord
public ServiceManager Services { get; } public ServiceManager Services { get; }
/// <summary> Gets the queue used for outgoing messages, if enabled. </summary> /// <summary> Gets the queue used for outgoing messages, if enabled. </summary>
public MessageQueue MessageQueue { get; } public MessageQueue MessageQueue { get; }
/// <summary> Gets the logger used for this client. </summary>
internal Logger Logger { get; }
/// <summary> Gets the JSON serializer used by this client. </summary>
public JsonSerializer Serializer { get; }


/// <summary> Gets the current connection state of this client. </summary> /// <summary> Gets the current connection state of this client. </summary>
public ConnectionState State { get; private set; } public ConnectionState State { get; private set; }
@@ -101,16 +102,16 @@ namespace Discord
_privateChannels = new ConcurrentDictionary<ulong, Channel>(); _privateChannels = new ConcurrentDictionary<ulong, Channel>();


//Serialization //Serialization
_serializer = new JsonSerializer();
_serializer.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
Serializer = new JsonSerializer();
Serializer.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
#if TEST_RESPONSES #if TEST_RESPONSES
_serializer.CheckAdditionalContent = true;
_serializer.MissingMemberHandling = MissingMemberHandling.Error;
Serializer.CheckAdditionalContent = true;
Serializer.MissingMemberHandling = MissingMemberHandling.Error;
#else #else
_serializer.CheckAdditionalContent = false;
_serializer.MissingMemberHandling = MissingMemberHandling.Ignore;
Serializer.CheckAdditionalContent = false;
Serializer.MissingMemberHandling = MissingMemberHandling.Ignore;
#endif #endif
_serializer.Error += (s, e) =>
Serializer.Error += (s, e) =>
{ {
e.ErrorContext.Handled = true; e.ErrorContext.Handled = true;
Logger.Error("Serialization Failed", e.ErrorContext.Error); Logger.Error("Serialization Failed", e.ErrorContext.Error);
@@ -119,7 +120,7 @@ namespace Discord
//Networking //Networking
ClientAPI = new RestClient(Config, DiscordConfig.ClientAPIUrl, Log.CreateLogger("ClientAPI")); ClientAPI = new RestClient(Config, DiscordConfig.ClientAPIUrl, Log.CreateLogger("ClientAPI"));
StatusAPI = new RestClient(Config, DiscordConfig.StatusAPIUrl, Log.CreateLogger("StatusAPI")); StatusAPI = new RestClient(Config, DiscordConfig.StatusAPIUrl, Log.CreateLogger("StatusAPI"));
GatewaySocket = new GatewaySocket(this, _serializer, Log.CreateLogger("Gateway"));
GatewaySocket = new GatewaySocket(this, Log.CreateLogger("Gateway"));
GatewaySocket.Connected += (s, e) => GatewaySocket.Connected += (s, e) =>
{ {
if (State == ConnectionState.Connecting) if (State == ConnectionState.Connecting)
@@ -486,7 +487,7 @@ namespace Discord
Stopwatch stopwatch = null; Stopwatch stopwatch = null;
if (Config.LogLevel >= LogSeverity.Verbose) if (Config.LogLevel >= LogSeverity.Verbose)
stopwatch = Stopwatch.StartNew(); stopwatch = Stopwatch.StartNew();
var data = e.Payload.ToObject<ReadyEvent>(_serializer);
var data = e.Payload.ToObject<ReadyEvent>(Serializer);
GatewaySocket.StartHeartbeat(data.HeartbeatInterval); GatewaySocket.StartHeartbeat(data.HeartbeatInterval);
GatewaySocket.SessionId = data.SessionId; GatewaySocket.SessionId = data.SessionId;
SessionId = data.SessionId; SessionId = data.SessionId;
@@ -517,7 +518,7 @@ namespace Discord
break; break;
case "RESUMED": case "RESUMED":
{ {
var data = e.Payload.ToObject<ResumedEvent>(_serializer);
var data = e.Payload.ToObject<ResumedEvent>(Serializer);
GatewaySocket.StartHeartbeat(data.HeartbeatInterval); GatewaySocket.StartHeartbeat(data.HeartbeatInterval);
} }
break; break;
@@ -525,7 +526,7 @@ namespace Discord
//Servers //Servers
case "GUILD_CREATE": case "GUILD_CREATE":
{ {
var data = e.Payload.ToObject<GuildCreateEvent>(_serializer);
var data = e.Payload.ToObject<GuildCreateEvent>(Serializer);
if (data.Unavailable != true) if (data.Unavailable != true)
{ {
var server = AddServer(data.Id); var server = AddServer(data.Id);
@@ -547,7 +548,7 @@ namespace Discord
break; break;
case "GUILD_UPDATE": case "GUILD_UPDATE":
{ {
var data = e.Payload.ToObject<GuildUpdateEvent>(_serializer);
var data = e.Payload.ToObject<GuildUpdateEvent>(Serializer);
var server = GetServer(data.Id); var server = GetServer(data.Id);
if (server != null) if (server != null)
{ {
@@ -562,7 +563,7 @@ namespace Discord
break; break;
case "GUILD_DELETE": case "GUILD_DELETE":
{ {
var data = e.Payload.ToObject<GuildDeleteEvent>(_serializer);
var data = e.Payload.ToObject<GuildDeleteEvent>(Serializer);
Server server = RemoveServer(data.Id); Server server = RemoveServer(data.Id);
if (server != null) if (server != null)
{ {
@@ -586,7 +587,7 @@ namespace Discord
//Channels //Channels
case "CHANNEL_CREATE": case "CHANNEL_CREATE":
{ {
var data = e.Payload.ToObject<ChannelCreateEvent>(_serializer);
var data = e.Payload.ToObject<ChannelCreateEvent>(Serializer);


Channel channel = null; Channel channel = null;
if (data.GuildId != null) if (data.GuildId != null)
@@ -610,7 +611,7 @@ namespace Discord
break; break;
case "CHANNEL_UPDATE": case "CHANNEL_UPDATE":
{ {
var data = e.Payload.ToObject<ChannelUpdateEvent>(_serializer);
var data = e.Payload.ToObject<ChannelUpdateEvent>(Serializer);
var channel = GetChannel(data.Id); var channel = GetChannel(data.Id);
if (channel != null) if (channel != null)
{ {
@@ -625,7 +626,7 @@ namespace Discord
break; break;
case "CHANNEL_DELETE": case "CHANNEL_DELETE":
{ {
var data = e.Payload.ToObject<ChannelDeleteEvent>(_serializer);
var data = e.Payload.ToObject<ChannelDeleteEvent>(Serializer);
var channel = RemoveChannel(data.Id); var channel = RemoveChannel(data.Id);
if (channel != null) if (channel != null)
{ {
@@ -641,7 +642,7 @@ namespace Discord
//Members //Members
case "GUILD_MEMBER_ADD": case "GUILD_MEMBER_ADD":
{ {
var data = e.Payload.ToObject<GuildMemberAddEvent>(_serializer);
var data = e.Payload.ToObject<GuildMemberAddEvent>(Serializer);
var server = GetServer(data.GuildId.Value); var server = GetServer(data.GuildId.Value);
if (server != null) if (server != null)
{ {
@@ -658,7 +659,7 @@ namespace Discord
break; break;
case "GUILD_MEMBER_UPDATE": case "GUILD_MEMBER_UPDATE":
{ {
var data = e.Payload.ToObject<GuildMemberUpdateEvent>(_serializer);
var data = e.Payload.ToObject<GuildMemberUpdateEvent>(Serializer);
var server = GetServer(data.GuildId.Value); var server = GetServer(data.GuildId.Value);
if (server != null) if (server != null)
{ {
@@ -679,7 +680,7 @@ namespace Discord
break; break;
case "GUILD_MEMBER_REMOVE": case "GUILD_MEMBER_REMOVE":
{ {
var data = e.Payload.ToObject<GuildMemberRemoveEvent>(_serializer);
var data = e.Payload.ToObject<GuildMemberRemoveEvent>(Serializer);
var server = GetServer(data.GuildId.Value); var server = GetServer(data.GuildId.Value);
if (server != null) if (server != null)
{ {
@@ -699,7 +700,7 @@ namespace Discord
break; break;
case "GUILD_MEMBERS_CHUNK": case "GUILD_MEMBERS_CHUNK":
{ {
var data = e.Payload.ToObject<GuildMembersChunkEvent>(_serializer);
var data = e.Payload.ToObject<GuildMembersChunkEvent>(Serializer);
var server = GetServer(data.GuildId); var server = GetServer(data.GuildId);
if (server != null) if (server != null)
{ {
@@ -718,7 +719,7 @@ namespace Discord
//Roles //Roles
case "GUILD_ROLE_CREATE": case "GUILD_ROLE_CREATE":
{ {
var data = e.Payload.ToObject<GuildRoleCreateEvent>(_serializer);
var data = e.Payload.ToObject<GuildRoleCreateEvent>(Serializer);
var server = GetServer(data.GuildId); var server = GetServer(data.GuildId);
if (server != null) if (server != null)
{ {
@@ -734,7 +735,7 @@ namespace Discord
break; break;
case "GUILD_ROLE_UPDATE": case "GUILD_ROLE_UPDATE":
{ {
var data = e.Payload.ToObject<GuildRoleUpdateEvent>(_serializer);
var data = e.Payload.ToObject<GuildRoleUpdateEvent>(Serializer);
var server = GetServer(data.GuildId); var server = GetServer(data.GuildId);
if (server != null) if (server != null)
{ {
@@ -755,7 +756,7 @@ namespace Discord
break; break;
case "GUILD_ROLE_DELETE": case "GUILD_ROLE_DELETE":
{ {
var data = e.Payload.ToObject<GuildRoleDeleteEvent>(_serializer);
var data = e.Payload.ToObject<GuildRoleDeleteEvent>(Serializer);
var server = GetServer(data.GuildId); var server = GetServer(data.GuildId);
if (server != null) if (server != null)
{ {
@@ -777,7 +778,7 @@ namespace Discord
//Bans //Bans
case "GUILD_BAN_ADD": case "GUILD_BAN_ADD":
{ {
var data = e.Payload.ToObject<GuildBanAddEvent>(_serializer);
var data = e.Payload.ToObject<GuildBanAddEvent>(Serializer);
var server = GetServer(data.GuildId.Value); var server = GetServer(data.GuildId.Value);
if (server != null) if (server != null)
{ {
@@ -797,7 +798,7 @@ namespace Discord
break; break;
case "GUILD_BAN_REMOVE": case "GUILD_BAN_REMOVE":
{ {
var data = e.Payload.ToObject<GuildBanRemoveEvent>(_serializer);
var data = e.Payload.ToObject<GuildBanRemoveEvent>(Serializer);
var server = GetServer(data.GuildId.Value); var server = GetServer(data.GuildId.Value);
if (server != null) if (server != null)
{ {
@@ -815,7 +816,7 @@ namespace Discord
//Messages //Messages
case "MESSAGE_CREATE": case "MESSAGE_CREATE":
{ {
var data = e.Payload.ToObject<MessageCreateEvent>(_serializer);
var data = e.Payload.ToObject<MessageCreateEvent>(Serializer);


Channel channel = GetChannel(data.ChannelId); Channel channel = GetChannel(data.ChannelId);
if (channel != null) if (channel != null)
@@ -860,7 +861,7 @@ namespace Discord
break; break;
case "MESSAGE_UPDATE": case "MESSAGE_UPDATE":
{ {
var data = e.Payload.ToObject<MessageUpdateEvent>(_serializer);
var data = e.Payload.ToObject<MessageUpdateEvent>(Serializer);
var channel = GetChannel(data.ChannelId); var channel = GetChannel(data.ChannelId);
if (channel != null) if (channel != null)
{ {
@@ -876,7 +877,7 @@ namespace Discord
break; break;
case "MESSAGE_DELETE": case "MESSAGE_DELETE":
{ {
var data = e.Payload.ToObject<MessageDeleteEvent>(_serializer);
var data = e.Payload.ToObject<MessageDeleteEvent>(Serializer);
var channel = GetChannel(data.ChannelId); var channel = GetChannel(data.ChannelId);
if (channel != null) if (channel != null)
{ {
@@ -893,7 +894,7 @@ namespace Discord
{ {
if (Config.MessageCacheSize > 0) if (Config.MessageCacheSize > 0)
{ {
var data = e.Payload.ToObject<MessageAckEvent>(_serializer);
var data = e.Payload.ToObject<MessageAckEvent>(Serializer);
var channel = GetChannel(data.ChannelId); var channel = GetChannel(data.ChannelId);
if (channel != null) if (channel != null)
{ {
@@ -914,7 +915,7 @@ namespace Discord
//Statuses //Statuses
case "PRESENCE_UPDATE": case "PRESENCE_UPDATE":
{ {
var data = e.Payload.ToObject<PresenceUpdateEvent>(_serializer);
var data = e.Payload.ToObject<PresenceUpdateEvent>(Serializer);
User user; User user;
Server server; Server server;
if (data.GuildId == null) if (data.GuildId == null)
@@ -951,7 +952,7 @@ namespace Discord
break; break;
case "TYPING_START": case "TYPING_START":
{ {
var data = e.Payload.ToObject<TypingStartEvent>(_serializer);
var data = e.Payload.ToObject<TypingStartEvent>(Serializer);
var channel = GetChannel(data.ChannelId); var channel = GetChannel(data.ChannelId);
if (channel != null) if (channel != null)
{ {
@@ -980,7 +981,7 @@ namespace Discord
//Voice //Voice
case "VOICE_STATE_UPDATE": case "VOICE_STATE_UPDATE":
{ {
var data = e.Payload.ToObject<VoiceStateUpdateEvent>(_serializer);
var data = e.Payload.ToObject<VoiceStateUpdateEvent>(Serializer);
var server = GetServer(data.GuildId); var server = GetServer(data.GuildId);
if (server != null) if (server != null)
{ {
@@ -1002,7 +1003,7 @@ namespace Discord
//Settings //Settings
case "USER_UPDATE": case "USER_UPDATE":
{ {
var data = e.Payload.ToObject<UserUpdateEvent>(_serializer);
var data = e.Payload.ToObject<UserUpdateEvent>(Serializer);
if (data.Id == CurrentUser.Id) if (data.Id == CurrentUser.Id)
{ {
CurrentUser.Update(data); CurrentUser.Update(data);


+ 2
- 2
src/Discord.Net/Net/WebSockets/GatewaySocket.cs View File

@@ -22,8 +22,8 @@ namespace Discord.Net.WebSockets
private void OnReceivedDispatch(string type, JToken payload) private void OnReceivedDispatch(string type, JToken payload)
=> ReceivedDispatch(this, new WebSocketEventEventArgs(type, payload)); => ReceivedDispatch(this, new WebSocketEventEventArgs(type, payload));


public GatewaySocket(DiscordClient client, JsonSerializer serializer, Logger logger)
: base(client, serializer, logger)
public GatewaySocket(DiscordClient client, Logger logger)
: base(client, logger)
{ {
Disconnected += async (s, e) => Disconnected += async (s, e) =>
{ {


+ 2
- 4
src/Discord.Net/Net/WebSockets/WebSocket.cs View File

@@ -24,9 +24,7 @@ namespace Discord.Net.WebSockets
/// <summary> Gets the logger used for this client. </summary> /// <summary> Gets the logger used for this client. </summary>
protected internal Logger Logger { get; } protected internal Logger Logger { get; }

public CancellationToken CancelToken { get; private set; } public CancellationToken CancelToken { get; private set; }

public CancellationToken? ParentCancelToken { get; set; } public CancellationToken? ParentCancelToken { get; set; }


public string Host { get; set; } public string Host { get; set; }
@@ -40,11 +38,11 @@ namespace Discord.Net.WebSockets
private void OnDisconnected(bool wasUnexpected, Exception error) private void OnDisconnected(bool wasUnexpected, Exception error)
=> Disconnected(this, new DisconnectedEventArgs(wasUnexpected, error)); => Disconnected(this, new DisconnectedEventArgs(wasUnexpected, error));


public WebSocket(DiscordClient client, JsonSerializer serializer, Logger logger)
public WebSocket(DiscordClient client, Logger logger)
{ {
_client = client; _client = client;
Logger = logger; Logger = logger;
_serializer = serializer;
_serializer = client.Serializer;


_lock = new AsyncLock(); _lock = new AsyncLock();
_taskManager = new TaskManager(Cleanup); _taskManager = new TaskManager(Cleanup);


Loading…
Cancel
Save