[Feature] Allow switching voice channels without disconnecting (external clients only) (#2866)

* eh well it should work

* fix issues

* make sure an external client is used
This commit is contained in:
Mihail Gribkov
2024-02-26 13:54:18 +03:00
committed by GitHub
parent bc5c1c523b
commit 5a62ba1af4
8 changed files with 12 additions and 10 deletions

View File

@@ -387,7 +387,7 @@ namespace Discord.WebSocket
#region IAudioChannel
/// <inheritdoc />
/// <exception cref="NotSupportedException">Connecting to a group channel is not supported.</exception>
Task<IAudioClient> IAudioChannel.ConnectAsync(bool selfDeaf, bool selfMute, bool external) { throw new NotSupportedException(); }
Task<IAudioClient> IAudioChannel.ConnectAsync(bool selfDeaf, bool selfMute, bool external, bool disconnect) { throw new NotSupportedException(); }
Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); }
Task IAudioChannel.ModifyAsync(Action<AudioChannelProperties> func, RequestOptions options) { throw new NotSupportedException(); }
#endregion

View File

@@ -89,8 +89,8 @@ namespace Discord.WebSocket
=> ChannelHelper.ModifyAsync(this, Discord, func, options);
/// <inheritdoc />
public Task<IAudioClient> ConnectAsync(bool selfDeaf = false, bool selfMute = false, bool external = false)
=> Guild.ConnectAudioAsync(Id, selfDeaf, selfMute, external);
public Task<IAudioClient> ConnectAsync(bool selfDeaf = false, bool selfMute = false, bool external = false, bool disconnect = true)
=> Guild.ConnectAudioAsync(Id, selfDeaf, selfMute, external, disconnect);
/// <inheritdoc />
public Task DisconnectAsync()

View File

@@ -1723,14 +1723,15 @@ namespace Discord.WebSocket
{
return _audioClient?.GetInputStream(userId);
}
internal async Task<IAudioClient> ConnectAudioAsync(ulong channelId, bool selfDeaf, bool selfMute, bool external)
internal async Task<IAudioClient> ConnectAudioAsync(ulong channelId, bool selfDeaf, bool selfMute, bool external, bool disconnect = true)
{
TaskCompletionSource<AudioClient> promise;
await _audioLock.WaitAsync().ConfigureAwait(false);
try
{
await DisconnectAudioInternalAsync().ConfigureAwait(false);
if (disconnect || !external)
await DisconnectAudioInternalAsync().ConfigureAwait(false);
promise = new TaskCompletionSource<AudioClient>();
_audioConnectPromise = promise;