use actix_web::{web, Error, HttpRequest, HttpResponse};
#[derive(Clone)]
pub struct WebSocketConfig {
pub ping_interval: u64,
pub ping_timeout: u64,
pub buffer_size: usize,
}
impl Default for WebSocketConfig {
fn default() -> Self {
Self {
ping_interval: 30,
ping_timeout: 10,
buffer_size: 65536,
}
}
}
pub struct WebSocketHandler {
config: WebSocketConfig,
}
impl WebSocketHandler {
pub fn new() -> Self {
Self {
config: WebSocketConfig::default(),
}
}
pub fn ping_interval(mut self, interval: u64) -> Self {
self.config.ping_interval = interval;
self
}
pub fn buffer_size(mut self, size: usize) -> Self {
self.config.buffer_size = size;
self
}
pub async fn handle(
_req: HttpRequest,
_stream: web::Payload,
) -> Result<HttpResponse, Error> {
Ok(HttpResponse::NotImplemented()
.content_type("text/plain")
.body("WebSocket support requires the `websocket` feature. Add `websocket = [\"actix-web-actors\"]` to your Cargo.toml features."))
}
}
impl Default for WebSocketHandler {
fn default() -> Self {
Self::new()
}
}