diff --git a/mm2src/mm2_core/src/mm_ctx.rs b/mm2src/mm2_core/src/mm_ctx.rs index 8ff812caee..c0f15dc164 100644 --- a/mm2src/mm2_core/src/mm_ctx.rs +++ b/mm2src/mm2_core/src/mm_ctx.rs @@ -333,8 +333,8 @@ impl MmCtx { pub fn use_trading_proto_v2(&self) -> bool { self.conf["use_trading_proto_v2"].as_bool().unwrap_or_default() } /// Returns the event streaming configuration in use. - pub fn event_streaming_configuration(&self) -> EventStreamingConfiguration { - serde_json::from_value(self.conf["event_streaming_configuration"].clone()).unwrap_or_default() + pub fn event_streaming_configuration(&self) -> Option { + serde_json::from_value(self.conf["event_streaming_configuration"].clone()).ok() } /// Returns the cloneable `WeakSpawner`. diff --git a/mm2src/mm2_event_stream/src/configuration.rs b/mm2src/mm2_event_stream/src/configuration.rs index 532d195e76..590665d581 100644 --- a/mm2src/mm2_event_stream/src/configuration.rs +++ b/mm2src/mm2_event_stream/src/configuration.rs @@ -5,7 +5,6 @@ use serde::Deserialize; /// The network-related configuration of the event streaming interface. // TODO: This better fits in mm2_net but then we would have circular dependency error trying to import it in mm2_core. pub struct EventStreamingConfiguration { - pub disabled: bool, pub worker_path: String, pub access_control_allow_origin: String, } @@ -13,7 +12,6 @@ pub struct EventStreamingConfiguration { impl Default for EventStreamingConfiguration { fn default() -> Self { Self { - disabled: false, worker_path: "event_streaming_worker.js".to_string(), access_control_allow_origin: "*".to_string(), } diff --git a/mm2src/mm2_main/src/lp_native_dex.rs b/mm2src/mm2_main/src/lp_native_dex.rs index a23cad1ad7..ff45f2374e 100644 --- a/mm2src/mm2_main/src/lp_native_dex.rs +++ b/mm2src/mm2_main/src/lp_native_dex.rs @@ -423,8 +423,7 @@ fn migration_1(_ctx: &MmArc) {} #[cfg(target_arch = "wasm32")] fn init_wasm_event_streaming(ctx: &MmArc) { - let event_streaming_config = ctx.event_streaming_configuration(); - if !event_streaming_config.disabled { + if let Some(event_streaming_config) = ctx.event_streaming_configuration() { ctx.spawner() .spawn(handle_worker_stream(ctx.clone(), event_streaming_config.worker_path)); } diff --git a/mm2src/mm2_net/src/event_streaming/sse_handler.rs b/mm2src/mm2_net/src/event_streaming/sse_handler.rs index 84eda03cc1..3fc1c5c333 100644 --- a/mm2src/mm2_net/src/event_streaming/sse_handler.rs +++ b/mm2src/mm2_net/src/event_streaming/sse_handler.rs @@ -12,10 +12,9 @@ pub async fn handle_sse(request: Request, ctx_h: u32) -> Result return handle_internal_error(err).await, }; - let event_streaming_config = ctx.event_streaming_configuration(); - if event_streaming_config.disabled { - return handle_internal_error("Event streaming is explicitly disabled".to_string()).await; - } + let Some(event_streaming_config) = ctx.event_streaming_configuration() else { + return handle_internal_error("Event streaming is disabled".to_string()).await; + }; let client_id = match request.uri().query().and_then(|query| { query