fix: 修复 rtsp 和 RustDesk 扩展启停错误;修改部分参数描述文本

This commit is contained in:
mofeng-git
2026-05-23 15:16:39 +00:00
parent 3de72677e6
commit dc6475776e
10 changed files with 271 additions and 457 deletions

View File

@@ -88,9 +88,10 @@ impl RtspService {
let status = self.status.clone();
let client_handles = self.client_handles.clone();
*self.status.write().await = RtspServiceStatus::Running;
let handle = tokio::spawn(async move {
tracing::info!("RTSP service listening on {}", bind_addr);
*status.write().await = RtspServiceStatus::Running;
loop {
tokio::select! {

View File

@@ -53,3 +53,59 @@ pub async fn update_rtsp_config(
Ok(Json(RtspConfigResponse::from(&new_config)))
}
pub async fn start_rtsp_service(
State(state): State<Arc<AppState>>,
) -> Result<Json<RtspStatusResponse>> {
let _apply_guard = try_apply_lock(&state.config_apply_locks.rtsp, "rtsp")?;
let current_config = state.config.get().rtsp.clone();
let mut start_config = current_config.clone();
start_config.enabled = true;
apply_rtsp_config(
&state,
&current_config,
&start_config,
ConfigApplyOptions::forced(),
)
.await?;
let status = {
let guard = state.rtsp.read().await;
if let Some(ref service) = *guard {
service.status().await
} else {
crate::rtsp::RtspServiceStatus::Stopped
}
};
Ok(Json(RtspStatusResponse::new(&current_config, status)))
}
pub async fn stop_rtsp_service(
State(state): State<Arc<AppState>>,
) -> Result<Json<RtspStatusResponse>> {
let _apply_guard = try_apply_lock(&state.config_apply_locks.rtsp, "rtsp")?;
let current_config = state.config.get().rtsp.clone();
let mut stop_config = current_config.clone();
stop_config.enabled = false;
apply_rtsp_config(
&state,
&current_config,
&stop_config,
ConfigApplyOptions::forced(),
)
.await?;
let status = {
let guard = state.rtsp.read().await;
if let Some(ref service) = *guard {
service.status().await
} else {
crate::rtsp::RtspServiceStatus::Stopped
}
};
Ok(Json(RtspStatusResponse::new(&current_config, status)))
}

View File

@@ -16,7 +16,7 @@ pub struct RustDeskConfigResponse {
pub device_id: String,
pub has_password: bool,
pub has_keypair: bool,
pub has_relay_key: bool,
pub relay_key: Option<String>,
}
impl From<&RustDeskConfig> for RustDeskConfigResponse {
@@ -28,7 +28,7 @@ impl From<&RustDeskConfig> for RustDeskConfigResponse {
device_id: config.device_id.clone(),
has_password: !config.device_password.is_empty(),
has_keypair: config.public_key.is_some() && config.private_key.is_some(),
has_relay_key: config.relay_key.is_some(),
relay_key: config.relay_key.clone(),
}
}
}
@@ -144,3 +144,71 @@ pub async fn get_device_password(State(state): State<Arc<AppState>>) -> Json<ser
"device_password": config.device_password
}))
}
pub async fn start_rustdesk_service(
State(state): State<Arc<AppState>>,
) -> Result<Json<RustDeskStatusResponse>> {
let _apply_guard = try_apply_lock(&state.config_apply_locks.rustdesk, "rustdesk")?;
let current_config = state.config.get().rustdesk.clone();
let mut start_config = current_config.clone();
start_config.enabled = true;
apply_rustdesk_config(
&state,
&current_config,
&start_config,
ConfigApplyOptions::forced(),
)
.await?;
let (service_status, rendezvous_status) = {
let guard = state.rustdesk.read().await;
if let Some(ref service) = *guard {
let status = format!("{}", service.status());
let rv_status = service.rendezvous_status().map(|s| format!("{}", s));
(status, rv_status)
} else {
("not_initialized".to_string(), None)
}
};
Ok(Json(RustDeskStatusResponse {
config: RustDeskConfigResponse::from(&current_config),
service_status,
rendezvous_status,
}))
}
pub async fn stop_rustdesk_service(
State(state): State<Arc<AppState>>,
) -> Result<Json<RustDeskStatusResponse>> {
let _apply_guard = try_apply_lock(&state.config_apply_locks.rustdesk, "rustdesk")?;
let current_config = state.config.get().rustdesk.clone();
let mut stop_config = current_config.clone();
stop_config.enabled = false;
apply_rustdesk_config(
&state,
&current_config,
&stop_config,
ConfigApplyOptions::forced(),
)
.await?;
let (service_status, rendezvous_status) = {
let guard = state.rustdesk.read().await;
if let Some(ref service) = *guard {
let status = format!("{}", service.status());
let rv_status = service.rendezvous_status().map(|s| format!("{}", s));
(status, rv_status)
} else {
("not_initialized".to_string(), None)
}
};
Ok(Json(RustDeskStatusResponse {
config: RustDeskConfigResponse::from(&current_config),
service_status,
rendezvous_status,
}))
}

View File

@@ -90,7 +90,7 @@ impl VideoConfigUpdate {
}
}
/// Stream configuration response (includes has_turn_password)
/// Stream configuration response
#[typeshare]
#[derive(Debug, serde::Serialize)]
pub struct StreamConfigResponse {
@@ -104,8 +104,7 @@ pub struct StreamConfigResponse {
pub stun_server: Option<String>,
pub turn_server: Option<String>,
pub turn_username: Option<String>,
/// Indicates whether TURN password has been configured (password is not returned)
pub has_turn_password: bool,
pub turn_password: Option<String>,
}
impl From<&StreamConfig> for StreamConfigResponse {
@@ -120,7 +119,7 @@ impl From<&StreamConfig> for StreamConfigResponse {
stun_server: config.stun_server.clone(),
turn_server: config.turn_server.clone(),
turn_username: config.turn_username.clone(),
has_turn_password: config.turn_password.is_some(),
turn_password: config.turn_password.clone(),
}
}
}
@@ -798,7 +797,7 @@ pub struct RtspConfigResponse {
pub allow_one_client: bool,
pub codec: RtspCodec,
pub username: Option<String>,
pub has_password: bool,
pub password: Option<String>,
}
impl From<&RtspConfig> for RtspConfigResponse {
@@ -811,7 +810,7 @@ impl From<&RtspConfig> for RtspConfigResponse {
allow_one_client: config.allow_one_client,
codec: config.codec.clone(),
username: config.username.clone(),
has_password: config.password.is_some(),
password: config.password.clone(),
}
}
}

View File

@@ -131,6 +131,14 @@ pub fn create_router(state: Arc<AppState>) -> Router {
"/config/rustdesk/regenerate-password",
post(handlers::config::regenerate_device_password),
)
.route(
"/config/rustdesk/start",
post(handlers::config::start_rustdesk_service),
)
.route(
"/config/rustdesk/stop",
post(handlers::config::stop_rustdesk_service),
)
// RTSP configuration endpoints
.route("/config/rtsp", get(handlers::config::get_rtsp_config))
.route("/config/rtsp", patch(handlers::config::update_rtsp_config))
@@ -138,6 +146,14 @@ pub fn create_router(state: Arc<AppState>) -> Router {
"/config/rtsp/status",
get(handlers::config::get_rtsp_status),
)
.route(
"/config/rtsp/start",
post(handlers::config::start_rtsp_service),
)
.route(
"/config/rtsp/stop",
post(handlers::config::stop_rtsp_service),
)
// Web server configuration
.route("/config/web", get(handlers::config::get_web_config))
.route("/config/web", patch(handlers::config::update_web_config))