Skip to content

Commit

Permalink
Make voice heartbeater use own incrementing sequence value
Browse files Browse the repository at this point in the history
  • Loading branch information
Quahu committed Aug 3, 2024
1 parent 9391df6 commit faba794
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/Disqord.Voice.Api/Default/DefaultVoiceGatewayClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Disqord.Serialization.Json;
Expand Down Expand Up @@ -30,8 +31,6 @@ public class DefaultVoiceGatewayClient : IVoiceGatewayClient

public IJsonSerializer Serializer { get; }

public int? Sequence { get; private set; }

public CancellationToken StoppingToken { get; private set; }

private readonly object _stateLock = new();
Expand Down Expand Up @@ -172,7 +171,6 @@ private async Task InternalRunAsync(CancellationToken stoppingToken)
{
var payload = await Gateway.ReceiveAsync(stoppingToken).ConfigureAwait(false);
Logger.LogTrace("Received voice payload: {0}.", payload.Op);
Sequence = payload.S;

switch (payload.Op)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Disqord.Utilities.Threading;
Expand All @@ -20,6 +21,7 @@ public class DefaultVoiceGatewayHeartbeater : IVoiceGatewayHeartbeater

private DateTime? _lastSend;
private DateTime? _lastAcknowledge;
private uint _sequence;

private Cts? _cts;
private Task? _task;
Expand All @@ -40,6 +42,7 @@ public ValueTask StartAsync(TimeSpan interval)
Interval = interval;
_lastSend = null;
_lastAcknowledge = null;
_sequence = 0;
_cts = new Cts();
_task = Task.Run(InternalRunAsync, _cts.Token);
return default;
Expand Down Expand Up @@ -78,7 +81,7 @@ protected virtual VoiceGatewayPayloadJsonModel GetPayload()
return new()
{
Op = VoiceGatewayPayloadOperation.Heartbeat,
D = Client.Serializer.GetJsonNode(Client.Sequence)
D = Client.Serializer.GetJsonNode(_sequence++)
};
}

Expand Down
5 changes: 0 additions & 5 deletions src/Disqord.Voice.Api/IVoiceGatewayClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public interface IVoiceGatewayClient : ILogging, IAsyncDisposable

IJsonSerializer Serializer { get; }

/// <summary>
/// Gets the last sequence number (<see cref="VoiceGatewayPayloadJsonModel.S"/>) received from the voice gateway.
/// </summary>
int? Sequence { get; }

Task<ReadyJsonModel> WaitForReadyAsync(CancellationToken cancellationToken);

Task<SessionDescriptionJsonModel> WaitForSessionDescriptionAsync(CancellationToken cancellationToken);
Expand Down

0 comments on commit faba794

Please sign in to comment.