@@ -43,9 +43,9 @@ namespace Discord.Audio | |||||
private Task _heartbeatTask; | private Task _heartbeatTask; | ||||
private long _heartbeatTime; | private long _heartbeatTime; | ||||
private string _url; | private string _url; | ||||
private bool _isDisposed; | |||||
private uint _ssrc; | private uint _ssrc; | ||||
private byte[] _secretKey; | private byte[] _secretKey; | ||||
private bool _isDisposed; | |||||
public SocketGuild Guild { get; } | public SocketGuild Guild { get; } | ||||
public DiscordVoiceAPIClient ApiClient { get; private set; } | public DiscordVoiceAPIClient ApiClient { get; private set; } | ||||
@@ -165,8 +165,9 @@ 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(ex).ConfigureAwait(false); | ||||
await Discord.ApiClient.SendVoiceStateUpdateAsync(Guild.Id, null, false, false).ConfigureAwait(false); | |||||
} | } | ||||
public Stream CreateOpusStream(int samplesPerFrame) | public Stream CreateOpusStream(int samplesPerFrame) | ||||
@@ -314,10 +315,12 @@ namespace Discord.Audio | |||||
internal void Dispose(bool disposing) | internal void Dispose(bool disposing) | ||||
{ | { | ||||
DisconnectInternalAsync(null).GetAwaiter().GetResult(); | |||||
if (!_isDisposed) | |||||
if (disposing && !_isDisposed) | |||||
{ | |||||
_isDisposed = true; | _isDisposed = true; | ||||
ApiClient.Dispose(); | |||||
DisconnectInternalAsync(null).GetAwaiter().GetResult(); | |||||
ApiClient.Dispose(); | |||||
} | |||||
} | } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public void Dispose() => Dispose(true); | public void Dispose() => Dispose(true); | ||||
@@ -54,7 +54,7 @@ namespace Discord.Audio | |||||
} | } | ||||
} | } | ||||
public override void Flush() | |||||
/*public override void Flush() | |||||
{ | { | ||||
FlushAsync(CancellationToken.None).GetAwaiter().GetResult(); | FlushAsync(CancellationToken.None).GetAwaiter().GetResult(); | ||||
} | } | ||||
@@ -68,7 +68,7 @@ namespace Discord.Audio | |||||
catch (Exception) { } //Incomplete frame | catch (Exception) { } //Incomplete frame | ||||
_partialFramePos = 0; | _partialFramePos = 0; | ||||
await base.FlushAsync(cancellationToken).ConfigureAwait(false); | await base.FlushAsync(cancellationToken).ConfigureAwait(false); | ||||
} | |||||
}*/ | |||||
protected override void Dispose(bool disposing) | protected override void Dispose(bool disposing) | ||||
{ | { | ||||
@@ -11,6 +11,7 @@ namespace Discord.Audio | |||||
private readonly byte[] _nonce, _secretKey; | private readonly byte[] _nonce, _secretKey; | ||||
private int _samplesPerFrame; | private int _samplesPerFrame; | ||||
private uint _ssrc, _timestamp = 0; | private uint _ssrc, _timestamp = 0; | ||||
private bool _isDisposed; | |||||
protected readonly byte[] _buffer; | protected readonly byte[] _buffer; | ||||
@@ -36,7 +37,11 @@ namespace Discord.Audio | |||||
protected override void Dispose(bool disposing) | protected override void Dispose(bool disposing) | ||||
{ | { | ||||
Flush(); | |||||
if (disposing && !_isDisposed) | |||||
{ | |||||
_isDisposed = true; | |||||
Flush(); | |||||
} | |||||
base.Dispose(disposing); | base.Dispose(disposing); | ||||
} | } | ||||
@@ -479,7 +479,6 @@ namespace Discord.WebSocket | |||||
if (AudioClient != null) | if (AudioClient != null) | ||||
await AudioClient.DisconnectAsync().ConfigureAwait(false); | await AudioClient.DisconnectAsync().ConfigureAwait(false); | ||||
AudioClient = null; | AudioClient = null; | ||||
await Discord.ApiClient.SendVoiceStateUpdateAsync(Id, null, false, false).ConfigureAwait(false); | |||||
} | } | ||||
internal async Task FinishConnectAudio(int id, string url, string token) | internal async Task FinishConnectAudio(int id, string url, string token) | ||||
{ | { | ||||