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
7fbb3b4f
Commit
7fbb3b4f
authored
Feb 24, 2025
by
qlintonger xeno
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
阐释添加额外消息发送
parent
f1a8eadf
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
2 deletions
+76
-2
src/deport.rs
+76
-2
No files found.
src/deport.rs
View file @
7fbb3b4f
use
crate
::
events
::
Event
;
use
crate
::
events
::
{
Event
,
CLIENT_SENDERS
}
;
use
crate
::
handles
::
handle_agora_call
::
handle_agora_call
;
use
crate
::
handles
::
online_users_update
::{
online_messages
,
send_online_users_resp
};
use
crate
::
typing
::
message_typed
::
ClientMessageData
;
use
tokio
::
sync
::
mpsc
::
UnboundedSender
;
use
crate
::
client
::
ONLINE_USERS
;
pub
async
fn
handle_ws_msg
(
client_message_data
:
&
ClientMessageData
,
...
...
@@ -44,6 +45,79 @@ pub async fn handle_ws_msg(
.await
;
}
// 针对其余消息类型,直接根据fromID -> toID规则发送即可
_
=>
{}
_
=>
{
let
to_id
=
&
client_message_data
.to_id
;
let
msg_json
=
serde_json
::
json!
({
"msgType"
:
msg_type
,
"msgData"
:
client_message_data
.msg_data
,
"fromID"
:
from_id
,
"fromName"
:
client_message_data
.from_name
,
"toID"
:
to_id
})
.to_string
();
println!
(
"收到客户端消息 类型: {} 来自: {} 发送给: {}"
,
msg_type
,
from_id
,
to_id
);
if
to_id
==
"-2"
{
// 广播消息给同频道的所有在线用户
if
let
Some
(
user_data
)
=
ONLINE_USERS
.get
(
&
from_id
)
{
let
channel_id
=
user_data
.split
(
','
)
.nth
(
1
)
.unwrap_or
(
""
)
.to_string
();
println!
(
"准备广播消息到频道: {} 来自用户: {}"
,
channel_id
,
from_id
);
tokio
::
spawn
({
let
event_sender
=
event_sender
.clone
();
let
msg_json
=
msg_json
.clone
();
let
from_id
=
from_id
.clone
();
async
move
{
for
entry
in
ONLINE_USERS
.iter
()
{
let
target_id
=
entry
.key
();
let
target_data
=
entry
.value
();
if
target_data
.split
(
','
)
.nth
(
1
)
.unwrap_or
(
""
)
==
channel_id
&&
target_id
!=
&
from_id
{
if
let
Some
(
sender
)
=
CLIENT_SENDERS
.iter
()
.find
(|
e
|
e
.key
()
.
0
==
*
target_id
)
.map
(|
e
|
e
.key
()
.clone
())
{
println!
(
"发送广播消息给用户: {} 内容: {}"
,
target_id
,
msg_json
);
if
let
Err
(
e
)
=
event_sender
.send
(
Event
::
SendClientMessage
(
sender
,
msg_json
.clone
(),
false
,
))
{
println!
(
"发送广播消息给用户: {} 失败: {:?}"
,
target_id
,
e
);
}
else
{
println!
(
"发送广播消息给用户: {} 成功"
,
target_id
);
}
}
else
{
println!
(
"未找到用户: {} 的sender,无法发送广播消息"
,
target_id
);
}
}
}
}
});
}
else
{
println!
(
"用户: {} 不在线或无频道信息,无法广播"
,
from_id
);
}
}
else
{
// 单播消息给指定用户
if
ONLINE_USERS
.contains_key
(
to_id
)
{
if
let
Some
(
sender
)
=
CLIENT_SENDERS
.iter
()
.find
(|
e
|
e
.key
()
.
0
==
*
to_id
)
.map
(|
e
|
e
.key
()
.clone
())
{
println!
(
"发送单播消息给用户: {} 内容: {}"
,
to_id
,
msg_json
);
if
let
Err
(
e
)
=
event_sender
.send
(
Event
::
SendClientMessage
(
sender
,
msg_json
,
false
,
))
{
println!
(
"发送单播消息给用户: {} 失败: {:?}"
,
to_id
,
e
);
}
else
{
println!
(
"发送单播消息给用户: {} 成功"
,
to_id
);
}
}
else
{
println!
(
"未找到用户: {} 的sender,无法发送单播消息"
,
to_id
);
}
}
else
{
println!
(
"目标用户: {} 不在线,无法发送单播消息"
,
to_id
);
}
}
}
}
}
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