mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 07:19:22 +00:00
Close concurrent call accesses
This commit is contained in:
parent
5194a389af
commit
024d83619d
@ -72,8 +72,25 @@ pub fn join_call(r: &mut UserWsRequestHandler) -> RequestResult {
|
||||
r.forbidden("This conversation can not be used to make calls!".to_string())?;
|
||||
}
|
||||
|
||||
// TODO : Remove any previous call linked to current connection + any other active connection
|
||||
// of current user to current conversation call
|
||||
// Remove any other active call with current WebSocket
|
||||
if let Some(call) = &r.get_conn().active_call {
|
||||
make_user_leave_call(&call.conv_id, r.get_conn())?;
|
||||
}
|
||||
|
||||
// Remove any other active connection to current call of current user
|
||||
user_ws_controller::foreach_connection(|conn| {
|
||||
if &conn.user_id != r.user_id_ref()? || conn.session.eq(&r.get_conn().session) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(call) = &conn.active_call {
|
||||
if call.conv_id == conv_id {
|
||||
make_user_leave_call(&call.conv_id, conn)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
r.update_conn(|r| r.active_call = Some(ActiveCall {
|
||||
conv_id,
|
||||
|
@ -573,7 +573,9 @@ pub fn disconnect_user_from_all_sockets(user_id: &UserID) -> Res {
|
||||
/// Do something with all active connections
|
||||
pub fn foreach_connection<F>(mut f: F) -> Res
|
||||
where F: FnMut(&UserWsConnection) -> Res {
|
||||
for conn in get_ws_connections_list().lock().unwrap().iter() {
|
||||
let list = get_ws_connections_list().lock().unwrap().clone();
|
||||
|
||||
for conn in list.iter() {
|
||||
f(conn)?;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user