Browse Source

Implemented ClientDisconnect event for audio client. (#2520)

tags/3.9.0
Frederik P GitHub 2 years ago
parent
commit
4cad546d57
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 2 deletions
  1. +1
    -0
      src/Discord.Net.Core/Audio/IAudioClient.cs
  2. +14
    -0
      src/Discord.Net.WebSocket/API/Voice/ClientDisconnectEvent.cs
  3. +7
    -1
      src/Discord.Net.WebSocket/Audio/AudioClient.Events.cs
  4. +10
    -1
      src/Discord.Net.WebSocket/Audio/AudioClient.cs

+ 1
- 0
src/Discord.Net.Core/Audio/IAudioClient.cs View File

@@ -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
- 0
src/Discord.Net.WebSocket/API/Voice/ClientDisconnectEvent.cs View 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; }
}

+ 7
- 1
src/Discord.Net.WebSocket/Audio/AudioClient.Events.cs View File

@@ -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>>();
}
}

+ 10
- 1
src/Discord.Net.WebSocket/Audio/AudioClient.cs View File

@@ -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;


Loading…
Cancel
Save