Process more settings from the streaming server
+use crate::state_types::msg::{Action, ActionSettings, Event};
use crate::state_types::msg::Internal::{CtxLoaded, StreamingServerSettingsLoaded};
-use crate::state_types::msg::Event;
-use crate::state_types::*;
+use crate::state_types::{Ctx, Effects, Environment, Msg, Request, UpdateWithCtx};
use futures::future::Future;
use serde::{Deserialize, Serialize};
+use std::fmt::{self, Debug};
extern crate web_sys;
@@ -12,11 +13,39 @@ pub struct SsOption {
pub label: String,
}
+#[derive(Deserialize, Serialize, Clone, Debug)]
+pub enum SsProfile {
+ Default,
+ Soft,
+ Fast,
+ Custom,
+}
+impl SsProfile {
+ fn default_profile() -> Self {
+ SsProfile::Default
+ }
+}
+impl fmt::Display for SsProfile {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "{:?}", self)
+ }
+}
+
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct SsValues {
+ pub server_version: String,
pub app_path: String,
- pub cache_size: u64,
+ pub cache_root: String,
+ pub cache_size: f64,
+ pub bt_max_connections: u64,
+ pub bt_handshake_timeout: u64,
+ pub bt_request_timeout: u64,
+ pub bt_download_speed_soft_limit: f64,
+ pub bt_download_speed_hard_limit: f64,
+ pub bt_min_peers_for_stable: f64,
+ #[serde(default = "SsProfile::default_profile")]
+ pub bt_profile: SsProfile,
}
#[derive(Deserialize, Serialize, Clone, Debug)]
@@ -27,6 +56,7 @@ pub struct SsSettings {
pub base_url: String,
}
+// These are the user settings from local storage.
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq)]
pub struct Settings {
pub language: String,
@@ -75,6 +105,7 @@ fn fetch_server_settings(local_settings: &Settings) -> Option<Request<()>> {
pub struct StreamingServerSettings {
pub is_loaded: bool,
pub cache_size: String,
+ pub profile: String,
}
impl Default for StreamingServerSettings {
@@ -82,6 +113,9 @@ impl Default for StreamingServerSettings {
StreamingServerSettings {
is_loaded: false,
cache_size: "2000".to_string(),
+ profile: SsProfile::default_profile()
+ .to_string()
+ .to_ascii_lowercase(),
}
}
}
@@ -103,7 +137,7 @@ impl<Env: Environment + 'static> UpdateWithCtx<Ctx<Env>> for StreamingServerSett
Ok(Msg::Internal(StreamingServerSettingsLoaded(settings)))
})
.or_else(|e| {
- // web_sys::console::log_1(&format!("{}", e).into());
+ web_sys::console::log_1(&format!("Streaming server settings error: {}", e).into());
Err(Msg::Event(Event::CtxFatal(e.into())))
}),
))
@@ -121,6 +155,10 @@ impl<Env: Environment + 'static> UpdateWithCtx<Ctx<Env>> for StreamingServerSett
// Perhaps dispatch custom event for streaming_server_settings_loaded
Effects::none()
}
+ Msg::Action(Action::Settings(ActionSettings::StoreStreamingServer(settings))) => {
+ web_sys::console::log_1(&format!("We have new settings {}", settings.cache_size ).into());
+ Effects::none()
+ }
_ => Effects::none().unchanged(),
}
}
