fix(ws): Songbird would fail if it could not deserialize ws payload. (#170)
Receiving a new opcode while connecting to a voice channel was causing the connection to fail, while this was handled correctly elsewhere. Unfortunately, Discord added such a payload during every connection. This PR moves the logging and conversion to no-op (and log) to catch both locations.
This commit is contained in:
13
src/ws.rs
13
src/ws.rs
@@ -14,7 +14,7 @@ use tokio_tungstenite::{
|
|||||||
MaybeTlsStream,
|
MaybeTlsStream,
|
||||||
WebSocketStream,
|
WebSocketStream,
|
||||||
};
|
};
|
||||||
use tracing::instrument;
|
use tracing::{debug, instrument};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub struct WsStream(WebSocketStream<MaybeTlsStream<TcpStream>>);
|
pub struct WsStream(WebSocketStream<MaybeTlsStream<TcpStream>>);
|
||||||
@@ -97,7 +97,16 @@ pub(crate) fn convert_ws_message(message: Option<Message>) -> Result<Option<Even
|
|||||||
// The below is safe as we have taken ownership of the inner `String`, and don't
|
// The below is safe as we have taken ownership of the inner `String`, and don't
|
||||||
// access it as a `str`/`String` or return it if failure occurs.
|
// access it as a `str`/`String` or return it if failure occurs.
|
||||||
Some(Message::Text(mut payload)) =>
|
Some(Message::Text(mut payload)) =>
|
||||||
unsafe { crate::json::from_str(payload.as_mut_str()) }.map(Some)?,
|
match unsafe { crate::json::from_str(payload.as_mut_str()) } {
|
||||||
|
Ok(event) => Some(event),
|
||||||
|
Err(why) => {
|
||||||
|
debug!(
|
||||||
|
"Could not deserialize websocket event, payload: {}, error: {}",
|
||||||
|
payload, why
|
||||||
|
);
|
||||||
|
None
|
||||||
|
},
|
||||||
|
},
|
||||||
Some(Message::Binary(bytes)) => {
|
Some(Message::Binary(bytes)) => {
|
||||||
return Err(Error::UnexpectedBinaryMessage(bytes));
|
return Err(Error::UnexpectedBinaryMessage(bytes));
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user