Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle Voice close codes, prevent Songbird spinning WS threads (#1068)
Voice `CloseCode`s now map to a type rather than a collection of constants. Correct close code handling in this way terminates the websocket task when there is no likelihood of resuming, which was causing leftover tasks to spin at the `tokio::select` in some circumstances (i.e., ::leave, which keeps the `Driver` alive).
- Loading branch information
1 parent
9dfba84
commit 79c506e
Showing
5 changed files
with
98 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use enum_primitive::*; | ||
|
||
enum_from_primitive! { | ||
/// Discord Voice Gateway Websocket close codes. | ||
#[derive(Copy, Clone, Debug, Eq, PartialEq)] | ||
pub enum CloseCode { | ||
/// Invalid Voice OP Code. | ||
UnknownOpcode = 4001, | ||
|
||
/// Invalid identification payload sent. | ||
InvalidPayload = 4002, | ||
|
||
/// A payload was sent prior to identifying. | ||
NotAuthenticated = 4003, | ||
|
||
/// The account token sent with the identify payload was incorrect. | ||
AuthenticationFailed = 4004, | ||
|
||
/// More than one identify payload was sent. | ||
AlreadyAuthenticated = 4005, | ||
|
||
/// The session is no longer valid. | ||
SessionInvalid = 4006, | ||
|
||
/// A session timed out. | ||
SessionTimeout = 4009, | ||
|
||
/// The server for the last connection attempt could not be found. | ||
ServerNotFound = 4011, | ||
|
||
/// Discord did not recognise the voice protocol chosen. | ||
UnknownProtocol = 4012, | ||
|
||
/// Disconnected, either due to channel closure/removal | ||
/// or kicking. | ||
/// | ||
/// Should not reconnect. | ||
Disconnected = 4014, | ||
|
||
/// Connected voice server crashed. | ||
/// | ||
/// Should resume. | ||
VoiceServerCrash = 4015, | ||
|
||
/// Discord didn't recognise the encryption scheme. | ||
UnknownEncryptionMode = 4016, | ||
} | ||
} | ||
|
||
impl CloseCode { | ||
/// Indicates whether a voice client should attempt to reconnect in response to this close code. | ||
/// | ||
/// Otherwise, the connection should be closed. | ||
pub fn should_resume(&self) -> bool { | ||
match self { | ||
CloseCode::VoiceServerCrash | CloseCode::SessionTimeout => true, | ||
_ => false, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters