use std::path::PathBuf;
use serde::{Deserialize, Serialize};
pub const RUNTIME_CONFIG_SCHEMA_VERSION: u32 = 2;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct RuntimeFileConfig {
pub schema_version: u32,
pub transport: TransportFileConfig,
pub cursor_stream: CursorStreamFileConfig,
pub management: ManagementFileConfig,
pub playback: PlaybackFileConfig,
pub logging: LoggingFileConfig,
}
impl Default for RuntimeFileConfig {
fn default() -> Self {
Self {
schema_version: RUNTIME_CONFIG_SCHEMA_VERSION,
transport: TransportFileConfig::default(),
cursor_stream: CursorStreamFileConfig::default(),
management: ManagementFileConfig::default(),
playback: PlaybackFileConfig::default(),
logging: LoggingFileConfig::default(),
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct TransportFileConfig {
pub role: String,
pub udp_listen: String,
pub server_address: String,
pub heartbeat_interval_secs: u64,
pub heartbeat_timeout_secs: u64,
}
impl Default for TransportFileConfig {
fn default() -> Self {
Self {
role: "server".to_string(),
udp_listen: "0.0.0.0:18002".to_string(),
server_address: "127.0.0.1:18002".to_string(),
heartbeat_interval_secs: 5,
heartbeat_timeout_secs: 15,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct CursorStreamFileConfig {
pub publish_hz: f64,
pub max_subscribers: usize,
pub reconnect_initial_secs: f64,
pub reconnect_max_secs: f64,
}
impl Default for CursorStreamFileConfig {
fn default() -> Self {
Self {
publish_hz: 30.0,
max_subscribers: 16,
reconnect_initial_secs: 0.5,
reconnect_max_secs: 5.0,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct ManagementFileConfig {
pub enabled: bool,
pub listen: String,
pub data_root: String,
pub web_root: String,
pub websocket_hz: f64,
}
impl Default for ManagementFileConfig {
fn default() -> Self {
Self {
enabled: true,
listen: "127.0.0.1:18003".to_string(),
data_root: "sessions".to_string(),
web_root: "web/dist".to_string(),
websocket_hz: 30.0,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct PlaybackFileConfig {
pub min_speed: f64,
pub max_speed: f64,
}
impl Default for PlaybackFileConfig {
fn default() -> Self {
Self {
min_speed: 0.1,
max_speed: 16.0,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct LoggingFileConfig {
pub level: String,
pub file_path: String,
}
impl Default for LoggingFileConfig {
fn default() -> Self {
Self {
level: "warn".to_string(),
file_path: String::new(),
}
}
}
#[derive(Debug, Clone)]
pub struct TransportConfig {
pub heartbeat_interval_secs: u64,
pub heartbeat_timeout_secs: u64,
}
impl Default for TransportConfig {
fn default() -> Self {
Self {
heartbeat_interval_secs: 5,
heartbeat_timeout_secs: 15,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct StoreConfig;
#[derive(Debug, Clone)]
pub struct ManagementConfig {
pub data_root: PathBuf,
pub web_root: Option<PathBuf>,
pub public_api_base_url: Option<String>,
pub public_websocket_url: Option<String>,
pub websocket_hz: f64,
pub cors_origins: Vec<String>,
}
impl Default for ManagementConfig {
fn default() -> Self {
Self {
data_root: PathBuf::from("sessions"),
web_root: Some(PathBuf::from("web/dist")),
public_api_base_url: None,
public_websocket_url: None,
websocket_hz: 30.0,
cors_origins: vec![
"http://localhost:3000".to_string(),
"http://127.0.0.1:3000".to_string(),
"http://localhost:5173".to_string(),
"http://127.0.0.1:5173".to_string(),
"http://localhost:8000".to_string(),
"http://127.0.0.1:8000".to_string(),
"http://localhost:18003".to_string(),
"http://127.0.0.1:18003".to_string(),
],
}
}
}
#[derive(Debug, Clone)]
pub struct ReplayConfig {
pub default_speed: f64,
pub min_speed: f64,
pub max_speed: f64,
}
impl Default for ReplayConfig {
fn default() -> Self {
Self {
default_speed: 1.0,
min_speed: 0.1,
max_speed: 16.0,
}
}
}
#[derive(Debug, Clone)]
pub struct LoggingConfig {
pub level: String,
pub file_path: Option<String>,
}
impl Default for LoggingConfig {
fn default() -> Self {
Self {
level: "warn".to_string(),
file_path: None,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct RuntimeConfig {
pub transport: TransportConfig,
pub cursor_stream: crate::cursor::CursorStreamConfig,
pub store: StoreConfig,
pub management: ManagementConfig,
pub replay: ReplayConfig,
pub logging: LoggingConfig,
}
#[cfg(test)]
mod tests {
use super::ManagementFileConfig;
#[test]
fn management_file_defaults_use_host_relative_paths() {
let config = ManagementFileConfig::default();
assert_eq!(config.data_root, "sessions");
assert_eq!(config.web_root, "web/dist");
}
}