api: upgrade audio client to VoiceWS v3
This commit is contained in:
10
src/Discord.Net.WebSocket/API/Voice/HelloEvent.cs
Normal file
10
src/Discord.Net.WebSocket/API/Voice/HelloEvent.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Voice
|
||||
{
|
||||
internal class HelloEvent
|
||||
{
|
||||
[JsonProperty("heartbeat_interval")]
|
||||
public int HeartbeatInterval { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma warning disable CS1591
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Discord.API.Voice
|
||||
{
|
||||
@@ -14,6 +15,7 @@ namespace Discord.API.Voice
|
||||
[JsonProperty("modes")]
|
||||
public string[] Modes { get; set; }
|
||||
[JsonProperty("heartbeat_interval")]
|
||||
[Obsolete("This field is errorneous and should not be used", true)]
|
||||
public int HeartbeatInterval { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#pragma warning disable CS1591
|
||||
#pragma warning disable CS1591
|
||||
namespace Discord.API.Voice
|
||||
{
|
||||
internal enum VoiceOpCode : byte
|
||||
@@ -11,11 +11,19 @@ namespace Discord.API.Voice
|
||||
Ready = 2,
|
||||
/// <summary> C→S - Used to keep the connection alive and measure latency. </summary>
|
||||
Heartbeat = 3,
|
||||
/// <summary> C←S - Used to reply to a client's heartbeat. </summary>
|
||||
HeartbeatAck = 3,
|
||||
/// <summary> C←S - Used to provide an encryption key to the client. </summary>
|
||||
SessionDescription = 4,
|
||||
/// <summary> C↔S - Used to inform that a certain user is speaking. </summary>
|
||||
Speaking = 5
|
||||
Speaking = 5,
|
||||
/// <summary> C←S - Used to reply to a client's heartbeat. </summary>
|
||||
HeartbeatAck = 6,
|
||||
/// <summary> C→S - Used to resume a connection. </summary>
|
||||
Resume = 7,
|
||||
/// <summary> C←S - Used to inform the client the heartbeat interval. </summary>
|
||||
Hello = 8,
|
||||
/// <summary> C←S - Used to acknowledge a resumed connection. </summary>
|
||||
Resumed = 9,
|
||||
/// <summary> C←S - Used to notify that a client has disconnected. </summary>
|
||||
ClientDisconnect = 13,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Discord.API.Voice;
|
||||
using Discord.API.Voice;
|
||||
using Discord.Audio.Streams;
|
||||
using Discord.Logging;
|
||||
using Discord.Net.Converters;
|
||||
@@ -107,7 +107,7 @@ namespace Discord.Audio
|
||||
private async Task OnConnectingAsync()
|
||||
{
|
||||
await _audioLogger.DebugAsync("Connecting ApiClient").ConfigureAwait(false);
|
||||
await ApiClient.ConnectAsync("wss://" + _url).ConfigureAwait(false);
|
||||
await ApiClient.ConnectAsync("wss://" + _url + "?v=3").ConfigureAwait(false);
|
||||
await _audioLogger.DebugAsync("Listening on port " + ApiClient.UdpPort).ConfigureAwait(false);
|
||||
await _audioLogger.DebugAsync("Sending Identity").ConfigureAwait(false);
|
||||
await ApiClient.SendIdentityAsync(_userId, _sessionId, _token).ConfigureAwait(false);
|
||||
@@ -216,6 +216,14 @@ namespace Discord.Audio
|
||||
{
|
||||
switch (opCode)
|
||||
{
|
||||
case VoiceOpCode.Hello:
|
||||
{
|
||||
await _audioLogger.DebugAsync("Received Hello").ConfigureAwait(false);
|
||||
var data = (payload as JToken).ToObject<HelloEvent>(_serializer);
|
||||
|
||||
_heartbeatTask = RunHeartbeatAsync(data.HeartbeatInterval, _connection.CancelToken);
|
||||
}
|
||||
break;
|
||||
case VoiceOpCode.Ready:
|
||||
{
|
||||
await _audioLogger.DebugAsync("Received Ready").ConfigureAwait(false);
|
||||
@@ -225,8 +233,6 @@ namespace Discord.Audio
|
||||
|
||||
if (!data.Modes.Contains(DiscordVoiceAPIClient.Mode))
|
||||
throw new InvalidOperationException($"Discord does not support {DiscordVoiceAPIClient.Mode}");
|
||||
|
||||
_heartbeatTask = RunHeartbeatAsync(data.HeartbeatInterval, _connection.CancelToken);
|
||||
|
||||
ApiClient.SetUdpEndpoint(data.Ip, data.Port);
|
||||
await ApiClient.SendDiscoveryAsync(_ssrc).ConfigureAwait(false);
|
||||
|
||||
Reference in New Issue
Block a user