Init
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
use crate::models::user::Model as User;
|
||||
use parking_lot::RwLock;
|
||||
use std::collections::HashMap;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub mod handlers;
|
||||
pub mod routes;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct GatewayManager {
|
||||
// {UserID: {connection_id: GatewayClient}}
|
||||
pub clients: RwLock<HashMap<Uuid, HashMap<Uuid, GatewayClient>>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct GatewayClient {
|
||||
user: User,
|
||||
connection_id: Uuid,
|
||||
}
|
||||
|
||||
impl GatewayManager {
|
||||
fn add_client(&self, gateway_client: GatewayClient) {
|
||||
let mut clients = self.clients.write();
|
||||
let user_id = gateway_client.user.id;
|
||||
clients
|
||||
.entry(user_id)
|
||||
.or_insert_with(HashMap::new)
|
||||
.insert(gateway_client.connection_id, gateway_client);
|
||||
}
|
||||
|
||||
fn remove_client(&self, gateway_client: GatewayClient) {
|
||||
let mut clients = self.clients.write();
|
||||
if let Some(client_list) = clients.get_mut(&gateway_client.user.id) {
|
||||
client_list.remove(&gateway_client.connection_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GatewayClient {
|
||||
pub fn new(user: User) -> Self {
|
||||
let connection_id = Uuid::new_v4();
|
||||
Self {
|
||||
user,
|
||||
connection_id,
|
||||
}
|
||||
}
|
||||
|
||||
async fn on_connect(&self) {}
|
||||
|
||||
async fn on_disconnect(&self) {}
|
||||
|
||||
async fn on_message(&self) {}
|
||||
}
|
||||
Reference in New Issue
Block a user