From a5d9b58e941d568dcd8a4cc1cbb5bf9266f7d006 Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Tue, 19 Mar 2024 08:28:56 +0000 Subject: [PATCH] Driver: Fix multiple disconnect events on `leave` (#233) Fixes behaviour where a Driver which was asked to leave an active call would receive the disconnect event several times: once when we started the disconnect, and once again when Discord killed the WS client. --- src/driver/tasks/mod.rs | 27 ++++++++++++++++----------- src/events/context/data/disconnect.rs | 4 ++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/driver/tasks/mod.rs b/src/driver/tasks/mod.rs index 4f42c22..49425fe 100644 --- a/src/driver/tasks/mod.rs +++ b/src/driver/tasks/mod.rs @@ -109,7 +109,7 @@ async fn runner(mut config: Config, rx: Receiver, tx: Sender, tx: Sender { drop(interconnect.mixer.send(MixerMessage::SetTrack(s))); diff --git a/src/events/context/data/disconnect.rs b/src/events/context/data/disconnect.rs index 4275849..0b22cd9 100644 --- a/src/events/context/data/disconnect.rs +++ b/src/events/context/data/disconnect.rs @@ -75,6 +75,10 @@ pub enum DisconnectReason { ProtocolViolation, /// A voice connection was not established in the specified time. TimedOut, + /// The call was manually disconnected by a user command, e.g. [`Driver::leave`]. + /// + /// [`Driver::leave`]: crate::driver::Driver::leave + Requested, /// The Websocket connection was closed by Discord. /// /// This typically indicates that the voice session has expired,