|
|
@@ -2,8 +2,13 @@ use std::{collections::HashMap, sync::Mutex};
|
|
|
use tokio::sync::mpsc::UnboundedSender;
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
+pub struct Client {
|
|
|
+ pub user_id: Uuid,
|
|
|
+ pub tx: UnboundedSender<String>
|
|
|
+}
|
|
|
+
|
|
|
pub struct ClientRegistry {
|
|
|
- pub clients: Mutex<HashMap<Uuid, UnboundedSender<String>>>
|
|
|
+ pub clients: Mutex<HashMap<Uuid, Client>>
|
|
|
}
|
|
|
|
|
|
impl ClientRegistry {
|
|
|
@@ -11,9 +16,9 @@ impl ClientRegistry {
|
|
|
Self { clients: Mutex::new(HashMap::new()) }
|
|
|
}
|
|
|
|
|
|
- pub fn register(&self, tx: UnboundedSender<String>, id: Uuid) -> Uuid {
|
|
|
- self.clients.lock().unwrap().insert(id, tx);
|
|
|
- id
|
|
|
+ pub fn register(&self, tx: UnboundedSender<String>, conn_id: Uuid, user_id: Uuid) -> Uuid {
|
|
|
+ self.clients.lock().unwrap().insert(conn_id, Client { user_id, tx });
|
|
|
+ conn_id
|
|
|
}
|
|
|
|
|
|
pub fn unregister(&self, id: &Uuid) {
|