1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 13:29:21 +00:00

Can request call offer

This commit is contained in:
Pierre HUBERT 2021-02-12 13:32:36 +01:00
parent 8ebfcf2785
commit 5388aa8054
5 changed files with 47 additions and 2 deletions

View File

@ -15,7 +15,7 @@ use crate::api_data::user_calls_config::UserCallsConfig;
use crate::controllers::routes::RequestResult;
use crate::controllers::user_ws_controller;
use crate::data::base_request_handler::BaseRequestHandler;
use crate::data::call_signal::{CallSignal, IceCandidate, NewUserCallSignal, SdpType};
use crate::data::call_signal::{CallSignal, IceCandidate, NewUserCallSignal, SdpType, UserCallOfferRequest};
use crate::data::config::conf;
use crate::data::conversation::ConvID;
use crate::data::error::{ExecError, Res};
@ -290,6 +290,25 @@ pub fn mark_user_ready(r: &mut UserWsRequestHandler) -> Res {
r.success("Information propagated.")
}
/// Request an offer from the server
pub fn request_offer(r: &mut UserWsRequestHandler) -> Res {
let call_id = r.post_call_id("callID")?;
// The ID of the user we stream the audio / video from
let peer_id = r.post_call_peer_id(&call_id, "peerID")?;
if !peer_id.is_valid() || peer_id == r.user_id_ref()? {
r.forbidden("You can not request an offer for yourself!".to_string())?;
}
events_helper::propagate_event(&Event::UserRequestedCallOffer(&UserCallOfferRequest {
call_hash: gen_call_hash(&call_id, &peer_id),
user_id: r.user_id()?,
}))?;
r.success("Request sent")
}
/// Make the user leave the call
pub fn make_user_leave_call(conv_id: &ConvID, connection: &UserWsConnection) -> Res {

View File

@ -60,6 +60,14 @@ struct CallUserSignal {
data: CallUserSignalData,
}
#[allow(non_snake_case)]
#[derive(Serialize)]
struct OfferRequest {
title: String,
callHash: String,
peerId: String,
}
/// Current WebSocket connection
static mut ACTIVE_RTC_CONNECTION: Option<Addr<RtcRelayActor>> = None;
@ -277,6 +285,14 @@ pub fn handle_event(e: &events_helper::Event) -> Res {
})?;
}
Event::UserRequestedCallOffer(request) => {
send_message_to_relay(OfferRequest {
title: "request_offer".to_string(),
callHash: request.call_hash.to_string(),
peerId: request.user_id.id().to_string(),
})?;
}
_ => {}
}

View File

@ -44,6 +44,7 @@ pub fn get_user_ws_routes() -> Vec<UserWsRoute> {
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),
UserWsRoute::new("calls/request_offer", calls_controller::request_offer),
]
}

View File

@ -42,6 +42,12 @@ pub struct NewRtcRelayMessage {
pub data: String,
}
/// Request of a user for a call
pub struct UserCallOfferRequest {
pub call_hash: String,
pub user_id: UserID,
}
impl SdpType {
pub fn from_str(val: &str) -> Res<SdpType> {
match val {

View File

@ -6,7 +6,7 @@
use crate::controllers::{calls_controller, comments_controller, conversations_controller, notifications_controller, rtc_relay_controller, user_ws_controller};
use crate::data::api_client::APIClient;
use crate::data::call_signal::{NewRtcRelayMessage, NewUserCallSignal};
use crate::data::call_signal::{NewRtcRelayMessage, NewUserCallSignal, UserCallOfferRequest};
use crate::data::comment::Comment;
use crate::data::conversation::ConvID;
use crate::data::conversation_message::ConversationMessage;
@ -62,6 +62,9 @@ pub enum Event<'a> {
/// Got a new RTC relay message
NewRTCRelayMessage(&'a NewRtcRelayMessage),
/// User requested an offer for a call
UserRequestedCallOffer(&'a UserCallOfferRequest),
/// No event
None,
}