Browse Source

Added AudioService.Leave(Channel)

pull/29/head
RogueException 9 years ago
parent
commit
1ccca4113f
1 changed files with 17 additions and 10 deletions
  1. +17
    -10
      src/Discord.Net.Audio/AudioService.cs

+ 17
- 10
src/Discord.Net.Audio/AudioService.cs View File

@@ -153,27 +153,34 @@ namespace Discord.Audio
} }


} }
}
public async Task Leave(Server server)
{
if (server == null) throw new ArgumentNullException(nameof(server));
}

public Task Leave(Server server) => Leave(server, null);
public Task Leave(Channel channel) => Leave(channel.Server, channel);
private async Task Leave(Server server, Channel channel)
{
if (server == null) throw new ArgumentNullException(nameof(server));


if (Config.EnableMultiserver) if (Config.EnableMultiserver)
{ {
AudioClient client; AudioClient client;
if (_voiceClients.TryRemove(server.Id, out client))
await client.Disconnect().ConfigureAwait(false);
//Potential race condition if changing channels during this call, but that's acceptable
if (channel == null || (_voiceClients.TryGetValue(server.Id, out client) && client.Channel == channel))
{
if (_voiceClients.TryRemove(server.Id, out client))
await client.Disconnect().ConfigureAwait(false);
}
} }
else else
{ {
using (await _asyncLock.LockAsync().ConfigureAwait(false)) using (await _asyncLock.LockAsync().ConfigureAwait(false))
{ {
var client = GetClient(server) as VirtualClient; var client = GetClient(server) as VirtualClient;
if (client != null)
if (client != null && client.Channel == channel)
await _defaultClient.Disconnect().ConfigureAwait(false); await _defaultClient.Disconnect().ConfigureAwait(false);
} }
} }
}
}

}
}
} }

Loading…
Cancel
Save