Driver: Support tokio-websockets (#226)
* Driver: Support `tokio-websockets` * Fix bad feature flag * Fix CI & examples features * Use tungstenite in twilight example * Error if none or both ws features are enabled * Match `twilight-gateway` features
This commit is contained in:
@@ -4,6 +4,7 @@ use crate::{
|
||||
model::{CloseCode as VoiceCloseCode, FromPrimitive},
|
||||
ws::Error as WsError,
|
||||
};
|
||||
#[cfg(feature = "tungstenite")]
|
||||
use tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode;
|
||||
|
||||
/// Voice connection details gathered at termination or failure.
|
||||
@@ -108,10 +109,16 @@ impl From<&ConnectionError> for DisconnectReason {
|
||||
impl From<&WsError> for DisconnectReason {
|
||||
fn from(e: &WsError) -> Self {
|
||||
Self::WsClosed(match e {
|
||||
#[cfg(feature = "tungstenite")]
|
||||
WsError::WsClosed(Some(frame)) => match frame.code {
|
||||
CloseCode::Library(l) => VoiceCloseCode::from_u16(l),
|
||||
_ => None,
|
||||
},
|
||||
#[cfg(feature = "tws")]
|
||||
WsError::WsClosed(Some(code)) => match (*code).into() {
|
||||
code @ 4000..=4999_u16 => VoiceCloseCode::from_u16(code),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user