Implemented ClientDisconnect event for audio client. (#2520)
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Discord.Audio
|
||||
event Func<ulong, AudioInStream, Task> StreamCreated;
|
||||
event Func<ulong, Task> StreamDestroyed;
|
||||
event Func<ulong, bool, Task> SpeakingUpdated;
|
||||
event Func<ulong, Task> ClientDisconnected;
|
||||
|
||||
/// <summary> Gets the current connection state of this client. </summary>
|
||||
ConnectionState ConnectionState { get; }
|
||||
|
||||
14
src/Discord.Net.WebSocket/API/Voice/ClientDisconnectEvent.cs
Normal file
14
src/Discord.Net.WebSocket/API/Voice/ClientDisconnectEvent.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord.API.Voice;
|
||||
internal class ClientDisconnectEvent
|
||||
{
|
||||
[JsonProperty("user_id")]
|
||||
public ulong UserId { get; set; }
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord.Audio
|
||||
@@ -47,5 +47,11 @@ namespace Discord.Audio
|
||||
remove { _speakingUpdatedEvent.Remove(value); }
|
||||
}
|
||||
private readonly AsyncEvent<Func<ulong, bool, Task>> _speakingUpdatedEvent = new AsyncEvent<Func<ulong, bool, Task>>();
|
||||
public event Func<ulong, Task> ClientDisconnected
|
||||
{
|
||||
add { _clientDisconnectedEvent.Add(value); }
|
||||
remove { _clientDisconnectedEvent.Remove(value); }
|
||||
}
|
||||
private readonly AsyncEvent<Func<ulong, Task>> _clientDisconnectedEvent = new AsyncEvent<Func<ulong, Task>>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.Audio
|
||||
{
|
||||
@@ -279,6 +279,15 @@ namespace Discord.Audio
|
||||
await _speakingUpdatedEvent.InvokeAsync(data.UserId, data.Speaking);
|
||||
}
|
||||
break;
|
||||
case VoiceOpCode.ClientDisconnect:
|
||||
{
|
||||
await _audioLogger.DebugAsync("Received ClientDisconnect").ConfigureAwait(false);
|
||||
|
||||
var data = (payload as JToken).ToObject<ClientDisconnectEvent>(_serializer);
|
||||
|
||||
await _clientDisconnectedEvent.InvokeAsync(data.UserId);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
await _audioLogger.WarningAsync($"Unknown OpCode ({opCode})").ConfigureAwait(false);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user