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.
This commit is contained in:
@@ -109,7 +109,7 @@ async fn runner(mut config: Config, rx: Receiver<CoreMessage>, tx: Sender<CoreMe
|
||||
drop(interconnect.events.send(EventMessage::FireCoreEvent(
|
||||
CoreContext::DriverDisconnect(InternalDisconnect {
|
||||
kind: DisconnectKind::Runtime,
|
||||
reason: None,
|
||||
reason: Some(DisconnectReason::Requested),
|
||||
info: conn.info.clone(),
|
||||
}),
|
||||
)));
|
||||
@@ -120,21 +120,26 @@ async fn runner(mut config: Config, rx: Receiver<CoreMessage>, tx: Sender<CoreMe
|
||||
// (i.e., prevent users from mistakenly trying to reconnect for an *old* dead conn).
|
||||
// if it *is* a match, the conn needs to die!
|
||||
// (as the WS channel has truly given up the ghost).
|
||||
if ws_idx == attempt_idx {
|
||||
connection = None;
|
||||
let conn = if ws_idx == attempt_idx {
|
||||
drop(interconnect.mixer.send(MixerMessage::DropConn));
|
||||
drop(interconnect.mixer.send(MixerMessage::RebuildEncoder));
|
||||
connection.take()
|
||||
} else {
|
||||
reason = None;
|
||||
}
|
||||
None
|
||||
};
|
||||
|
||||
drop(interconnect.events.send(EventMessage::FireCoreEvent(
|
||||
CoreContext::DriverDisconnect(InternalDisconnect {
|
||||
kind: DisconnectKind::Runtime,
|
||||
reason,
|
||||
info: ws_info,
|
||||
}),
|
||||
)));
|
||||
// Conn may have been unset earlier (i.e., in a deliberate disconnect).
|
||||
// If so, do not repropagate/repeat the disconnect event.
|
||||
if conn.is_some() {
|
||||
drop(interconnect.events.send(EventMessage::FireCoreEvent(
|
||||
CoreContext::DriverDisconnect(InternalDisconnect {
|
||||
kind: DisconnectKind::Runtime,
|
||||
reason,
|
||||
info: ws_info,
|
||||
}),
|
||||
)));
|
||||
}
|
||||
},
|
||||
CoreMessage::SetTrack(s) => {
|
||||
drop(interconnect.mixer.send(MixerMessage::SetTrack(s)));
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user