25 lines
743 B
Rust
25 lines
743 B
Rust
use futures_channel::mpsc::UnboundedSender;
|
|
use tungstenite::Message;
|
|
use std::net::SocketAddr;
|
|
use std::collections::{HashMap, BTreeMap};
|
|
use std::sync::{Mutex, Arc};
|
|
|
|
pub type Tx = UnboundedSender<Message>;
|
|
pub type PeerMap = Arc<Mutex<HashMap<SocketAddr, Tx>>>;
|
|
pub type RoomMap = Arc<Mutex<BTreeMap<String, BTreeMap<String, SocketAddr>>>>;
|
|
|
|
pub trait TxSendMessage {
|
|
fn send_close(&self) -> bool;
|
|
fn send_text<S>(&self, text: S) -> bool where S: Into<String>;
|
|
}
|
|
|
|
impl TxSendMessage for Tx {
|
|
fn send_close(&self) -> bool {
|
|
self.unbounded_send(Message::Close(None)).is_ok()
|
|
}
|
|
|
|
fn send_text<S>(&self, text: S) -> bool where S: Into<String> {
|
|
self.unbounded_send(Message::Text(text.into())).is_ok()
|
|
}
|
|
}
|