Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
ws-rst
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qlintonger xeno
ws-rst
Commits
e210a1a7
Commit
e210a1a7
authored
Feb 20, 2025
by
qlintonger xeno
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
自动挂断目前没问题了
parent
897d3d02
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
28 deletions
+23
-28
Cargo.toml
+3
-2
src/handles/handle_agora_call.rs
+14
-25
src/handles/redis.rs
+6
-1
No files found.
Cargo.toml
View file @
e210a1a7
...
...
@@ -13,4 +13,5 @@ futures = "0.3.31"
redis
=
"0.28.2"
redis_pool
=
"0.7.0"
lazy_static
=
"1.4"
dashmap
=
"4.0.0"
\ No newline at end of file
dashmap
=
"4.0.0"
urlencoding
=
"2.1.3"
\ No newline at end of file
src/handles/handle_agora_call.rs
View file @
e210a1a7
...
...
@@ -111,6 +111,7 @@ pub async fn handle_agora_call(
}
else
{
println!
(
"取消拒绝接听的线程队列成功"
);
}
drop
(
ref_procedure_sender
);
}
let
the_other_caller
=
{
ONLINE_USERS
.get
(
&
to_hangup_id
)
};
// 获取当前用户状态信息成功后,再进行额外操作
...
...
@@ -415,6 +416,7 @@ pub async fn handle_agora_call(
// 最后广播用户更新
notify_all_clients_to_update_online_users
()
.await
;
});
println!
(
"step - 7 开启定时挂断线程refuse {}"
,
refuse_thread_users
.len
());
// 开启定时器线程任务,如果所有用户20s内没有接听,则挂断,发送所有CmdRefuse数据并重置
for
user_id
in
refuse_thread_users
{
let
current_user_status_data
=
{
ONLINE_USERS
.get
(
&
user_id
)
};
...
...
@@ -426,6 +428,9 @@ pub async fn handle_agora_call(
let
(
cancel_tx
,
mut
cancel_rx
)
=
mpsc
::
unbounded_channel
::
<
()
>
();
refuse_procedure_map
.insert
(
user_id
,
cancel_tx
);
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
::
select!
{
_
=
sleep
(
Duration
::
from_secs
(
15
))
=>
{
...
...
@@ -459,27 +464,15 @@ pub async fn handle_agora_call(
});
println!
(
"step R-H 3"
);
// 对其发送CmdHangup,对发起方发送CmdRefuse
// 发起方的isHost一定是1,找到该用户即可
let
host_user_id_now
=
{
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
())
};
// 发起方的状态一定是callout
let
host_user_id_now
=
target_from_id
;
println!
(
"step R-H 4"
);
// 再找到对应的Sender
let
host_user_sender_which
=
if
let
Some
(
host_user_id
)
=
host_user_id_now
{
let
host_user_sender_which
=
{
CLIENT_SENDERS
.iter
()
.find
(|
entry
|
entry
.key
()
.
0
==
host_user_id
)
.find
(|
entry
|
entry
.key
()
.
0
==
host_user_id
_now
)
.map
(|
entry
|
entry
.key
()
.clone
())
}
else
{
None
};
println!
(
"step R-H 5"
);
if
let
Some
(
host_user_sender_which
)
=
host_user_sender_which
{
...
...
@@ -537,17 +530,14 @@ pub async fn handle_agora_call(
.collect
()
};
println!
(
"step R-H 9"
);
// 如果剩下来的用户只有一人,直接要求其挂断
if
left_users
.len
()
<=
1
{
let
only_left_user
=
left_users
.get
(
0
);
if
let
Some
((
user_id
,
user_data
))
=
only_left_user
{
let
mut
user_data
=
user_data
.split
(
','
)
.collect
::
<
Vec
<&
str
>>
();
{
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
=
{
CLIENT_SENDERS
.iter
()
.find
(|
entry
|
entry
.key
()
.
0
==
user_id
.to_string
())
};
...
...
@@ -575,7 +565,7 @@ pub async fn handle_agora_call(
host_user_sender_which
.key
(),
&
event_sender
,
serde_json
::
json!
({
"msgType"
:
"Cmd
CancelCall
"
,
"msgType"
:
"Cmd
Hangup
"
,
"fromID"
:
"0"
,
"fromName"
:
"Server"
,
"toID"
:
host_user_sender_which
.key
()
.
0
,
...
...
@@ -583,7 +573,6 @@ pub async fn handle_agora_call(
})
.to_string
(),
user_id
,
)
.await
;
}
}
}
}
}
...
...
@@ -914,7 +903,6 @@ pub async fn handle_agora_call(
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
]
.to_string
();
println!
(
"step - hangup -2 修改数据信息"
);
current_user_data_vec
[
0
]
=
"idle"
;
...
...
@@ -958,7 +946,7 @@ pub async fn handle_agora_call(
.await
;
println!
(
"step - hangup -5 发送消息"
);
// 如果当前用户是主持人,主持人退出之后,需要在剩下的用户中决定新主持人
if
is_current_user_host
{
{
println!
(
"step - hangup -6 发送消息 当前用户是主持人,需要更新数据"
);
// 过滤出剩下来的channelID同一的在线用户,并且整合为Vec集合
let
remaining_users
:
Vec
<
String
>
=
{
...
...
@@ -1209,6 +1197,7 @@ pub async fn handle_agora_call(
}
else
{
println!
(
"挂断personnel的任务已经发送成功"
)
}
drop
(
hangup_personnel
);
}
println!
(
"Step Connect-1.3"
);
// 检查一下是否存在挂断channel的任务,如果存在,对齐发送消息,然后关闭
...
...
src/handles/redis.rs
View file @
e210a1a7
...
...
@@ -5,6 +5,7 @@ use redis::Client;
use
redis
::
Commands
;
use
redis_pool
::
SingleRedisPool
;
use
std
::
collections
::
HashMap
;
use
urlencoding
::
decode
;
lazy_static!
{
static
ref
REDIS_POOL
:
SingleRedisPool
=
{
...
...
@@ -72,11 +73,15 @@ pub async fn insert_this_connection(
}
else
{
"0"
.to_string
()
};
let
from_name_decoded
=
match
decode
(
from_name
.as_str
())
{
Ok
(
decoded
)
=>
decoded
.to_string
(),
Err
(
_
)
=>
from_name
,
};
// 按照结构体OnlineUserMessage的格式构造用户信息字符串,用逗号拼接即可
// callState,channelID,deviceID,fromID,hasCamera,hasMike,isHost,userCallGroup,fromName
let
user_info_str
=
format!
(
"{},{},{},{},{},{},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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment