use super::message::*; use crate::ws::Error as WsError; use audiopus::Error as OpusError; use flume::SendError; use std::io::Error as IoError; use xsalsa20poly1305::aead::Error as CryptoError; #[derive(Debug)] pub enum Recipient { AuxNetwork, Event, Mixer, UdpRx, UdpTx, } pub type Result = std::result::Result; #[derive(Debug)] pub enum Error { Crypto(CryptoError), /// Received an illegal voice packet on the voice UDP socket. IllegalVoicePacket, InterconnectFailure(Recipient), Io(IoError), Opus(OpusError), Ws(WsError), } impl Error { pub(crate) fn should_trigger_connect(&self) -> bool { matches!( self, Error::InterconnectFailure(Recipient::AuxNetwork) | Error::InterconnectFailure(Recipient::UdpRx) | Error::InterconnectFailure(Recipient::UdpTx) ) } pub(crate) fn should_trigger_interconnect_rebuild(&self) -> bool { matches!(self, Error::InterconnectFailure(Recipient::Event)) } } impl From for Error { fn from(e: CryptoError) -> Self { Error::Crypto(e) } } impl From for Error { fn from(e: IoError) -> Error { Error::Io(e) } } impl From for Error { fn from(e: OpusError) -> Error { Error::Opus(e) } } impl From> for Error { fn from(_e: SendError) -> Error { Error::InterconnectFailure(Recipient::AuxNetwork) } } impl From> for Error { fn from(_e: SendError) -> Error { Error::InterconnectFailure(Recipient::Event) } } impl From> for Error { fn from(_e: SendError) -> Error { Error::InterconnectFailure(Recipient::Mixer) } } impl From> for Error { fn from(_e: SendError) -> Error { Error::InterconnectFailure(Recipient::UdpRx) } } impl From> for Error { fn from(_e: SendError) -> Error { Error::InterconnectFailure(Recipient::UdpTx) } } impl From for Error { fn from(e: WsError) -> Error { Error::Ws(e) } }