use std::any::Any;
use async_trait::async_trait;
use webparse::{
ws::{CloseData, OwnedMessage},
};
use crate::{ProtError, ProtResult, RecvRequest, RecvResponse};
use super::{WsHandshake, WsOption};
#[async_trait]
pub trait WsTrait: Send {
#[inline]
async fn on_request(&mut self, req: &RecvRequest) -> ProtResult<RecvResponse> {
WsHandshake::build_request(req)
}
async fn on_open(&mut self, shake: WsHandshake) -> ProtResult<Option<WsOption>>;
async fn on_close(&mut self, _reason: &Option<CloseData>) {}
async fn on_error(&mut self, _err: ProtError) {}
async fn on_ping(&mut self, val: Vec<u8>) -> ProtResult<Option<OwnedMessage>> {
return Ok(Some(OwnedMessage::Pong(val)));
}
async fn on_pong(&mut self, _val: Vec<u8>) -> ProtResult<()> {
Ok(())
}
async fn on_message(&mut self, msg: OwnedMessage) -> ProtResult<()>;
async fn on_interval(&mut self, _option: &mut Option<WsOption>) -> ProtResult<()> {
Ok(())
}
fn as_any(&self) -> Option<&dyn Any> {
None
}
fn as_any_mut(&mut self) -> Option<&mut dyn Any> {
None
}
}