Lee Morgan vor 1 Monat
Ursprung
Commit
e3346c0e9a
2 geänderte Dateien mit 10 neuen und 5 gelöschten Zeilen
  1. 1 1
      src/controllers/ws_connect.rs
  2. 9 4
      src/ws_registry.rs

+ 1 - 1
src/controllers/ws_connect.rs

@@ -33,7 +33,7 @@ pub async fn route(
 
     let (tx, mut rx) = mpsc::unbounded_channel::<String>();
     let conn_id = Uuid::new_v4();
-    let client_id = registry.register(tx, conn_id);
+    let client_id = registry.register(tx, conn_id, user.id);
     let last_pong = Arc::new(Mutex::new(Instant::now()));
 
     let mut push_session = session.clone();

+ 9 - 4
src/ws_registry.rs

@@ -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) {