Browse Source

Prevent duplicate incoming stream events on connect

tags/1.0-rc
RogueException 8 years ago
parent
commit
6798ba0d4b
2 changed files with 12 additions and 4 deletions
  1. +4
    -2
      src/Discord.Net.WebSocket/Audio/AudioClient.cs
  2. +8
    -2
      src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs

+ 4
- 2
src/Discord.Net.WebSocket/Audio/AudioClient.cs View File

@@ -47,15 +47,17 @@ namespace Discord.Audio
public SocketGuild Guild { get; }
public DiscordVoiceAPIClient ApiClient { get; private set; }
public int Latency { get; private set; }
public ulong ChannelId { get; internal set; }

private DiscordSocketClient Discord => Guild.Discord;
public ConnectionState ConnectionState => _connection.State;

/// <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;
_audioLogger = Discord.LogManager.CreateLogger($"Audio #{id}");
ChannelId = channelId;
_audioLogger = Discord.LogManager.CreateLogger($"Audio #{clientId}");

ApiClient = new DiscordVoiceAPIClient(guild.Id, Discord.WebSocketProvider, Discord.UdpSocketProvider);
ApiClient.SentGatewayMessage += async opCode => await _audioLogger.DebugAsync($"Sent {opCode}").ConfigureAwait(false);


+ 8
- 2
src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs View File

@@ -433,7 +433,13 @@ namespace Discord.WebSocket
if (_audioClient != null && before.VoiceChannel?.Id != after.VoiceChannel?.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
{
await _audioClient.RemoveInputStreamAsync(model.UserId).ConfigureAwait(false); //User changed channels, end their stream
@@ -480,7 +486,7 @@ namespace Discord.WebSocket

if (_audioClient == null)
{
var audioClient = new AudioClient(this, Discord.GetAudioId());
var audioClient = new AudioClient(this, Discord.GetAudioId(), channelId);
audioClient.Disconnected += async ex =>
{
if (!promise.Task.IsCompleted)


Loading…
Cancel
Save