()
| 65 | |
| 66 | impl ChatServer { |
| 67 | pub fn new() -> (Self, ChatServerHandle) { |
| 68 | // create empty server |
| 69 | let mut rooms = HashMap::with_capacity(4); |
| 70 | |
| 71 | // create default room |
| 72 | rooms.insert("main".to_owned(), HashSet::new()); |
| 73 | |
| 74 | let (cmd_tx, cmd_rx) = mpsc::unbounded_channel(); |
| 75 | |
| 76 | ( |
| 77 | Self { |
| 78 | sessions: HashMap::new(), |
| 79 | rooms, |
| 80 | visitor_count: Arc::new(AtomicUsize::new(0)), |
| 81 | cmd_rx, |
| 82 | }, |
| 83 | ChatServerHandle { cmd_tx }, |
| 84 | ) |
| 85 | } |
| 86 | |
| 87 | /// Send message to users in a room. |
| 88 | /// |