mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-09-25 22:29:45 +00:00
Can join call
This commit is contained in:
@@ -14,7 +14,6 @@ use serde_json::Value;
|
||||
use crate::api_data::res_get_ws_token::ResGetWsToken;
|
||||
use crate::constants::{USER_LAST_ACTIVITY_REFRESH, WS_ACCESS_TOKEN_LENGTH};
|
||||
use crate::controllers::user_ws_controller::ws_connections_list::{add_connection, find_connection, get_ws_connections_list, remove_connection};
|
||||
pub use crate::controllers::user_ws_controller::ws_connections_list::WsConnection;
|
||||
use crate::controllers::user_ws_routes::find_user_ws_route;
|
||||
use crate::data::api_client::APIClient;
|
||||
use crate::data::base_request_handler::BaseRequestHandler;
|
||||
@@ -22,6 +21,7 @@ use crate::data::config::conf;
|
||||
use crate::data::error::{ExecError, Res, ResultBoxError};
|
||||
use crate::data::http_request_handler::HttpRequestHandler;
|
||||
use crate::data::user::UserID;
|
||||
use crate::data::user_ws_connection::UserWsConnection;
|
||||
use crate::data::user_ws_message::UserWsMessage;
|
||||
use crate::data::user_ws_request_handler::{UserWsRequestHandler, UserWsResponseType};
|
||||
use crate::helpers::{account_helper, events_helper};
|
||||
@@ -100,30 +100,15 @@ mod ws_tokens_list {
|
||||
|
||||
/// WebSocket connections list
|
||||
mod ws_connections_list {
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use actix::Addr;
|
||||
|
||||
use crate::controllers::user_ws_controller::WsSession;
|
||||
use crate::data::conversation::ConvID;
|
||||
use crate::data::post::PostID;
|
||||
use crate::data::user::UserID;
|
||||
use crate::data::user_ws_connection::UserWsConnection;
|
||||
|
||||
/// This structure contains information about an active connection
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct WsConnection {
|
||||
pub user_id: UserID,
|
||||
pub client_id: u32,
|
||||
pub remote_ip: String,
|
||||
pub session: actix::Addr<WsSession>,
|
||||
pub incognito: bool,
|
||||
pub conversations: HashSet<ConvID>,
|
||||
pub posts: HashSet<PostID>,
|
||||
}
|
||||
|
||||
impl WsConnection {
|
||||
impl UserWsConnection {
|
||||
/// Change some of the properties of the connection
|
||||
pub fn replace<H>(mut self, do_update: H) -> Self where H: FnOnce(&mut Self) {
|
||||
let list = get_ws_connections_list();
|
||||
@@ -147,23 +132,23 @@ mod ws_connections_list {
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref WS_CONNECTIONS: Arc<Mutex<Vec<WsConnection>>> = {
|
||||
static ref WS_CONNECTIONS: Arc<Mutex<Vec<UserWsConnection >>> = {
|
||||
Arc::new(Mutex::new(Vec::new()))
|
||||
};
|
||||
}
|
||||
|
||||
/// Get the list of WebSocket connections
|
||||
pub fn get_ws_connections_list() -> Arc<Mutex<Vec<WsConnection>>> {
|
||||
pub fn get_ws_connections_list() -> Arc<Mutex<Vec<UserWsConnection>>> {
|
||||
(*WS_CONNECTIONS).clone()
|
||||
}
|
||||
|
||||
/// Add a new token to the list
|
||||
pub fn add_connection(t: WsConnection) {
|
||||
pub fn add_connection(t: UserWsConnection) {
|
||||
get_ws_connections_list().lock().unwrap().push(t)
|
||||
}
|
||||
|
||||
/// Find a connection in the list
|
||||
pub fn find_connection(t: Addr<WsSession>) -> Option<WsConnection> {
|
||||
pub fn find_connection(t: Addr<WsSession>) -> Option<UserWsConnection> {
|
||||
get_ws_connections_list()
|
||||
.lock()
|
||||
.unwrap()
|
||||
@@ -173,7 +158,7 @@ mod ws_connections_list {
|
||||
}
|
||||
|
||||
/// Remove a connection from the list
|
||||
pub fn remove_connection(t: Addr<WsSession>) -> Option<WsConnection> {
|
||||
pub fn remove_connection(t: Addr<WsSession>) -> Option<UserWsConnection> {
|
||||
let list = get_ws_connections_list();
|
||||
let mut list = list.lock().unwrap();
|
||||
for i in 0..list.len() {
|
||||
@@ -326,7 +311,7 @@ impl Actor for WsSession {
|
||||
self.hb(ctx);
|
||||
self.user_activity(ctx);
|
||||
|
||||
add_connection(WsConnection {
|
||||
add_connection(UserWsConnection {
|
||||
user_id: self.user_id.clone(),
|
||||
client_id: self.client_id,
|
||||
remote_ip: self.remote_ip.clone(),
|
||||
@@ -334,6 +319,7 @@ impl Actor for WsSession {
|
||||
incognito: self.incognito,
|
||||
conversations: HashSet::new(),
|
||||
posts: HashSet::new(),
|
||||
active_call: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -506,9 +492,9 @@ pub fn send_message_to_user(msg: &UserWsMessage, user: &UserID) -> Res {
|
||||
|
||||
/// Send a message to specific users
|
||||
pub fn send_message_to_specific_connections<F, M, A>(filter: F, msg_generator: M, after_send: Option<A>) -> Res
|
||||
where F: Fn(&WsConnection) -> bool,
|
||||
M: Fn(&WsConnection) -> Res<UserWsMessage>,
|
||||
A: Fn(&WsConnection) -> Res
|
||||
where F: Fn(&UserWsConnection) -> bool,
|
||||
M: Fn(&UserWsConnection) -> Res<UserWsMessage>,
|
||||
A: Fn(&UserWsConnection) -> Res
|
||||
{
|
||||
let connections = get_ws_connections_list()
|
||||
.lock()
|
||||
@@ -516,7 +502,7 @@ pub fn send_message_to_specific_connections<F, M, A>(filter: F, msg_generator: M
|
||||
.iter()
|
||||
.filter(|f| filter(f))
|
||||
.map(|f| f.clone())
|
||||
.collect::<Vec<WsConnection>>();
|
||||
.collect::<Vec<UserWsConnection>>();
|
||||
|
||||
for con in connections {
|
||||
send_message(con.session.clone(), &msg_generator(&con)?)?;
|
||||
|
Reference in New Issue
Block a user