- Fix `if (!external)` styling - Remove unecessary ConnectAsync overloadpull/1057/head
| @@ -7,9 +7,6 @@ namespace Discord | |||||
| public interface IAudioChannel : IChannel | public interface IAudioChannel : IChannel | ||||
| { | { | ||||
| /// <summary> Connects to this audio channel. </summary> | /// <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); | Task<IAudioClient> ConnectAsync(Action<IAudioClient> configAction = null, bool external = false); | ||||
| /// <summary> Disconnects from this audio channel. </summary> | /// <summary> Disconnects from this audio channel. </summary> | ||||
| @@ -143,7 +143,6 @@ namespace Discord.Rest | |||||
| => EnterTypingState(options); | => EnterTypingState(options); | ||||
| //IAudioChannel | //IAudioChannel | ||||
| Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction) { throw new NotSupportedException(); } | |||||
| Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction, bool external) { throw new NotSupportedException(); } | Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction, bool external) { throw new NotSupportedException(); } | ||||
| Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); } | Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); } | ||||
| @@ -41,7 +41,6 @@ namespace Discord.Rest | |||||
| private string DebuggerDisplay => $"{Name} ({Id}, Voice)"; | private string DebuggerDisplay => $"{Name} ({Id}, Voice)"; | ||||
| //IAudioChannel | //IAudioChannel | ||||
| Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction) { throw new NotSupportedException(); } | |||||
| Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction, bool external) { throw new NotSupportedException(); } | Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction, bool external) { throw new NotSupportedException(); } | ||||
| Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); } | Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); } | ||||
| @@ -206,7 +206,6 @@ namespace Discord.WebSocket | |||||
| => EnterTypingState(options); | => EnterTypingState(options); | ||||
| //IAudioChannel | //IAudioChannel | ||||
| Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction) { throw new NotSupportedException(); } | |||||
| Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction, bool external) { throw new NotSupportedException(); } | Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction, bool external) { throw new NotSupportedException(); } | ||||
| Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); } | Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); } | ||||
| @@ -518,37 +518,38 @@ namespace Discord.WebSocket | |||||
| promise = new TaskCompletionSource<AudioClient>(); | promise = new TaskCompletionSource<AudioClient>(); | ||||
| _audioConnectPromise = promise; | _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); | await Discord.ApiClient.SendVoiceStateUpdateAsync(Id, channelId, selfDeaf, selfMute).ConfigureAwait(false); | ||||