Browse Source

Expose the Guild of a connected AudioClient on the interface

Expose the instance itself on events
pull/505/head
Joe4evr 8 years ago
parent
commit
8f0e9a761b
2 changed files with 13 additions and 8 deletions
  1. +4
    -2
      src/Discord.Net.Core/Audio/IAudioClient.cs
  2. +9
    -6
      src/Discord.Net.WebSocket/Audio/AudioClient.cs

+ 4
- 2
src/Discord.Net.Core/Audio/IAudioClient.cs View File

@@ -5,14 +5,16 @@ namespace Discord.Audio
{ {
public interface IAudioClient : IDisposable public interface IAudioClient : IDisposable
{ {
event Func<Task> Connected;
event Func<Exception, Task> Disconnected;
event Func<IAudioClient, Task> Connected;
event Func<IAudioClient, Exception, Task> Disconnected;
event Func<int, int, Task> LatencyUpdated; event Func<int, int, Task> LatencyUpdated;
/// <summary> Gets the current connection state of this client. </summary> /// <summary> Gets the current connection state of this client. </summary>
ConnectionState ConnectionState { get; } ConnectionState ConnectionState { get; }
/// <summary> Gets the estimated round-trip latency, in milliseconds, to the gateway server. </summary> /// <summary> Gets the estimated round-trip latency, in milliseconds, to the gateway server. </summary>
int Latency { get; } int Latency { get; }
/// <summary> Gets the Guild this client is in. </summary>
IGuild Guild { get; }


Task DisconnectAsync(); Task DisconnectAsync();




+ 9
- 6
src/Discord.Net.WebSocket/Audio/AudioClient.cs View File

@@ -14,18 +14,18 @@ namespace Discord.Audio
{ {
internal class AudioClient : IAudioClient, IDisposable internal class AudioClient : IAudioClient, IDisposable
{ {
public event Func<Task> Connected
public event Func<IAudioClient, Task> Connected
{ {
add { _connectedEvent.Add(value); } add { _connectedEvent.Add(value); }
remove { _connectedEvent.Remove(value); } remove { _connectedEvent.Remove(value); }
} }
private readonly AsyncEvent<Func<Task>> _connectedEvent = new AsyncEvent<Func<Task>>();
public event Func<Exception, Task> Disconnected
private readonly AsyncEvent<Func<IAudioClient, Task>> _connectedEvent = new AsyncEvent<Func<IAudioClient, Task>>();
public event Func<IAudioClient, Exception, Task> Disconnected
{ {
add { _disconnectedEvent.Add(value); } add { _disconnectedEvent.Add(value); }
remove { _disconnectedEvent.Remove(value); } remove { _disconnectedEvent.Remove(value); }
} }
private readonly AsyncEvent<Func<Exception, Task>> _disconnectedEvent = new AsyncEvent<Func<Exception, Task>>();
private readonly AsyncEvent<Func<IAudioClient, Exception, Task>> _disconnectedEvent = new AsyncEvent<Func<IAudioClient, Exception, Task>>();
public event Func<int, int, Task> LatencyUpdated public event Func<int, int, Task> LatencyUpdated
{ {
add { _latencyUpdatedEvent.Add(value); } add { _latencyUpdatedEvent.Add(value); }
@@ -115,7 +115,7 @@ namespace Discord.Audio
await ApiClient.SendIdentityAsync(userId, sessionId, token).ConfigureAwait(false); await ApiClient.SendIdentityAsync(userId, sessionId, token).ConfigureAwait(false);
await _connectTask.Task.ConfigureAwait(false); await _connectTask.Task.ConfigureAwait(false);


await _connectedEvent.InvokeAsync().ConfigureAwait(false);
await _connectedEvent.InvokeAsync(this).ConfigureAwait(false);
ConnectionState = ConnectionState.Connected; ConnectionState = ConnectionState.Connected;
await _audioLogger.InfoAsync("Connected").ConfigureAwait(false); await _audioLogger.InfoAsync("Connected").ConfigureAwait(false);
} }
@@ -164,7 +164,7 @@ namespace Discord.Audio


ConnectionState = ConnectionState.Disconnected; ConnectionState = ConnectionState.Disconnected;
await _audioLogger.InfoAsync("Disconnected").ConfigureAwait(false); await _audioLogger.InfoAsync("Disconnected").ConfigureAwait(false);
await _disconnectedEvent.InvokeAsync(ex).ConfigureAwait(false);
await _disconnectedEvent.InvokeAsync(this, ex).ConfigureAwait(false);


await Discord.ApiClient.SendVoiceStateUpdateAsync(Guild.Id, null, false, false).ConfigureAwait(false); await Discord.ApiClient.SendVoiceStateUpdateAsync(Guild.Id, null, false, false).ConfigureAwait(false);
} }
@@ -311,6 +311,9 @@ namespace Discord.Audio
} }
catch (OperationCanceledException) { } catch (OperationCanceledException) { }
} }
/// <inheritdoc />
IGuild IAudioClient.Guild => Guild;


internal void Dispose(bool disposing) internal void Dispose(bool disposing)
{ {


Loading…
Cancel
Save