mod mods; use std::{collections::HashMap, convert::Infallible, sync::Arc, fs, fs::File, io::prelude::*, env}; use tokio::sync::{mpsc, Mutex}; use warp::{ws::Message, Filter, Rejection}; use toml; use serde_derive::Deserialize; #[derive(Deserialize)] struct General { websocket_ip: String, websocket_port: String, restore_conf: String, } #[derive(Debug, Clone)] pub struct Client { pub client_id: String, pub sender: Option>>, } type Clients = Arc>>; type Result = std::result::Result; #[tokio::main] async fn main() { let clients: Clients = Arc::new(Mutex::new(HashMap::new())); println!("Configuring websocket route"); let ws_route = warp::path("ws") .and(warp::ws()) .and(with_clients(clients.clone())) .and_then(mods::handlers::ws_handler); let routes = ws_route.with(warp::cors().allow_any_origin()); println!("Starting server"); warp::serve(routes).run(([127, 0, 0, 1], 8080)).await; } fn with_clients(clients: Clients) -> impl Filter + Clone { warp::any().map(move || clients.clone()) }