Commit e210a1a7 by qlintonger xeno

自动挂断目前没问题了

parent 897d3d02
...@@ -14,3 +14,4 @@ redis = "0.28.2" ...@@ -14,3 +14,4 @@ redis = "0.28.2"
redis_pool = "0.7.0" redis_pool = "0.7.0"
lazy_static = "1.4" lazy_static = "1.4"
dashmap = "4.0.0" dashmap = "4.0.0"
urlencoding = "2.1.3"
\ No newline at end of file
...@@ -111,6 +111,7 @@ pub async fn handle_agora_call( ...@@ -111,6 +111,7 @@ pub async fn handle_agora_call(
} else { } else {
println!("取消拒绝接听的线程队列成功"); println!("取消拒绝接听的线程队列成功");
} }
drop(ref_procedure_sender);
} }
let the_other_caller = { ONLINE_USERS.get(&to_hangup_id) }; let the_other_caller = { ONLINE_USERS.get(&to_hangup_id) };
// 获取当前用户状态信息成功后,再进行额外操作 // 获取当前用户状态信息成功后,再进行额外操作
...@@ -415,6 +416,7 @@ pub async fn handle_agora_call( ...@@ -415,6 +416,7 @@ pub async fn handle_agora_call(
// 最后广播用户更新 // 最后广播用户更新
notify_all_clients_to_update_online_users().await; notify_all_clients_to_update_online_users().await;
}); });
println!("step - 7 开启定时挂断线程refuse {}", refuse_thread_users.len());
// 开启定时器线程任务,如果所有用户20s内没有接听,则挂断,发送所有CmdRefuse数据并重置 // 开启定时器线程任务,如果所有用户20s内没有接听,则挂断,发送所有CmdRefuse数据并重置
for user_id in refuse_thread_users { for user_id in refuse_thread_users {
let current_user_status_data = { ONLINE_USERS.get(&user_id) }; let current_user_status_data = { ONLINE_USERS.get(&user_id) };
...@@ -426,6 +428,9 @@ pub async fn handle_agora_call( ...@@ -426,6 +428,9 @@ pub async fn handle_agora_call(
let (cancel_tx, mut cancel_rx) = mpsc::unbounded_channel::<()>(); let (cancel_tx, mut cancel_rx) = mpsc::unbounded_channel::<()>();
refuse_procedure_map.insert(user_id, cancel_tx); refuse_procedure_map.insert(user_id, cancel_tx);
let user_data_cloned_current = current_user_status_data.clone(); let user_data_cloned_current = current_user_status_data.clone();
println!("step -8 Refuse-Call auto");
// from_id一定是呼叫方
let target_from_id = from_id.clone();
tokio::spawn(async move { tokio::spawn(async move {
tokio::select! { tokio::select! {
_ = sleep(Duration::from_secs(15)) => { _ = sleep(Duration::from_secs(15)) => {
...@@ -459,27 +464,15 @@ pub async fn handle_agora_call( ...@@ -459,27 +464,15 @@ pub async fn handle_agora_call(
}); });
println!("step R-H 3"); println!("step R-H 3");
// 对其发送CmdHangup,对发起方发送CmdRefuse // 对其发送CmdHangup,对发起方发送CmdRefuse
// 发起方的isHost一定是1,找到该用户即可 // 发起方的状态一定是callout
let host_user_id_now = { let host_user_id_now = target_from_id;
ONLINE_USERS
.iter()
.find(|entry| {
entry.value().split(',').collect::<Vec<_>>()[1]
== current_channel_id
&& entry.value().split(',').collect::<Vec<_>>()[6]
== "1"
})
.map(|entry| entry.key().clone())
};
println!("step R-H 4"); println!("step R-H 4");
// 再找到对应的Sender // 再找到对应的Sender
let host_user_sender_which = if let Some(host_user_id) = host_user_id_now { let host_user_sender_which = {
CLIENT_SENDERS CLIENT_SENDERS
.iter() .iter()
.find(|entry| entry.key().0 == host_user_id) .find(|entry| entry.key().0 == host_user_id_now)
.map(|entry| entry.key().clone()) .map(|entry| entry.key().clone())
} else {
None
}; };
println!("step R-H 5"); println!("step R-H 5");
if let Some(host_user_sender_which) = host_user_sender_which { if let Some(host_user_sender_which) = host_user_sender_which {
...@@ -537,16 +530,13 @@ pub async fn handle_agora_call( ...@@ -537,16 +530,13 @@ pub async fn handle_agora_call(
.collect() .collect()
}; };
println!("step R-H 9"); println!("step R-H 9");
// 如果剩下来的用户只有一人,直接要求其挂断
if left_users.len() <= 1 { if left_users.len() <= 1 {
let only_left_user = left_users.get(0); let only_left_user = left_users.get(0);
if let Some((user_id, user_data)) = only_left_user { if let Some((user_id, user_data)) = only_left_user {
let mut user_data = user_data.split(',').collect::<Vec<&str>>(); let mut user_data = user_data.split(',').collect::<Vec<&str>>();
{ {
println!("step R-H 10"); println!("step R-H 10");
let user_is_host = user_data[1] == "1";
if user_is_host {
// 发起方
// 找到发起方的Sender
println!("step R-H 10-1"); println!("step R-H 10-1");
let sender_or_not = { let sender_or_not = {
CLIENT_SENDERS.iter().find(|entry| entry.key().0 == user_id.to_string()) CLIENT_SENDERS.iter().find(|entry| entry.key().0 == user_id.to_string())
...@@ -575,7 +565,7 @@ pub async fn handle_agora_call( ...@@ -575,7 +565,7 @@ pub async fn handle_agora_call(
host_user_sender_which.key(), host_user_sender_which.key(),
&event_sender, &event_sender,
serde_json::json!({ serde_json::json!({
"msgType": "CmdCancelCall", "msgType": "CmdHangup",
"fromID": "0", "fromID": "0",
"fromName": "Server", "fromName": "Server",
"toID": host_user_sender_which.key().0, "toID": host_user_sender_which.key().0,
...@@ -586,7 +576,6 @@ pub async fn handle_agora_call( ...@@ -586,7 +576,6 @@ pub async fn handle_agora_call(
} }
} }
} }
}
println!("step R-H 11"); println!("step R-H 11");
tokio::spawn(async move { tokio::spawn(async move {
// 要求所有用户更新在线人员列表 // 要求所有用户更新在线人员列表
...@@ -914,7 +903,6 @@ pub async fn handle_agora_call( ...@@ -914,7 +903,6 @@ pub async fn handle_agora_call(
if let Some(current_user_data) = user_d { if let Some(current_user_data) = user_d {
// 直接修改对应数据即可 // 直接修改对应数据即可
let mut current_user_data_vec: Vec<&str> = current_user_data.split(',').collect(); 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].to_string(); let current_chatting_channel_id = current_user_data_vec[1].to_string();
println!("step - hangup -2 修改数据信息"); println!("step - hangup -2 修改数据信息");
current_user_data_vec[0] = "idle"; current_user_data_vec[0] = "idle";
...@@ -958,7 +946,7 @@ pub async fn handle_agora_call( ...@@ -958,7 +946,7 @@ pub async fn handle_agora_call(
.await; .await;
println!("step - hangup -5 发送消息"); println!("step - hangup -5 发送消息");
// 如果当前用户是主持人,主持人退出之后,需要在剩下的用户中决定新主持人 // 如果当前用户是主持人,主持人退出之后,需要在剩下的用户中决定新主持人
if is_current_user_host { {
println!("step - hangup -6 发送消息 当前用户是主持人,需要更新数据"); println!("step - hangup -6 发送消息 当前用户是主持人,需要更新数据");
// 过滤出剩下来的channelID同一的在线用户,并且整合为Vec集合 // 过滤出剩下来的channelID同一的在线用户,并且整合为Vec集合
let remaining_users: Vec<String> = { let remaining_users: Vec<String> = {
...@@ -1209,6 +1197,7 @@ pub async fn handle_agora_call( ...@@ -1209,6 +1197,7 @@ pub async fn handle_agora_call(
} else { } else {
println!("挂断personnel的任务已经发送成功") println!("挂断personnel的任务已经发送成功")
} }
drop(hangup_personnel);
} }
println!("Step Connect-1.3"); println!("Step Connect-1.3");
// 检查一下是否存在挂断channel的任务,如果存在,对齐发送消息,然后关闭 // 检查一下是否存在挂断channel的任务,如果存在,对齐发送消息,然后关闭
......
...@@ -5,6 +5,7 @@ use redis::Client; ...@@ -5,6 +5,7 @@ use redis::Client;
use redis::Commands; use redis::Commands;
use redis_pool::SingleRedisPool; use redis_pool::SingleRedisPool;
use std::collections::HashMap; use std::collections::HashMap;
use urlencoding::decode;
lazy_static! { lazy_static! {
static ref REDIS_POOL: SingleRedisPool = { static ref REDIS_POOL: SingleRedisPool = {
...@@ -72,11 +73,15 @@ pub async fn insert_this_connection( ...@@ -72,11 +73,15 @@ pub async fn insert_this_connection(
} else { } else {
"0".to_string() "0".to_string()
}; };
let from_name_decoded = match decode(from_name.as_str()) {
Ok(decoded) => decoded.to_string(),
Err(_) => from_name,
};
// 按照结构体OnlineUserMessage的格式构造用户信息字符串,用逗号拼接即可 // 按照结构体OnlineUserMessage的格式构造用户信息字符串,用逗号拼接即可
// callState,channelID,deviceID,fromID,hasCamera,hasMike,isHost,userCallGroup,fromName // callState,channelID,deviceID,fromID,hasCamera,hasMike,isHost,userCallGroup,fromName
let user_info_str = format!( let user_info_str = format!(
"{},{},{},{},{},{},0,{},{}", "{},{},{},{},{},{},0,{},{}",
"idle", "", device_id, from_id, has_camera, has_mike, user_call_group, from_name "idle", "", device_id, from_id, has_camera, has_mike, user_call_group, from_name_decoded
); );
if let Err(e) = con.hset::<&str, &str, &str, ()>("onlineUsers", from_id, &user_info_str) { if let Err(e) = con.hset::<&str, &str, &str, ()>("onlineUsers", from_id, &user_info_str) {
......
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