| @@ -12,6 +12,9 @@ namespace Discord | |||||
| /// <summary> | /// <summary> | ||||
| /// Connects to this audio channel. | /// Connects to this audio channel. | ||||
| /// </summary> | /// </summary> | ||||
| Task<IAudioClient> ConnectAsync(Action<IAudioClient> configAction = null); | |||||
| Task<IAudioClient> ConnectAsync(bool selfDeaf = false, bool selfMute = false, bool external = false); | |||||
| /// <summary> Disconnects from this audio channel. </summary> | |||||
| Task DisconnectAsync(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -187,8 +187,8 @@ namespace Discord.Rest | |||||
| //IAudioChannel | //IAudioChannel | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="NotSupportedException">Connecting to a group channel is not supported.</exception> | /// <exception cref="NotSupportedException">Connecting to a group channel is not supported.</exception> | ||||
| Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction) => | |||||
| throw new NotSupportedException(); | |||||
| Task<IAudioClient> IAudioChannel.ConnectAsync(bool selfDeaf, bool selfMute, bool external) { throw new NotSupportedException(); } | |||||
| Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); } | |||||
| //IChannel | //IChannel | ||||
| Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | ||||
| @@ -54,7 +54,8 @@ namespace Discord.Rest | |||||
| //IAudioChannel | //IAudioChannel | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="NotSupportedException">Connecting to a REST-based channel is not supported.</exception> | /// <exception cref="NotSupportedException">Connecting to a REST-based channel is not supported.</exception> | ||||
| Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction) => throw new NotSupportedException(); | |||||
| Task<IAudioClient> IAudioChannel.ConnectAsync(bool selfDeaf, bool selfMute, bool external) { throw new NotSupportedException(); } | |||||
| Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); } | |||||
| //IGuildChannel | //IGuildChannel | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| @@ -256,8 +256,8 @@ namespace Discord.WebSocket | |||||
| //IAudioChannel | //IAudioChannel | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| /// <exception cref="NotSupportedException">Connecting to a group channel is not supported.</exception> | /// <exception cref="NotSupportedException">Connecting to a group channel is not supported.</exception> | ||||
| Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction) => | |||||
| throw new NotSupportedException(); | |||||
| Task<IAudioClient> IAudioChannel.ConnectAsync(bool selfDeaf, bool selfMute, bool external) { throw new NotSupportedException(); } | |||||
| Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); } | |||||
| //IChannel | //IChannel | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| @@ -51,11 +51,14 @@ namespace Discord.WebSocket | |||||
| => ChannelHelper.ModifyAsync(this, Discord, func, options); | => ChannelHelper.ModifyAsync(this, Discord, func, options); | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public async Task<IAudioClient> ConnectAsync(Action<IAudioClient> configAction = null) | |||||
| public async Task<IAudioClient> ConnectAsync(bool selfDeaf, bool selfMute, bool external) | |||||
| { | { | ||||
| return await Guild.ConnectAudioAsync(Id, false, false, configAction).ConfigureAwait(false); | |||||
| return await Guild.ConnectAudioAsync(Id, selfDeaf, selfMute, external).ConfigureAwait(false); | |||||
| } | } | ||||
| public async Task DisconnectAsync() | |||||
| => await Guild.DisconnectAudioAsync(); | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public override SocketGuildUser GetUser(ulong id) | public override SocketGuildUser GetUser(ulong id) | ||||
| { | { | ||||
| @@ -734,11 +734,8 @@ namespace Discord.WebSocket | |||||
| { | { | ||||
| return _audioClient?.GetInputStream(userId); | return _audioClient?.GetInputStream(userId); | ||||
| } | } | ||||
| internal async Task<IAudioClient> ConnectAudioAsync(ulong channelId, bool selfDeaf, bool selfMute, Action<IAudioClient> configAction) | |||||
| internal async Task<IAudioClient> ConnectAudioAsync(ulong channelId, bool selfDeaf, bool selfMute, bool external) | |||||
| { | { | ||||
| selfDeaf = false; | |||||
| selfMute = false; | |||||
| TaskCompletionSource<AudioClient> promise; | TaskCompletionSource<AudioClient> promise; | ||||
| await _audioLock.WaitAsync().ConfigureAwait(false); | await _audioLock.WaitAsync().ConfigureAwait(false); | ||||
| @@ -748,6 +745,13 @@ namespace Discord.WebSocket | |||||
| promise = new TaskCompletionSource<AudioClient>(); | promise = new TaskCompletionSource<AudioClient>(); | ||||
| _audioConnectPromise = promise; | _audioConnectPromise = promise; | ||||
| if (external) | |||||
| { | |||||
| var _ = promise.TrySetResultAsync(null); | |||||
| await Discord.ApiClient.SendVoiceStateUpdateAsync(Id, channelId, selfDeaf, selfMute).ConfigureAwait(false); | |||||
| return null; | |||||
| } | |||||
| if (_audioClient == null) | if (_audioClient == null) | ||||
| { | { | ||||
| var audioClient = new AudioClient(this, Discord.GetAudioId(), channelId); | var audioClient = new AudioClient(this, Discord.GetAudioId(), channelId); | ||||
| @@ -755,7 +759,9 @@ namespace Discord.WebSocket | |||||
| { | { | ||||
| if (!promise.Task.IsCompleted) | if (!promise.Task.IsCompleted) | ||||
| { | { | ||||
| try { audioClient.Dispose(); } catch { } | |||||
| try | |||||
| { audioClient.Dispose(); } | |||||
| catch { } | |||||
| _audioClient = null; | _audioClient = null; | ||||
| if (ex != null) | if (ex != null) | ||||
| await promise.TrySetExceptionAsync(ex); | await promise.TrySetExceptionAsync(ex); | ||||
| @@ -769,7 +775,6 @@ namespace Discord.WebSocket | |||||
| var _ = promise.TrySetResultAsync(_audioClient); | var _ = promise.TrySetResultAsync(_audioClient); | ||||
| return Task.Delay(0); | return Task.Delay(0); | ||||
| }; | }; | ||||
| configAction?.Invoke(audioClient); | |||||
| _audioClient = audioClient; | _audioClient = audioClient; | ||||
| } | } | ||||
| @@ -828,8 +833,11 @@ namespace Discord.WebSocket | |||||
| await _audioLock.WaitAsync().ConfigureAwait(false); | await _audioLock.WaitAsync().ConfigureAwait(false); | ||||
| try | try | ||||
| { | { | ||||
| await RepopulateAudioStreamsAsync().ConfigureAwait(false); | |||||
| await _audioClient.StartAsync(url, Discord.CurrentUser.Id, voiceState.VoiceSessionId, token).ConfigureAwait(false); | |||||
| if (_audioClient != null) | |||||
| { | |||||
| await RepopulateAudioStreamsAsync().ConfigureAwait(false); | |||||
| await _audioClient.StartAsync(url, Discord.CurrentUser.Id, voiceState.VoiceSessionId, token).ConfigureAwait(false); | |||||
| } | |||||
| } | } | ||||
| catch (OperationCanceledException) | catch (OperationCanceledException) | ||||
| { | { | ||||