Added config to log, fixed LeaveVoiceServer

This commit is contained in:
Brandon Smith
2015-09-29 16:32:58 -03:00
parent ba23289a46
commit a526d2a75b
2 changed files with 22 additions and 7 deletions

View File

@@ -22,6 +22,7 @@ namespace Discord
private readonly JsonSerializer _serializer;
private readonly ConcurrentQueue<Message> _pendingMessages;
private readonly ConcurrentDictionary<string, DiscordSimpleClient> _voiceClients;
private bool _sentInitialLog;
/// <summary> Returns the current logged-in user. </summary>
public User CurrentUser => _currentUser;
@@ -219,9 +220,12 @@ namespace Discord
/// <returns> Returns a token for future connections. </returns>
public new async Task<string> Connect(string email, string password)
{
if (!_sentInitialLog)
SendInitialLog();
if (State != DiscordClientState.Disconnected)
await Disconnect().ConfigureAwait(false);
string token;
try
{
@@ -240,6 +244,9 @@ namespace Discord
/// <summary> Connects to the Discord server with the provided token. </summary>
public async Task Connect(string token)
{
if (!_sentInitialLog)
SendInitialLog();
if (State != (int)DiscordClientState.Disconnected)
await Disconnect().ConfigureAwait(false);
@@ -729,7 +736,9 @@ namespace Discord
return client;
}
async Task LeaveVoiceServer(string serverId)
public Task LeaveVoiceServer(Server server)
=> LeaveVoiceServer(server?.Id);
public async Task LeaveVoiceServer(string serverId)
{
CheckReady(); //checkVoice is done inside the voice client
if (serverId == null) throw new ArgumentNullException(nameof(serverId));
@@ -738,5 +747,12 @@ namespace Discord
if (_voiceClients.TryRemove(serverId, out client))
await client.Disconnect();
}
private void SendInitialLog()
{
if (_config.LogLevel >= LogMessageSeverity.Verbose)
RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Client, $"Config: {JsonConvert.SerializeObject(_config)}");
_sentInitialLog = true;
}
}
}

View File

@@ -9,7 +9,6 @@ namespace Discord
public interface IDiscordVoiceClient
{
Task JoinChannel(string channelId);
Task Disconnect();
void SendVoicePCM(byte[] data, int count);
void ClearVoicePCM();
@@ -24,7 +23,7 @@ namespace Discord
CheckReady(checkVoice: true);
if (channelId == null) throw new ArgumentNullException(nameof(channelId));
await ((IDiscordVoiceClient)this).Disconnect().ConfigureAwait(false);
await _voiceSocket.Disconnect().ConfigureAwait(false);
_voiceSocket.SetChannel(_voiceServerId, channelId);
_dataSocket.SendJoinVoice(_voiceServerId, channelId);
@@ -38,12 +37,12 @@ namespace Discord
catch (TimeoutException)
{
tokenSource.Cancel();
await ((IDiscordVoiceClient)this).Disconnect().ConfigureAwait(false);
await _voiceSocket.Disconnect().ConfigureAwait(false);
throw;
}
}
async Task IDiscordVoiceClient.Disconnect()
/*async Task IDiscordVoiceClient.Disconnect()
{
CheckReady(checkVoice: true);
@@ -55,7 +54,7 @@ namespace Discord
_dataSocket.SendLeaveVoice(_voiceSocket.CurrentServerId);
}
}
}
}*/
/// <summary> Sends a PCM frame to the voice server. Will block until space frees up in the outgoing buffer. </summary>
/// <param name="data">PCM frame to send. This must be a single or collection of uncompressed 48Kz monochannel 20ms PCM frames. </param>