Merge pull request #167 from DigiTechs/audio
Finish SocketVoiceChannel.ConnectAsync
This commit is contained in:
@@ -45,8 +45,9 @@ namespace Discord
|
||||
await Discord.ApiClient.SendVoiceStateUpdateAsync(Guild.Id, Id,
|
||||
(audioMode & AudioMode.Incoming) == 0,
|
||||
(audioMode & AudioMode.Outgoing) == 0).ConfigureAwait(false);
|
||||
return null;
|
||||
//TODO: Block and return
|
||||
|
||||
await Guild.AudioConnectPromise.ConfigureAwait(false);
|
||||
return Guild.AudioClient;
|
||||
}
|
||||
|
||||
public SocketVoiceChannel Clone() => MemberwiseClone() as SocketVoiceChannel;
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Discord
|
||||
internal override bool IsAttached => true;
|
||||
|
||||
private readonly SemaphoreSlim _audioLock;
|
||||
private TaskCompletionSource<bool> _syncPromise, _downloaderPromise;
|
||||
private TaskCompletionSource<bool> _syncPromise, _downloaderPromise, _audioConnectPromise;
|
||||
private ConcurrentHashSet<ulong> _channels;
|
||||
private ConcurrentDictionary<ulong, SocketGuildUser> _members;
|
||||
private ConcurrentDictionary<ulong, VoiceState> _voiceStates;
|
||||
@@ -39,6 +39,7 @@ namespace Discord
|
||||
public bool IsSynced => _syncPromise.Task.IsCompleted;
|
||||
public Task SyncPromise => _syncPromise.Task;
|
||||
public Task DownloaderPromise => _downloaderPromise.Task;
|
||||
public Task AudioConnectPromise => _audioConnectPromise.Task;
|
||||
|
||||
public new DiscordSocketClient Discord => base.Discord as DiscordSocketClient;
|
||||
public SocketGuildUser CurrentUser => GetUser(Discord.CurrentUser.Id);
|
||||
@@ -306,7 +307,16 @@ namespace Discord
|
||||
{
|
||||
_audioLock.Release();
|
||||
}
|
||||
await audioClient.ConnectAsync(url, CurrentUser.Id, voiceState.VoiceSessionId, token).ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
await audioClient.ConnectAsync(url, CurrentUser.Id, voiceState.VoiceSessionId, token).ConfigureAwait(false);
|
||||
await _audioConnectPromise.TrySetResultAsync(true).ConfigureAwait(false);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
await _audioConnectPromise.SetExceptionAsync(e).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public SocketGuild Clone() => MemberwiseClone() as SocketGuild;
|
||||
|
||||
Reference in New Issue
Block a user