use crate::{ import::*, WsErr };
#[ derive( Clone, Debug, PartialEq, Eq ) ]
pub enum WsEvent
{
Open,
Error,
Closing,
Closed( CloseEvent ),
WsErr( WsErr )
}
impl WsEvent
{
pub fn is_open( &self ) -> bool
{
match self
{
Self::Open => true,
_ => false,
}
}
pub fn is_err( &self ) -> bool
{
match self
{
Self::Error => true,
_ => false,
}
}
pub fn is_closing( &self ) -> bool
{
match self
{
Self::Closing => true,
_ => false,
}
}
pub fn is_closed( &self ) -> bool
{
match self
{
Self::Closed(_) => true,
_ => false,
}
}
pub fn is_ws_err( &self ) -> bool
{
match self
{
Self::WsErr(_) => true,
_ => false,
}
}
}
#[ derive( Clone, Debug, PartialEq, Eq ) ]
pub struct CloseEvent
{
pub code: u16,
pub reason: String,
pub was_clean: bool,
}
impl From<JsCloseEvt> for CloseEvent
{
fn from( js_evt: JsCloseEvt ) -> Self
{
Self
{
code : js_evt.code () ,
reason : js_evt.reason () ,
was_clean: js_evt.was_clean() ,
}
}
}