Skip to content

Commit

Permalink
fix: Fix behavior with NotifyVoiceServerUpdatedAsync/NotifyVoiceState…
Browse files Browse the repository at this point in the history
…UpdatedAsync

Previously on player creation the event would be only invoked after the player creation finished which implied that only one of the event would be actually invoked on creation. This commit changes to always dispatch both events regardless of their order of execution.
  • Loading branch information
angelobreuer committed Feb 11, 2024
1 parent 8608c23 commit 3339a89
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Lavalink4NET/Players/LavalinkPlayerHandle.cs
Original file line number Diff line number Diff line change
@@ -148,9 +148,14 @@ private async ValueTask CompleteAsync(bool isVoiceServerUpdated, CancellationTok
Interlocked.Decrement(ref Diagnostics.PendingHandles);
Interlocked.Increment(ref Diagnostics.ActivePlayers);
}

if (_value is ILavalinkPlayerListener playerListener)
else
{
// Player already created which indicates that the completion indicates a voice server or voice state update
if (_value is not ILavalinkPlayerListener playerListener)
{
return;
}

if (isVoiceServerUpdated)
{
await playerListener
@@ -246,6 +251,17 @@ await lifecycle
.NotifyPlayerCreatedAsync(cancellationToken)
.ConfigureAwait(false);

if (player is ILavalinkPlayerListener playerListener)
{
await playerListener
.NotifyVoiceServerUpdatedAsync(_voiceServer.Value, cancellationToken)
.ConfigureAwait(false);

await playerListener
.NotifyVoiceStateUpdatedAsync(_voiceState.Value, cancellationToken)
.ConfigureAwait(false);
}

return player;
}
}

0 comments on commit 3339a89

Please sign in to comment.