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
e93a18f7
Commit
e93a18f7
authored
Feb 25, 2025
by
qlintonger xeno
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改挂断呼叫逻辑,增添命令行参数以及环境变量适配
parent
c633ebeb
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
2 deletions
+38
-2
src/handles/handle_agora_call.rs
+0
-0
src/main.rs
+10
-2
src/utils/utils.rs
+28
-0
No files found.
src/handles/handle_agora_call.rs
View file @
e93a18f7
This diff is collapsed.
Click to expand it.
src/main.rs
View file @
e93a18f7
...
@@ -10,14 +10,22 @@ mod deport;
...
@@ -10,14 +10,22 @@ mod deport;
use
crate
::
events
::
handle_events
;
use
crate
::
events
::
handle_events
;
use
client
::
handle_client
;
use
client
::
handle_client
;
use
config
::
config
::
STATIC_ADDR
as
addr
;
use
tokio
::
net
::
TcpListener
;
use
tokio
::
net
::
TcpListener
;
use
tokio
::
sync
::
mpsc
;
use
tokio
::
sync
::
mpsc
;
use
utils
::
utils
::
get_addr
;
#[tokio
::
main]
#[tokio
::
main]
async
fn
main
()
{
async
fn
main
()
{
let
listener
=
TcpListener
::
bind
(
addr
)
.await
.unwrap
();
let
bind_addr
=
match
get_addr
()
{
Ok
(
other_addr
)
=>
other_addr
,
Err
(
err
)
=>
{
eprintln!
(
"Error: {}"
,
err
);
std
::
process
::
exit
(
1
);
}
};
let
listener
=
TcpListener
::
bind
(
bind_addr
)
.await
.unwrap
();
// 创建事件通道
// 创建事件通道
let
(
event_sender
,
event_receiver
)
=
mpsc
::
unbounded_channel
();
let
(
event_sender
,
event_receiver
)
=
mpsc
::
unbounded_channel
();
// 启动事件处理任务
// 启动事件处理任务
...
...
src/utils/utils.rs
View file @
e93a18f7
use
std
::
collections
::
HashMap
;
use
std
::
collections
::
HashMap
;
use
std
::
env
;
use
std
::
net
::
SocketAddr
;
use
crate
::
config
::
config
::
STATIC_ADDR
;
pub
(
crate
)
fn
get_connection_params
(
pub
(
crate
)
fn
get_connection_params
(
connection_url
:
String
,
connection_url
:
String
,
...
@@ -17,3 +20,27 @@ pub(crate) fn get_connection_params(
...
@@ -17,3 +20,27 @@ pub(crate) fn get_connection_params(
Ok
(
HashMap
::
new
())
Ok
(
HashMap
::
new
())
}
}
}
}
// 获取地址的逻辑封装
pub
fn
get_addr
()
->
Result
<
String
,
Box
<
dyn
std
::
error
::
Error
>>
{
// 1. 处理命令行参数
let
mut
args
=
env
::
args
()
.skip
(
1
);
if
let
Some
(
pos
)
=
args
.position
(|
arg
|
arg
==
"--addr"
)
{
// 获取下一个参数值
return
args
.nth
(
pos
)
.ok_or
(
"--addr requires a value"
.into
())
.and_then
(|
addr
|
{
addr
.parse
::
<
SocketAddr
>
()
?
;
Ok
(
addr
)
});
}
// 2. 处理环境变量
if
let
Ok
(
env_addr
)
=
env
::
var
(
"RS_WS_ADDR"
)
{
env_addr
.parse
::
<
SocketAddr
>
()
?
;
return
Ok
(
env_addr
);
}
// 3. 返回默认值
Ok
(
STATIC_ADDR
.to_string
())
}
\ No newline at end of file
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