feat: add version
This commit is contained in:
15
src/main.rs
15
src/main.rs
@@ -16,6 +16,9 @@ type Tx = UnboundedSender<Message>;
|
||||
type PeerMap = Arc<Mutex<HashMap<SocketAddr, Tx>>>;
|
||||
type RoomMap = Arc<Mutex<BTreeMap<String, BTreeMap<String, SocketAddr>>>>;
|
||||
|
||||
const NAME: &str = env!("CARGO_PKG_NAME");
|
||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
enum RoomMessageType {
|
||||
#[serde(rename = "Enter")]
|
||||
@@ -191,6 +194,12 @@ async fn inner_handle_connection(
|
||||
}
|
||||
return future::ok(());
|
||||
}
|
||||
if msg == "/version" {
|
||||
tx.unbounded_send(Message::Text(
|
||||
format!("{} - v{}", NAME, VERSION)
|
||||
)).ok();
|
||||
return future::ok(());
|
||||
}
|
||||
}
|
||||
let room_message = match serde_json::from_str::<RoomMessage>(&msg) {
|
||||
Ok(room_message) => room_message,
|
||||
@@ -220,8 +229,7 @@ async fn inner_handle_connection(
|
||||
"Replace client: {:?} - {:?}, from {:?} -> {:?}",
|
||||
msg_room_id, msg_client_id, peer_addr, addr
|
||||
);
|
||||
let tx = peer_map.lock().unwrap().remove(peer_addr);
|
||||
if let Some(tx) = tx {
|
||||
if let Some(tx) = peer_map.lock().unwrap().remove(peer_addr) {
|
||||
tx.unbounded_send(Message::Close(None)).ok();
|
||||
}
|
||||
client_map.insert(msg_client_id.clone(), addr);
|
||||
@@ -279,8 +287,7 @@ async fn inner_handle_connection(
|
||||
let client_map = room_map.remove(room_id);
|
||||
if let Some(client_map) = client_map {
|
||||
for (_client_id, client_addr) in client_map {
|
||||
let client_tx = peer_map.lock().unwrap().remove(&client_addr);
|
||||
if let Some(client_tx) = client_tx {
|
||||
if let Some(client_tx) = peer_map.lock().unwrap().remove(&client_addr) {
|
||||
client_tx.unbounded_send(Message::Close(None)).ok();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user