chore: polish code

This commit is contained in:
Del Wang
2026-01-04 15:06:55 +08:00
parent cce3dd630a
commit d88d63b15b
9 changed files with 137 additions and 159 deletions
+35 -40
View File
@@ -16,6 +16,13 @@ pub struct ClientInfo {
pub serial_number: String,
}
/// 音频数据包 - UDP 通道传输
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AudioPacket {
/// Opus 编码的音频数据
pub data: Vec<u8>,
}
// ==================== 控制包 ====================
/// 控制包 - TCP 通道传输的所有消息类型
@@ -23,7 +30,10 @@ pub struct ClientInfo {
pub enum ControlPacket {
// ========== 服务发现 ==========
/// 服务发现广播
Discovery { protocol: String, port: u16 },
Discovery {
protocol: String,
port: u16,
},
// ========== 握手 ==========
/// 服务端握手
@@ -46,9 +56,15 @@ pub enum ControlPacket {
// ========== RPC ==========
/// RPC 请求(新版,使用 Command 类型)
RpcRequest { id: u32, command: Command },
RpcRequest {
id: u32,
command: Command,
},
/// RPC 响应(新版,使用 CommandResult 类型)
RpcResponse { id: u32, result: CommandResult },
RpcResponse {
id: u32,
result: CommandResult,
},
// ========== 事件 ==========
/// 服务端事件推送
@@ -56,48 +72,27 @@ pub enum ControlPacket {
/// 客户端事件推送
ClientEvent(ClientEvent),
// ========== 订阅管理 ==========
/// 订阅事件类型
Subscribe {
event_types: Vec<String>,
},
/// 取消订阅
Unsubscribe {
event_types: Vec<String>,
},
// ========== 音频控制 ==========
/// 开始录音
StartRecording { config: AudioConfig },
StartRecording {
config: AudioConfig,
},
/// 停止录音
StopRecording,
/// 开始播放
StartPlayback { config: AudioConfig },
StartPlayback {
config: AudioConfig,
},
/// 停止播放
StopPlayback,
// ========== 订阅管理 ==========
/// 订阅事件类型
Subscribe { event_types: Vec<String> },
/// 取消订阅
Unsubscribe { event_types: Vec<String> },
}
// ==================== 音频包 ====================
/// 音频数据包 - UDP 通道传输
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AudioPacket {
/// Opus 编码的音频数据
pub data: Vec<u8>,
}
// ==================== 兼容性:旧版 RPC 结果 ====================
/// 旧版 RPC 结果(保持向后兼容)
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct RpcResult {
pub stdout: String,
pub stderr: String,
pub code: i32,
}
impl From<crate::net::command::ShellResponse> for RpcResult {
fn from(resp: crate::net::command::ShellResponse) -> Self {
Self {
stdout: resp.stdout,
stderr: resp.stderr,
code: resp.exit_code,
}
}
}