Browse Source

Review changes:

- Fix `if (!external)` styling
- Remove unecessary ConnectAsync overload
pull/1057/head
NovusTheory 7 years ago
parent
commit
a4e08b2506
5 changed files with 29 additions and 34 deletions
  1. +0
    -3
      src/Discord.Net.Core/Entities/Channels/IAudioChannel.cs
  2. +0
    -1
      src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs
  3. +0
    -1
      src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs
  4. +0
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs
  5. +29
    -28
      src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs

+ 0
- 3
src/Discord.Net.Core/Entities/Channels/IAudioChannel.cs View File

@@ -7,9 +7,6 @@ namespace Discord
public interface IAudioChannel : IChannel
{
/// <summary> Connects to this audio channel. </summary>
Task<IAudioClient> ConnectAsync(Action<IAudioClient> configAction = null);

/// <summary> Connects to this audio channel but can specify if client is handled externally. </summary>
Task<IAudioClient> ConnectAsync(Action<IAudioClient> configAction = null, bool external = false);

/// <summary> Disconnects from this audio channel. </summary>


+ 0
- 1
src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs View File

@@ -143,7 +143,6 @@ namespace Discord.Rest
=> EnterTypingState(options);

//IAudioChannel
Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction) { throw new NotSupportedException(); }
Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction, bool external) { throw new NotSupportedException(); }
Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); }



+ 0
- 1
src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs View File

@@ -41,7 +41,6 @@ namespace Discord.Rest
private string DebuggerDisplay => $"{Name} ({Id}, Voice)";

//IAudioChannel
Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction) { throw new NotSupportedException(); }
Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction, bool external) { throw new NotSupportedException(); }
Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); }



+ 0
- 1
src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs View File

@@ -206,7 +206,6 @@ namespace Discord.WebSocket
=> EnterTypingState(options);

//IAudioChannel
Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction) { throw new NotSupportedException(); }
Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction, bool external) { throw new NotSupportedException(); }
Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); }



+ 29
- 28
src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs View File

@@ -518,37 +518,38 @@ namespace Discord.WebSocket
promise = new TaskCompletionSource<AudioClient>();
_audioConnectPromise = promise;

if (!external)
if (external)
{
if (_audioClient == null)
var _ = promise.TrySetResultAsync(null);
await Discord.ApiClient.SendVoiceStateUpdateAsync(Id, channelId, selfDeaf, selfMute).ConfigureAwait(false);
return null;
}

if (_audioClient == null)
{
var audioClient = new AudioClient(this, Discord.GetAudioId(), channelId);
audioClient.Disconnected += async ex =>
{
var audioClient = new AudioClient(this, Discord.GetAudioId(), channelId);
audioClient.Disconnected += async ex =>
{
if (!promise.Task.IsCompleted)
{
try
{ audioClient.Dispose(); }
catch { }
_audioClient = null;
if (ex != null)
await promise.TrySetExceptionAsync(ex);
else
await promise.TrySetCanceledAsync();
return;
}
};
audioClient.Connected += () =>
if (!promise.Task.IsCompleted)
{
var _ = promise.TrySetResultAsync(_audioClient);
return Task.Delay(0);
};
configAction?.Invoke(audioClient);
_audioClient = audioClient;
}
} else
{
var _ = promise.TrySetResultAsync(null);
try
{ audioClient.Dispose(); }
catch { }
_audioClient = null;
if (ex != null)
await promise.TrySetExceptionAsync(ex);
else
await promise.TrySetCanceledAsync();
return;
}
};
audioClient.Connected += () =>
{
var _ = promise.TrySetResultAsync(_audioClient);
return Task.Delay(0);
};
configAction?.Invoke(audioClient);
_audioClient = audioClient;
}

await Discord.ApiClient.SendVoiceStateUpdateAsync(Id, channelId, selfDeaf, selfMute).ConfigureAwait(false);


Loading…
Cancel
Save