Prevent duplicate incoming stream events on connect
This commit is contained in:
@@ -47,15 +47,17 @@ namespace Discord.Audio
|
|||||||
public SocketGuild Guild { get; }
|
public SocketGuild Guild { get; }
|
||||||
public DiscordVoiceAPIClient ApiClient { get; private set; }
|
public DiscordVoiceAPIClient ApiClient { get; private set; }
|
||||||
public int Latency { get; private set; }
|
public int Latency { get; private set; }
|
||||||
|
public ulong ChannelId { get; internal set; }
|
||||||
|
|
||||||
private DiscordSocketClient Discord => Guild.Discord;
|
private DiscordSocketClient Discord => Guild.Discord;
|
||||||
public ConnectionState ConnectionState => _connection.State;
|
public ConnectionState ConnectionState => _connection.State;
|
||||||
|
|
||||||
/// <summary> Creates a new REST/WebSocket discord client. </summary>
|
/// <summary> Creates a new REST/WebSocket discord client. </summary>
|
||||||
internal AudioClient(SocketGuild guild, int id)
|
internal AudioClient(SocketGuild guild, int clientId, ulong channelId)
|
||||||
{
|
{
|
||||||
Guild = guild;
|
Guild = guild;
|
||||||
_audioLogger = Discord.LogManager.CreateLogger($"Audio #{id}");
|
ChannelId = channelId;
|
||||||
|
_audioLogger = Discord.LogManager.CreateLogger($"Audio #{clientId}");
|
||||||
|
|
||||||
ApiClient = new DiscordVoiceAPIClient(guild.Id, Discord.WebSocketProvider, Discord.UdpSocketProvider);
|
ApiClient = new DiscordVoiceAPIClient(guild.Id, Discord.WebSocketProvider, Discord.UdpSocketProvider);
|
||||||
ApiClient.SentGatewayMessage += async opCode => await _audioLogger.DebugAsync($"Sent {opCode}").ConfigureAwait(false);
|
ApiClient.SentGatewayMessage += async opCode => await _audioLogger.DebugAsync($"Sent {opCode}").ConfigureAwait(false);
|
||||||
|
|||||||
@@ -433,7 +433,13 @@ namespace Discord.WebSocket
|
|||||||
if (_audioClient != null && before.VoiceChannel?.Id != after.VoiceChannel?.Id)
|
if (_audioClient != null && before.VoiceChannel?.Id != after.VoiceChannel?.Id)
|
||||||
{
|
{
|
||||||
if (model.UserId == CurrentUser.Id)
|
if (model.UserId == CurrentUser.Id)
|
||||||
await RepopulateAudioStreamsAsync().ConfigureAwait(false);
|
{
|
||||||
|
if (after.VoiceChannel != null && _audioClient.ChannelId != after.VoiceChannel?.Id)
|
||||||
|
{
|
||||||
|
_audioClient.ChannelId = after.VoiceChannel.Id;
|
||||||
|
await RepopulateAudioStreamsAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _audioClient.RemoveInputStreamAsync(model.UserId).ConfigureAwait(false); //User changed channels, end their stream
|
await _audioClient.RemoveInputStreamAsync(model.UserId).ConfigureAwait(false); //User changed channels, end their stream
|
||||||
@@ -480,7 +486,7 @@ namespace Discord.WebSocket
|
|||||||
|
|
||||||
if (_audioClient == null)
|
if (_audioClient == null)
|
||||||
{
|
{
|
||||||
var audioClient = new AudioClient(this, Discord.GetAudioId());
|
var audioClient = new AudioClient(this, Discord.GetAudioId(), channelId);
|
||||||
audioClient.Disconnected += async ex =>
|
audioClient.Disconnected += async ex =>
|
||||||
{
|
{
|
||||||
if (!promise.Task.IsCompleted)
|
if (!promise.Task.IsCompleted)
|
||||||
|
|||||||
Reference in New Issue
Block a user