Commit acac86d4 by qlintonger xeno

尝试优化+1

parent a3538879
......@@ -71,7 +71,7 @@ pub async fn handle_agora_call(
)) {
println!("发送给用户id {} 独立消息失败:{:?}", from_id, e);
}
let user_status = { ONLINE_USERS.get(from_id) };
let user_status = { ONLINE_USERS.get(from_id).map(|v|v.clone()) };
// 对同一个channelID的组,发送挂断消息
if let Some(user_status) = user_status {
// 将获取的字符串用逗号拆分,并存储为 Vec<String>
......@@ -113,7 +113,7 @@ pub async fn handle_agora_call(
}
drop(ref_procedure_sender);
}
let the_other_caller = { ONLINE_USERS.get(&to_hangup_id) };
let the_other_caller = { ONLINE_USERS.get(&to_hangup_id).map(|v|v.clone()) };
// 获取当前用户状态信息成功后,再进行额外操作
if let Some(ref the_other_caller_data) = the_other_caller {
let mut the_other_caller_data: Vec<String> = the_other_caller_data
......@@ -235,7 +235,7 @@ pub async fn handle_agora_call(
.await;
return;
}
let user_status = { ONLINE_USERS.get(from_id) };
let user_status = { ONLINE_USERS.get(from_id).map(|v|v.clone()) };
// 获取当前用户状态信息成功后,再进行额外操作
if let Some(user_status) = user_status {
// 将获取的字符串用逗号拆分
......@@ -270,7 +270,7 @@ pub async fn handle_agora_call(
.await;
continue;
}
let user_status = { ONLINE_USERS.get(calling_to_id) };
let user_status = { ONLINE_USERS.get(calling_to_id).map(|v|v.clone()) };
// 2.检查目标用户是否为空闲状态
if let Some(user_status) = user_status {
// 将获取的字符串用逗号拆分
......@@ -422,7 +422,7 @@ pub async fn handle_agora_call(
);
// 开启定时器线程任务,如果所有用户20s内没有接听,则挂断,发送所有CmdRefuse数据并重置
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).map(|v|v.clone()) };
if let Some(current_user_status_data) = current_user_status_data {
// 设置线程任务
let user_id_clone = user_id.clone();
......@@ -611,7 +611,7 @@ pub async fn handle_agora_call(
}
drop(target_sender_or_not);
}
let user_data = { ONLINE_USERS.get(from_id) };
let user_data = { ONLINE_USERS.get(from_id).map(|v|v.clone()) };
let mut current_channel_id = "".to_string();
// 给当前from_id用户发送CmdHangup,表示已经成功拒接了电话,并且修改了状态
if let Some(ref current_user_data) = user_data {
......@@ -743,7 +743,7 @@ pub async fn handle_agora_call(
drop(current_all_chatters);
// 获取ONLINE_USERS
println!("step - Refuse - 7.758 - alone");
let target_ud = ONLINE_USERS.get(&target_id);
let target_ud = ONLINE_USERS.get(&target_id).map(|v|v.clone());
if let Some(target_ud) = target_ud {
let mut target_ud_vec: Vec<&str> = target_ud.split(',').collect();
target_ud_vec[0] = "idle";
......@@ -778,7 +778,7 @@ pub async fn handle_agora_call(
// 主持人结束通话
"EndMeeting" => {
println!("step - EndMeeting - 1 收到挂断会议通知!");
let user_found = { ONLINE_USERS.get(from_id) };
let user_found = { ONLINE_USERS.get(from_id).map(|v|v.clone()) };
// 要求判断是否为主持人,只有主持人可以结束通话
if let Some(ref current_user_data) = user_found {
let current_user_data_vec: Vec<&str> = current_user_data.split(',').collect();
......@@ -827,7 +827,7 @@ pub async fn handle_agora_call(
println!("step - EndMeeting - 1.6 判断channel_id 遍历循环");
// 再根据上面的id,找到所有sender,并且修改所有对应ONLINE_USERS数据
for user_id_current_chat in users_to_notify {
let user_d = { ONLINE_USERS.get(&user_id_current_chat) };
let user_d = { ONLINE_USERS.get(&user_id_current_chat).map(|v|v.clone()) };
if let Some(current_user_data) = user_d {
let mut current_user_data_vec: Vec<&str> =
current_user_data.split(',').collect();
......@@ -901,7 +901,7 @@ pub async fn handle_agora_call(
// 通话过程中挂断
"Hangup" => {
println!("step - hangup -1 接收到hangup消息");
let user_d = { ONLINE_USERS.get(from_id) };
let user_d = { ONLINE_USERS.get(from_id).map(|v|v.clone()) };
// 挂断通话不是拒接,不需要处理refuse_procedure_map中的线程消息
if let Some(current_user_data) = user_d {
// 直接修改对应数据即可
......@@ -1013,7 +1013,7 @@ pub async fn handle_agora_call(
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);
let remain_user_d = ONLINE_USERS.get(&remaining_user_id_clone).map(|v|v.clone());
if let Some(remain_user_info_data) = remain_user_d {
let sender_d = {CLIENT_SENDERS
.iter()
......@@ -1085,7 +1085,7 @@ pub async fn handle_agora_call(
// 让第一位id的用户成为主持人
if let Some(allowed_user_id) = allowed_users_clone.get(0) {
let allowed_user_id_clone = allowed_user_id.clone(); // 克隆 allowed_user_id
let data_f = { ONLINE_USERS.get(&allowed_user_id_clone) };
let data_f = { ONLINE_USERS.get(&allowed_user_id_clone).map(|v|v.clone()) };
if let Some(ref allowed_user_info_data) = data_f {
let mut user_info_data_for_allowed = allowed_user_info_data
.split(',')
......@@ -1122,7 +1122,7 @@ pub async fn handle_agora_call(
let disallowed_users_clone = disallowed_users.clone(); // 克隆 disallowed_users
if let Some(disallowed_user_id) = disallowed_users_clone.get(0) {
let disallowed_user_id_clone = disallowed_user_id.clone(); // 克隆 disallowed_user_id
let d_f = { ONLINE_USERS.get(&disallowed_user_id_clone) };
let d_f = { ONLINE_USERS.get(&disallowed_user_id_clone).map(|v|v.clone()) };
if let Some(ref disallowed_user_info_data) = d_f {
let mut current_host_data = disallowed_user_info_data
.split(',')
......@@ -1178,7 +1178,7 @@ pub async fn handle_agora_call(
let to_id_user = &client_message_data.to_id;
// 找到对应to_id用户的数据
println!("Step Connect-1");
let to_id_user_data_here = { ONLINE_USERS.get(to_id_user) };
let to_id_user_data_here = { ONLINE_USERS.get(to_id_user).map(|v|v.clone()) };
if let Some(to_id_user_data) = to_id_user_data_here {
// 如果存在,则获取这个channel_id
let data_split = to_id_user_data
......@@ -1239,7 +1239,7 @@ pub async fn handle_agora_call(
if HOST_ENABLED_ID_SET.contains(&channel_id_first_element.to_string()) {
// 具备成为主持人资格,直接修改其对应数据即可
let online_d =
{ ONLINE_USERS.get(&channel_id_first_element.to_string()) };
{ ONLINE_USERS.get(&channel_id_first_element.to_string()).map(|v|v.clone()) };
if let Some(ref host_data) = online_d {
let mut host_data_vec =
host_data.split(",").collect::<Vec<_>>();
......@@ -1300,7 +1300,7 @@ pub async fn handle_agora_call(
}
}
println!("Step Connect-7.5 找到具备成为主持人的host-id");
let hd = { ONLINE_USERS.get(id) };
let hd = { ONLINE_USERS.get(id).map(|v|v.clone()) };
if let Some(ref host_data) = hd {
let mut host_data_vec =
host_data.split(",").collect::<Vec<_>>();
......@@ -1426,7 +1426,7 @@ pub async fn handle_agora_call(
"KickOut" => {
println!("step - KickOut - 1 收到踢出通知");
// 判断当前用户是否是主持人
let user_found = { ONLINE_USERS.get(from_id) };
let user_found = { ONLINE_USERS.get(from_id).map(|v|v.clone()) };
if let Some(user_found) = user_found {
let user_split = user_found.split(",").collect::<Vec<_>>();
if user_split[6] == "1" {
......@@ -1461,7 +1461,7 @@ pub async fn handle_agora_call(
println!("tep - KickOut 4 --踢出对应消息的人");
// 使该sender-which发送消息CmdHangup
// 注意,需要修改其用户数据
let kicked_user = ONLINE_USERS.get(&user_id);
let kicked_user = ONLINE_USERS.get(&user_id).map(|v|v.clone());
if let Some(kicked_user) = kicked_user {
let mut kicked_user_data = kicked_user.split(",").collect::<Vec<_>>();
kicked_user_data[0] ="idle";
......@@ -1583,7 +1583,7 @@ pub async fn handle_agora_call(
} else {
// 直接找到对应to_id的sender-which,然后发送消息即可
// 目前只有主持人可以静音他人
let user_found = { ONLINE_USERS.get(from_id) };
let user_found = { ONLINE_USERS.get(from_id).map(|v|v.clone()) };
if let Some(user_found) = user_found {
let user_data_now = user_found.split(",").collect::<Vec<_>>();
if user_data_now[6] == "1" {
......@@ -1654,7 +1654,7 @@ pub async fn handle_agora_call(
// 处理全部人员静音,只有主持人有操作权限!
"MuteAll" => {
println!("step - MuteAll - 1 收到静音全部通知");
let user_found = { ONLINE_USERS.get(from_id) };
let user_found = { ONLINE_USERS.get(from_id).map(|v|v.clone()) };
if let Some(user_found) = user_found {
let current_user_data = user_found.split(",").collect::<Vec<_>>();
println!("step - MuteAll -2 拆解数据");
......@@ -1738,7 +1738,7 @@ pub async fn handle_agora_call(
"MuteSelf" | "UnMuteSelf" => {
println!("step - MuteSelf-UN - 1 收到开关静音自己通知");
// 直接以fromId为基准,找到对应channel ID数据即可
let user_found = { ONLINE_USERS.get(from_id) };
let user_found = { ONLINE_USERS.get(from_id).map(|v|v.clone()) };
if let Some(user_found) = user_found {
let data_split = user_found.split(",").collect::<Vec<_>>();
let channel_id = data_split[1].to_string();
......
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