Files
open-xiaoai/packages/client-v2/src/net/protocol.rs
T

60 lines
1.1 KiB
Rust
Raw Normal View History

2026-01-02 13:04:19 +08:00
use crate::audio::config::AudioConfig;
2026-01-02 09:59:29 +08:00
use serde::{Deserialize, Serialize};
2026-01-02 13:04:19 +08:00
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct DeviceInfo {
pub model: String,
pub mac: String,
pub version: u32,
2026-01-02 09:59:29 +08:00
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum ControlPacket {
2026-01-02 13:04:19 +08:00
// 服务发现
2026-01-02 09:59:29 +08:00
ServerHello {
2026-01-02 13:04:19 +08:00
tcp_port: u16,
2026-01-02 09:59:29 +08:00
},
2026-01-02 13:04:19 +08:00
// 握手与认证
2026-01-02 09:59:29 +08:00
ClientIdentify {
2026-01-02 13:04:19 +08:00
info: DeviceInfo,
2026-01-02 09:59:29 +08:00
},
2026-01-02 13:04:19 +08:00
IdentifyOk,
// 音频控制
StartRecording {
config: AudioConfig,
2026-01-02 09:59:29 +08:00
},
2026-01-02 13:04:19 +08:00
StopRecording,
StartPlayback {
config: AudioConfig,
2026-01-02 09:59:29 +08:00
},
2026-01-02 13:04:19 +08:00
StopPlayback,
// RPC
RpcRequest {
id: u32,
method: String,
args: Vec<String>,
},
RpcResponse {
id: u32,
result: RpcResult,
},
// 心跳
Ping,
Pong,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RpcResult {
pub stdout: String,
pub stderr: String,
pub code: i32,
2026-01-02 09:59:29 +08:00
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AudioPacket {
2026-01-02 13:04:19 +08:00
pub data: Vec<u8>, // Opus 编码数据
2026-01-02 09:59:29 +08:00
}