alpaDrive / server

The central messaging server for the app & vehicle
https://alpadrive.com
5 stars 0 forks source link

Unable to get stats of session #2

Closed vishalkrishnads closed 1 year ago

vishalkrishnads commented 1 year ago

The initial plan to get the current stats of active users and vehicles was to directly get the .len() of the sessions & rooms hashmaps in the Lobby. However, as Lobby is an actor, there is no way to get those from the Manager.

sockets/lobby.rs:

impl Lobby {
        pub fn active_users(&self) -> usize {
            self.sessions.len() - self.rooms.len()
        }

        pub fn active_vehicles(&self) -> usize {
            self.rooms.len()
        }
}

But since the lobby is declared as Addr<Lobby> in Manager, it becomes impossible to invoke the method here

src/manager.rs

impl Manager {
    pub async fn joinvehicle(
        // ... all the args
    ) -> HttpResponse {
        // this method doesn't exist obviously
        let temp = self.lobby.active_users();
    }
}

There doesn't seem to be a solution to this problem as actix::Addr<A> doesn't currently have any valid implementation to expose A, as mentioned in this Stack Overflow post.