1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-25 23:09:22 +00:00

Can mark a user as ready to stream

This commit is contained in:
Pierre HUBERT 2021-02-11 19:21:24 +01:00
parent 50b094acfb
commit 8ebfcf2785
4 changed files with 54 additions and 1 deletions

View File

@ -0,0 +1,23 @@
//! # Call peer ready API
//!
//! @author Pierre Hubert
use serde::Serialize;
use crate::data::conversation::ConvID;
use crate::data::user::UserID;
#[derive(Serialize)]
#[allow(non_snake_case)]
pub struct CallPeerReadyAPI {
callID: u64,
peerID: u64,
}
impl CallPeerReadyAPI {
pub fn new(call_id: &ConvID, user_id: &UserID) -> Self {
Self {
callID: call_id.clone(),
peerID: user_id.id(),
}
}
}

View File

@ -61,4 +61,5 @@ pub mod user_calls_config;
pub mod joined_call_message;
pub mod call_member_info;
pub mod left_call_message;
pub mod new_call_signal;
pub mod new_call_signal;
pub mod call_peer_ready;

View File

@ -7,6 +7,7 @@ use std::collections::HashMap;
use webrtc_sdp::attribute_type::SdpAttribute;
use crate::api_data::call_member_info::CallMemberInfo;
use crate::api_data::call_peer_ready::CallPeerReadyAPI;
use crate::api_data::joined_call_message::JoinedCallMessage;
use crate::api_data::left_call_message::LeftCallMessage;
use crate::api_data::new_call_signal::NewCallSignalAPI;
@ -61,6 +62,17 @@ impl UserWsRequestHandler {
Ok(peer_id)
}
/// Update call information
fn update_call<F>(&mut self, update: F) -> Res where F: FnOnce(&mut ActiveCall) {
self.update_conn(|conn| {
if let Some(call) = &mut conn.active_call {
update(call);
}
})?;
Ok(())
}
}
/// Get legacy call configuration
@ -262,6 +274,22 @@ pub fn on_client_signal(r: &mut UserWsRequestHandler) -> RequestResult {
r.success("Signal sent")
}
/// Mark user ready for streaming
pub fn mark_user_ready(r: &mut UserWsRequestHandler) -> Res {
let call_id = r.post_call_id("callID")?;
let user_id = r.user_id()?;
r.update_call(|call| call.ready = true)?;
user_ws_controller::send_message_to_specific_connections(
|c| c.user_id != &user_id && c.is_having_call_with_conversation(&call_id),
|_| UserWsMessage::no_id_message("call_peer_ready", CallPeerReadyAPI::new(&call_id, r.user_id_ref()?)),
None::<fn(&_) -> _>,
)?;
r.success("Information propagated.")
}
/// Make the user leave the call
pub fn make_user_leave_call(conv_id: &ConvID, connection: &UserWsConnection) -> Res {

View File

@ -43,6 +43,7 @@ pub fn get_user_ws_routes() -> Vec<UserWsRoute> {
UserWsRoute::new("calls/leave", calls_controller::leave_call),
UserWsRoute::new("calls/members", calls_controller::get_members_list),
UserWsRoute::new("calls/signal", calls_controller::on_client_signal),
UserWsRoute::new("calls/mark_ready", calls_controller::mark_user_ready),
]
}