| @@ -13,6 +13,7 @@ namespace Discord.Audio | |||||
| event Func<ulong, AudioInStream, Task> StreamCreated; | event Func<ulong, AudioInStream, Task> StreamCreated; | ||||
| event Func<ulong, Task> StreamDestroyed; | event Func<ulong, Task> StreamDestroyed; | ||||
| event Func<ulong, bool, Task> SpeakingUpdated; | event Func<ulong, bool, Task> SpeakingUpdated; | ||||
| event Func<ulong, Task> ClientDisconnected; | |||||
| /// <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; } | ||||
| @@ -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; | using System.Threading.Tasks; | ||||
| namespace Discord.Audio | namespace Discord.Audio | ||||
| @@ -47,5 +47,11 @@ namespace Discord.Audio | |||||
| remove { _speakingUpdatedEvent.Remove(value); } | remove { _speakingUpdatedEvent.Remove(value); } | ||||
| } | } | ||||
| private readonly AsyncEvent<Func<ulong, bool, Task>> _speakingUpdatedEvent = new AsyncEvent<Func<ulong, bool, Task>>(); | 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.Text; | ||||
| using System.Threading; | using System.Threading; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using System.Collections.Generic; | |||||
| using System.Collections.Generic; | |||||
| namespace Discord.Audio | namespace Discord.Audio | ||||
| { | { | ||||
| @@ -279,6 +279,15 @@ namespace Discord.Audio | |||||
| await _speakingUpdatedEvent.InvokeAsync(data.UserId, data.Speaking); | await _speakingUpdatedEvent.InvokeAsync(data.UserId, data.Speaking); | ||||
| } | } | ||||
| break; | 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: | default: | ||||
| await _audioLogger.WarningAsync($"Unknown OpCode ({opCode})").ConfigureAwait(false); | await _audioLogger.WarningAsync($"Unknown OpCode ({opCode})").ConfigureAwait(false); | ||||
| return; | return; | ||||