Commit 897d3d02 by qlintonger xeno

自动挂断channel完毕,看看自动挂断refuse的

parent 14a4c852
......@@ -428,7 +428,7 @@ pub async fn handle_agora_call(
let user_data_cloned_current = current_user_status_data.clone();
tokio::spawn(async move {
tokio::select! {
_ = sleep(Duration::from_secs(20)) => {
_ = sleep(Duration::from_secs(15)) => {
println!("20秒内没有接听,准备挂断通话");
// 20秒内没有接听,准备挂断通话
let mut current_user_data_vec: Vec<String> = user_data_cloned_current.split(',').map(|s| s.to_string()).collect();
......@@ -908,19 +908,25 @@ pub async fn handle_agora_call(
}
// 通话过程中挂断
"Hangup" => {
println!("step - hangup -1 接收到hangup消息");
let user_d = { ONLINE_USERS.get(from_id) };
// 挂断通话不是拒接,不需要处理refuse_procedure_map中的线程消息
if let Some(current_user_data) = user_d {
// 直接修改对应数据即可
let mut current_user_data_vec: Vec<&str> = current_user_data.split(',').collect();
let is_current_user_host = current_user_data_vec[6] == "1";
let current_chatting_channel_id = current_user_data_vec[1];
let current_chatting_channel_id = current_user_data_vec[1].to_string();
println!("step - hangup -2 修改数据信息");
current_user_data_vec[0] = "idle";
current_user_data_vec[1] = "";
// 无论是否是主持人,都需要发送对应消息,更新数据以及同步redis
current_user_data_vec[6] = "0";
let current_user_data_joined = current_user_data_vec.join(",");
println!("step - hangup -3 获取当前用户数据");
drop(current_user_data_vec);
drop(current_user_data);
ONLINE_USERS.insert(from_id.to_string(), current_user_data_joined.clone());
println!("step - hangup -4 更新数据");
let from_id_clone = from_id.to_string();
tokio::spawn(async move {
// 更新redis数据
......@@ -950,8 +956,10 @@ pub async fn handle_agora_call(
&from_id,
)
.await;
println!("step - hangup -5 发送消息");
// 如果当前用户是主持人,主持人退出之后,需要在剩下的用户中决定新主持人
if is_current_user_host {
println!("step - hangup -6 发送消息 当前用户是主持人,需要更新数据");
// 过滤出剩下来的channelID同一的在线用户,并且整合为Vec集合
let remaining_users: Vec<String> = {
ONLINE_USERS
......@@ -970,6 +978,7 @@ pub async fn handle_agora_call(
// 如果余留下的用户数量仅为1,则开启线程,20s内如果该频道与会人数仍为1,则对剩下来的用户发送CmdHangup指令
// 如果大于2人,则需要判断主持人
else {
println!("准备发送CmdLeave消息");
// 无论如何,都要向他们发送CmdLeave消息
for user_id in remaining_users.iter() {
let sender_found = {
......@@ -997,6 +1006,7 @@ pub async fn handle_agora_call(
.await;
}
}
println!("判断是否仅为1人,需要自动挂断");
if remaining_users.len() == 1 {
let (cancel_tx, mut cancel_rx) = mpsc::unbounded_channel::<()>();
channel_hangup_procedure_map
......@@ -1007,17 +1017,17 @@ pub async fn handle_agora_call(
tokio::spawn(async move {
let remaining_users_clone = remaining_users.clone();
tokio::select! {
_ = tokio::time::sleep(Duration::from_secs(20)) => {
_ = tokio::time::sleep(Duration::from_secs(15)) => {
println!("20s内如果该频道与会人数仍为1,则对剩下来的用户发送CmdHangup指令 {:?}", remaining_users_clone);
if let Some(remaining_user_id) = remaining_users_clone.get(0) {
let remaining_user_id_clone = remaining_user_id.clone(); // 克隆 remaining_user_id
let remain_user_d = ONLINE_USERS.get(&remaining_user_id_clone);
if let Some(remain_user_info_data) = remain_user_d {
let sender_d = CLIENT_SENDERS
let sender_d = {CLIENT_SENDERS
.iter()
.find(|entry| entry.key().0 == remaining_user_id_clone)
.map(|entry| entry.key().clone());
.map(|entry| entry.key().clone())};
if let Some(target_sender_which) = sender_d {
let mut user_info_data_for_remained = remain_user_info_data.split(',').collect::<Vec<&str>>();
......@@ -1025,10 +1035,12 @@ pub async fn handle_agora_call(
user_info_data_for_remained[1] = "";
user_info_data_for_remained[6] = "0";
let user_info_data_for_remained_joined = user_info_data_for_remained.join(",");
println!("准备更新剩余一人数据!");
drop(user_info_data_for_remained);
drop(remain_user_info_data);
// 插入克隆后的 remaining_user_id_clone
ONLINE_USERS.insert(remaining_user_id_clone.clone(), user_info_data_for_remained_joined.clone());
println!("更新剩余一人数据成功!");
// 内部 tokio::spawn 使用克隆后的 remaining_user_id_clone
let clone_for_redis = remaining_user_id_clone.clone();
tokio::spawn(async move {
......@@ -1283,16 +1295,15 @@ pub async fn handle_agora_call(
.collect::<Vec<String>>()
};
// 在all_in_group_chatters_id中,找寻第一个在HOST_ENABLED_ID_SET中的id
let first_host_id = all_in_group_chatters_id.iter()
let first_host_id = all_in_group_chatters_id
.iter()
.find(|id| HOST_ENABLED_ID_SET.contains(&id.to_string()));
let mut id = "";
if let Some(target_id) = first_host_id {
id = target_id;
} else {
// 若是空的,则直接取值第一个即可
if let Some(first_element) =
all_in_group_chatters_id.first()
{
if let Some(first_element) = all_in_group_chatters_id.first() {
id = first_element;
}
}
......@@ -1307,8 +1318,7 @@ pub async fn handle_agora_call(
let host_data_joined = host_data_vec.join(",");
println!("Step Connect-9");
drop(hd);
ONLINE_USERS
.insert(id.to_string(), host_data_joined.clone());
ONLINE_USERS.insert(id.to_string(), host_data_joined.clone());
println!("Step Connect-9.1");
let host_id_clone = id.to_string();
tokio::spawn(async move {
......@@ -1316,7 +1326,7 @@ pub async fn handle_agora_call(
&host_id_clone,
host_data_joined.clone(),
)
.await
.await
{
println!(
"更新redis数据失败:{:?} 用户id {} 成为主持人",
......@@ -1342,9 +1352,13 @@ pub async fn handle_agora_call(
entry_split[1] == target_channel_id && entry_split[0] != "calling"
})
.map(|entry| entry.key().clone())
.collect::<Vec<String>>()
.collect::<Vec<String>>()
};
println!("Step Connect-11.5 当前所有channel用户 {:?}和channelID {}", all_not_calling_users,target_channel_id.to_string());
println!(
"Step Connect-11.5 当前所有channel用户 {:?}和channelID {}",
all_not_calling_users,
target_channel_id.to_string()
);
// 遍历上述结构,然后针对他们均发送CmdConnect消息
for user_id in all_not_calling_users {
// 找到对应sender
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment